Skip to content

Commit

Permalink
Merge pull request #145 from VincentLanglet/feature/fix
Browse files Browse the repository at this point in the history
Improve support of array shape
  • Loading branch information
VincentLanglet authored Jul 29, 2021
2 parents 12d33a8 + af8154f commit 40eb821
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ private function getValidTypes(string $content): string
while ('' !== $content && false !== $content) {
preg_match('{^'.SniffHelper::REGEX_TYPES.'$}ix', $content, $matches);

if (isset($matches['array']) && '' !== $matches['array']) {
$validType = $this->getValidTypes(mb_substr($matches['array'], 0, -2)).'[]';
} elseif (isset($matches['multiple']) && '' !== $matches['multiple']) {
if (isset($matches['multiple']) && '' !== $matches['multiple']) {
$validType = '('.$this->getValidTypes($matches['mutipleContent']).')';
} elseif (isset($matches['generic']) && '' !== $matches['generic']) {
$validType = $this->getValidGenericType($matches['genericName'], $matches['genericContent']);
} elseif (isset($matches['object']) && '' !== $matches['object']) {
$validType = $this->getValidObjectType($matches['objectContent']);
} elseif (isset($matches['generic']) && '' !== $matches['generic']) {
$validType = $this->getValidGenericType($matches['genericName'], $matches['genericContent']);
} elseif (isset($matches['array']) && '' !== $matches['array']) {
$validType = $this->getValidTypes(mb_substr($matches['array'], 0, -2)).'[]';
} else {
$validType = $this->getValidType($matches['type']);
}
Expand Down Expand Up @@ -203,11 +203,13 @@ private function getValidObjectType(string $objectContent): string
$validType = 'array{';

while ('' !== $objectContent && false !== $objectContent) {
$split = preg_split('/(\??:|,)/', $objectContent, 2, PREG_SPLIT_DELIM_CAPTURE);
if (0 !== mb_strpos($objectContent, 'array{') && 0 !== mb_strpos($objectContent, 'array<')) {
$split = preg_split('/(\??:|,)/', $objectContent, 2, PREG_SPLIT_DELIM_CAPTURE);

if (isset($split[1]) && ',' !== $split[1]) {
$validType .= $split[0].$split[1].' ';
$objectContent = $split[2];
if (isset($split[1]) && ',' !== $split[1]) {
$validType .= $split[0].$split[1].' ';
$objectContent = $split[2];
}
}

preg_match('{^'.SniffHelper::REGEX_TYPES.',?}ix', $objectContent, $matches);
Expand Down

0 comments on commit 40eb821

Please sign in to comment.