Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions CakePHP/Sniffs/Commenting/TypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,28 @@ public function process(File $phpcsFile, $stackPtr)

$tagComment = $phpcsFile->fixer->getTokenContent($tag + 2);
$valueNode = self::getValueNode($tokens[$tag]['content'], $tagComment);
if ($valueNode instanceof InvalidTagValueNode || !$valueNode->type instanceof UnionTypeNode) {
if ($valueNode instanceof InvalidTagValueNode) {
continue;
}

$originalTypeHint = $this->renderUnionTypes($valueNode->type->types);
$sortedTypeHint = $this->getSortedTypeHint($valueNode->type->types);
if ($valueNode->type instanceof UnionTypeNode) {
$types = $valueNode->type->types;
} elseif ($valueNode->type instanceof ArrayTypeNode) {
$types = [$valueNode->type];
} else {
continue;
}

$originalTypeHint = $this->renderUnionTypes($types);
$sortedTypeHint = $this->getSortedTypeHint($types);
if ($sortedTypeHint === $originalTypeHint) {
continue;
}

$fix = $phpcsFile->addFixableWarning(
'%s type hint is not formatted properly, expected "%s"',
$tag,
'Format',
'IncorrectFormat',
[$tokens[$tag]['content'], $sortedTypeHint]
);
if (!$fix) {
Expand Down
4 changes: 2 additions & 2 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ namespace Beakman;

class Foo
{
/** @var int|string[]|int[] */
/** @var string[] */
protected $testVar;

/** @var null|string|class-string<\Cake\I18n\Number>|array $testVar2 */
/** @var null|string[]|class-string<\Cake\I18n\Number> $testVar2 */
protected $testVar2;

/**
Expand Down
4 changes: 2 additions & 2 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ namespace Beakman;

class Foo
{
/** @var array<string>|array<int>|int */
/** @var array<string> */
protected $testVar;

/** @var array|class-string<\Cake\I18n\Number>|string|null $testVar2 */
/** @var array<string>|class-string<\Cake\I18n\Number>|null $testVar2 */
protected $testVar2;

/**
Expand Down