diff --git a/src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php b/src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php index 09fbe0fc..ecfcf274 100644 --- a/src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php +++ b/src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php @@ -43,10 +43,13 @@ public function addArrayItemToEnvConfig( ): FileInformationTransfer { $valueStm = $this->expressionPartialParser->parse(sprintf('$var = %s;', $value)); - /** @var \PhpParser\Node\Stmt\Class_|null $node */ + /** @var \PhpParser\Node\Expr\ArrayItem|null $arrayItem */ $arrayItem = (new NodeFinder())->findFirst($valueStm, function (Node $node) { return $node instanceof ArrayItem; }); + if (!$arrayItem) { + return $fileInformationTransfer; + } $nodeTraverser = new NodeTraverser(); $nodeTraverser->addVisitor(new AddArrayItemToEnvConfigVisitor($target, $arrayItem)); diff --git a/src/Builder/Extractor/ValueExtractor/AbstractValueExtractorStrategy.php b/src/Builder/Extractor/ValueExtractor/AbstractValueExtractorStrategy.php index b82959fe..4bee28fd 100644 --- a/src/Builder/Extractor/ValueExtractor/AbstractValueExtractorStrategy.php +++ b/src/Builder/Extractor/ValueExtractor/AbstractValueExtractorStrategy.php @@ -108,6 +108,6 @@ protected function createArrayStringFromResult(array $array): string */ protected function isConstant(string $value): bool { - return strpos($value, '::'); + return (bool)strpos($value, '::'); } } diff --git a/src/Builder/Extractor/ValueExtractor/ArrayDimValueExtractor.php b/src/Builder/Extractor/ValueExtractor/ArrayDimValueExtractor.php index f18b3fd7..4cda0a6d 100644 --- a/src/Builder/Extractor/ValueExtractor/ArrayDimValueExtractor.php +++ b/src/Builder/Extractor/ValueExtractor/ArrayDimValueExtractor.php @@ -39,7 +39,10 @@ public function extractValue( $variable = $expression->var; /** @var \PhpParser\Node\Identifier $varName */ $varName = $variable->name; - $key = $valueExtractorStrategyCollection->execute($expression->dim); + /** @var \PhpParser\Node\Expr $dim */ + $dim = $expression->dim; + + $key = $valueExtractorStrategyCollection->execute($dim); return new ExtractedValueTransfer(sprintf('$%s[%s]', $varName, $key->getValue()), true); } diff --git a/src/Builder/Extractor/ValueExtractor/ArrayValueExtractorStrategy.php b/src/Builder/Extractor/ValueExtractor/ArrayValueExtractorStrategy.php index d2fff0ea..d4f70caa 100644 --- a/src/Builder/Extractor/ValueExtractor/ArrayValueExtractorStrategy.php +++ b/src/Builder/Extractor/ValueExtractor/ArrayValueExtractorStrategy.php @@ -38,6 +38,7 @@ public function extractValue( ValueExtractorStrategyCollection $valueExtractorStrategyCollection ): ExtractedValueTransfer { $array = []; + /** @var \PhpParser\Node\Expr\ArrayItem $item */ foreach ($expression->items as $key => $item) { if (!$item->key) { $array[] = $valueExtractorStrategyCollection->execute($item->value)->getValue(); diff --git a/src/Builder/Extractor/ValueExtractor/StaticFuncCallValueExtractorStrategy.php b/src/Builder/Extractor/ValueExtractor/StaticFuncCallValueExtractorStrategy.php index 9e90b961..8f7b401c 100644 --- a/src/Builder/Extractor/ValueExtractor/StaticFuncCallValueExtractorStrategy.php +++ b/src/Builder/Extractor/ValueExtractor/StaticFuncCallValueExtractorStrategy.php @@ -49,8 +49,13 @@ public function extractValue( } } + /** @var \PhpParser\Node\Name $class */ + $class = $expression->class; + /** @var \PhpParser\Node\Identifier $name */ + $name = $expression->name; + return new ExtractedValueTransfer( - sprintf('%s::%s(%s)', $this->getCalleeName($expression->class->parts), $expression->name->name, implode(', ', $arguments)), + sprintf('%s::%s(%s)', $this->getCalleeName($class->parts), $name->name, implode(', ', $arguments)), true, ); } diff --git a/src/Builder/Extractor/ValueExtractor/ValueExtractorStrategyCollection.php b/src/Builder/Extractor/ValueExtractor/ValueExtractorStrategyCollection.php index 8123e93d..f8a5f46f 100644 --- a/src/Builder/Extractor/ValueExtractor/ValueExtractorStrategyCollection.php +++ b/src/Builder/Extractor/ValueExtractor/ValueExtractorStrategyCollection.php @@ -71,8 +71,10 @@ protected function getStrategies(): array return $this->strategiesCache; } - foreach (static::STRATEGIES as $strategy) { - $this->strategiesCache[] = new $strategy(); + foreach (static::STRATEGIES as $strategyClass) { + /** @var \SprykerSdk\Integrator\Builder\Extractor\ValueExtractor\ValueExtractorStrategyInterface $strategy */ + $strategy = new $strategyClass(); + $this->strategiesCache[] = $strategy; } return $this->strategiesCache; diff --git a/src/Builder/Extractor/ValueExtractor/VariableExtractorStrategy.php b/src/Builder/Extractor/ValueExtractor/VariableExtractorStrategy.php index 642153bc..09456f42 100644 --- a/src/Builder/Extractor/ValueExtractor/VariableExtractorStrategy.php +++ b/src/Builder/Extractor/ValueExtractor/VariableExtractorStrategy.php @@ -35,6 +35,6 @@ public function extractValue( Expr $expression, ValueExtractorStrategyCollection $valueExtractorStrategyCollection ): ExtractedValueTransfer { - return new ExtractedValueTransfer(sprintf('$%s', (string)$expression->name), true); + return new ExtractedValueTransfer(sprintf('$%s', is_string($expression->name) ? $expression->name : 'var'), true); } } diff --git a/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php b/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php index e5b6d479..9d739cc8 100644 --- a/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php +++ b/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php @@ -27,7 +27,7 @@ class AddArrayItemToEnvConfigVisitor extends NodeVisitorAbstract protected $target; /** - * @var array<\PhpParser\Node> + * @var \PhpParser\Node\Expr\ArrayItem */ protected $value;