Skip to content

Commit b51ed0d

Browse files
committed
DoctrineEntitySniff: support multi-line attributes and self reference
1 parent 84f4b4b commit b51ed0d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Swivl/Sniffs/Commenting/DoctrineEntitySniff.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,14 @@ protected function parseNativeAttributeParams(string $text): array
520520
$colonPos = strpos($text, ':');
521521
$name = substr($text, 0, $colonPos);
522522

523-
if (strpos($name, ' ') !== false) {
523+
if (strpos($name, ' ') !== false && strpos($name, "\n") === false) {
524524
$name = trim($name);
525525
$error = 'Found extra space before attribute "%s" name';
526526
$data = [$name];
527527
$this->reportError($error, $this->tagStart, 'ExtraSpace', $data);
528528
}
529529

530+
$name = trim($name, " \r\n");
530531
$valuePos = $colonPos + 1;
531532

532533
if (substr($text, $valuePos, 1) !== ' ') {
@@ -777,7 +778,7 @@ protected function validateAnnotationAttributeType(string $name, string $attrNam
777778
break;
778779

779780
case 'class':
780-
$valid = (ucfirst($value) === $value) && (
781+
$valid = (ucfirst($value) === $value || $value === 'self::class') && (
781782
(strpos($value, "\\") !== false)
782783
|| strpos($value, self::CLASS_SUFFIX, -self::CLASS_SUFFIX_LENGTH)
783784
);
@@ -821,8 +822,8 @@ protected function validateAnnotationColumn(string $name, array $attributes): vo
821822
}
822823
}
823824

824-
$columnType = null;
825-
$expectedType = null;
825+
$expectedType = $this->memberType;
826+
826827
if (isset($attributes['type'])) {
827828
$columnType = $attributes['type'];
828829

@@ -1215,6 +1216,10 @@ protected function getShortClassName(string $className): string
12151216
$className = substr($className, 0, -self::CLASS_SUFFIX_LENGTH);
12161217
}
12171218

1219+
if ($className === 'self') {
1220+
$className = $this->getMethodClassName($this->memberPtr);
1221+
}
1222+
12181223
return $className;
12191224
}
12201225

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"php": ">=7.1",
1818
"squizlabs/php_codesniffer": "^3.6"
1919
},
20+
"conflict": {
21+
"doctrine/orm": "<2.9"
22+
},
2023
"autoload": {
2124
"psr-4": {
2225
"Swivl\\Sniffs\\": "Swivl/Sniffs/",
@@ -25,7 +28,7 @@
2528
},
2629
"extra": {
2730
"branch-alias": {
28-
"dev-master": "1.3.x-dev"
31+
"dev-master": "1.4.x-dev"
2932
}
3033
}
3134
}

0 commit comments

Comments
 (0)