improve complexity

This commit is contained in:
TomasVotruba 2017-12-09 22:27:38 +01:00
parent 3fa22870f7
commit dbd515df9c
2 changed files with 30 additions and 17 deletions

View File

@ -35,6 +35,7 @@ final class DocBlockAnalyzerTest extends AbstractContainerAwareTestCase
$this->docBlockAnalyzer->removeAnnotationFromNode($node, 'param');
$emptyDoc = <<<'EOT'
/**
*
*/
EOT;
$this->assertSame($emptyDoc, $node->getDocComment()->getText());

View File

@ -68,23 +68,7 @@ final class AutoconfigureRector implements YamlRectorInterface
// find class with system tags
foreach ($services as $key => $service) {
if (! isset($service['tags'])) {
continue;
}
$tags = $service['tags'];
// more tags or more than tag name
if (count($tags) !== 1 || count($tags[0]) !== 1) {
continue;
}
if (! isset($tags[0]['name'])) {
continue;
}
// is system tag name
$tagName = $tags[0]['name'];
if (! in_array($tagName, $this->systemTags, true)) {
if ($this->shouldSkip($service)) {
continue;
}
@ -115,4 +99,32 @@ final class AutoconfigureRector implements YamlRectorInterface
return array_merge($defaultsAutowire, $services);
}
/**
* @param mixed[] $service
*/
private function shouldSkip(array $service): bool
{
if (! isset($service['tags'])) {
return true;
}
$tags = $service['tags'];
// more tags or more than tag name
if (count($tags) !== 1 || count($tags[0]) !== 1) {
return true;
}
if (! isset($tags[0]['name'])) {
return true;
}
// is system tag name
$tagName = $tags[0]['name'];
if (! in_array($tagName, $this->systemTags, true)) {
return true;
}
return false;
}
}