Skip to content

Commit

Permalink
SKD-5377: Introduce ENV array element manifest type / phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavStrelchenko committed Nov 24, 2023
1 parent 24376b5 commit 36e4e34
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ protected function createArrayStringFromResult(array $array): string
*/
protected function isConstant(string $value): bool
{
return strpos($value, '::');
return (bool)strpos($value, '::');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AddArrayItemToEnvConfigVisitor extends NodeVisitorAbstract
protected $target;

/**
* @var array<\PhpParser\Node>
* @var \PhpParser\Node\Expr\ArrayItem
*/
protected $value;

Expand Down

0 comments on commit 36e4e34

Please sign in to comment.