Skip to content

Commit f238293

Browse files
committed
Fix up StrictType sniff to by default require at top, as per PSR.
1 parent c87f388 commit f238293

File tree

8 files changed

+242
-357
lines changed

8 files changed

+242
-357
lines changed

PhpCollective/Sniffs/Commenting/DisallowArrayTypeHintSyntaxSniff.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* For full license information, please view the LICENSE file that was distributed with this source code.
66
*/
77

8-
declare(strict_types=1);
9-
108
namespace PhpCollective\Sniffs\Commenting;
119

1210
use PHP_CodeSniffer\Files\File;
@@ -102,6 +100,9 @@ public function process(File $phpcsFile, $docCommentOpenPointer): void
102100
}
103101

104102
$parsedDocComment = DocCommentHelper::parseDocComment($phpcsFile, $docCommentOpenPointer);
103+
if ($parsedDocComment === null) {
104+
continue;
105+
}
105106

106107
/** @var list<\PHPStan\PhpDocParser\Ast\Type\UnionTypeNode> $unionTypeNodes */
107108
$unionTypeNodes = AnnotationHelper::getAnnotationNodesByType($annotation->getNode(), UnionTypeNode::class);
@@ -194,6 +195,7 @@ protected function isGenericObjectCollection(Annotation $annotation): bool
194195
*/
195196
protected function fixGenericObjectCollection(File $phpcsFile, Annotation $annotation): void
196197
{
198+
//@phpstan-ignore-next-line
197199
$typeNode = AnnotationHelper::getAnnotationTypes($annotation)[0];
198200

199201
$genericType = null;
@@ -215,6 +217,7 @@ protected function fixGenericObjectCollection(File $phpcsFile, Annotation $annot
215217
continue;
216218
}
217219

220+
//@phpstan-ignore-next-line
218221
if ($this->isArrayTypeNode($type)) {
219222
if ($arrayType !== null) {
220223
return;
@@ -236,7 +239,7 @@ protected function fixGenericObjectCollection(File $phpcsFile, Annotation $annot
236239
$fix = $phpcsFile->addFixableError(
237240
sprintf(
238241
'Usage of old type hint syntax for generic in `%s` is disallowed, use generic type hint syntax instead.',
239-
AnnotationTypeHelper::export($typeNode),
242+
AnnotationTypeHelper::print($typeNode),
240243
),
241244
$annotation->getStartPointer(),
242245
static::CODE_DISALLOWED_ARRAY_TYPE_HINT_SYNTAX . 'Union',
@@ -256,6 +259,7 @@ protected function fixGenericObjectCollection(File $phpcsFile, Annotation $annot
256259

257260
$fixedType = implode('|', $unionTypes);
258261

262+
//@phpstan-ignore-next-line
259263
$content = $annotation->getContent() ?? '';
260264
$spacePosition = strpos($content, ' ');
261265
if ($spacePosition !== false) {

PhpCollective/Sniffs/Commenting/FileDocBlockSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function register(): array
3939
public function process(File $phpCsFile, $stackPointer): void
4040
{
4141
$license = $this->getLicense($phpCsFile);
42+
if ($license === '') {
43+
return;
44+
}
4245

4346
$fileDocBlockPointer = $this->fileDocBlockPointer($phpCsFile, $stackPointer);
4447
if ($fileDocBlockPointer === null) {

0 commit comments

Comments
 (0)