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
13 changes: 13 additions & 0 deletions rules/code-quality/src/CompactConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ public function __construct(ValueResolver $valueResolver)
$this->valueResolver = $valueResolver;
}

public function hasAllArgumentsNamed(FuncCall $funcCall): bool
{
foreach ($funcCall->args as $arg) {
/** @var string|null $variableName */
$variableName = $this->valueResolver->getValue($arg->value);
if (! is_string($variableName)) {
return false;
}
}

return true;
}

public function convertToArray(FuncCall $funcCall): Array_
{
$array = new Array_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->compactConverter->hasAllArgumentsNamed($node)) {
return null;
}

return $this->compactConverter->convertToArray($node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\CodeQuality\Tests\Rector\FuncCall\CompactToVariablesRector\Fixture;

class SkipUnknown
{
public function run()
{
$names = ['one', 'two'];

return compact($names);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ final class SyncAnnotationParserCommand extends Command
*/
public function __construct(array $classSyncers, SymfonyStyle $symfonyStyle, ParameterProvider $parameterProvider)
{
parent::__construct();

$this->symfonyStyle = $symfonyStyle;
$this->classSyncers = $classSyncers;
$this->parameterProvider = $parameterProvider;

parent::__construct();
}

protected function configure(): void
{
// disable imports
$this->parameterProvider->changeParameter(Option::AUTO_IMPORT_NAMES, false);

$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('[DOC] Generate value-preserving DocParser from doctrine/annotation');

Expand All @@ -63,6 +60,9 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
// disable imports
$this->parameterProvider->changeParameter(Option::AUTO_IMPORT_NAMES, false);

$dryRun = (bool) $input->getOption(Option::OPTION_DRY_RUN);

foreach ($this->classSyncers as $classSyncer) {
Expand Down