Skip to content
Closed
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
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
"tests/Source",
"tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Source",
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source",
"stubs",
"tests/Issues/Issue1243/Source",
"packages/Autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Expected",
"packages/Autodiscovery/tests/Rector/FileSystem/MoveServicesBySuffixToDirectoryRector/Expected"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,24 @@
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Rector\Util\RectorStrings;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Process\Process;

/**
* @see https://github.com/symfony/symfony/pull/27821/files
*
* @see \Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\StringToArrayArgumentProcessRectorTest
*/
final class StringToArrayArgumentProcessRector extends AbstractRector
{
/**
* @var string
*/
private $processClass;

/**
* @var string
*/
private $processHelperClass;

/**
* @var NodeTransformer
*/
private $nodeTransformer;

public function __construct(
NodeTransformer $nodeTransformer,
string $processClass = 'Symfony\Component\Process\Process',
string $processHelperClass = 'Symfony\Component\Console\Helper\ProcessHelper'
) {
public function __construct(NodeTransformer $nodeTransformer)
{
$this->nodeTransformer = $nodeTransformer;
$this->processClass = $processClass;
$this->processHelperClass = $processHelperClass;
}

public function getDefinition(): RectorDefinition
Expand Down Expand Up @@ -79,11 +67,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($this->isObjectType($node, $this->processClass)) {
if ($this->isObjectType($node, Process::class)) {
return $this->processArgumentPosition($node, 0);
}

if ($this->isObjectType($node, $this->processHelperClass)) {
if ($this->isObjectType($node, ProcessHelper::class)) {
return $this->processArgumentPosition($node, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

function stringToArgumentArray()
{
Expand All @@ -27,7 +27,7 @@ function stringToArgumentArray()

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

function stringToArgumentArray()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Symfony\Component\Process\Process;

function stringToArgumentArray3()
{
Expand All @@ -20,7 +22,9 @@ function stringToArgumentArray3()
-----
<?php

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Symfony\Component\Process\Process;

function stringToArgumentArray3()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

function stringToArgumentArray4()
{
Expand All @@ -15,7 +15,7 @@ function stringToArgumentArray4()

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

function stringToArgumentArray4()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\ProcessHelper;
use Symfony\Component\Console\Output\ConsoleOutput;
namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Symfony\Component\Console\Helper\ProcessHelper;

function stringToArgumentArray2()
{
Expand All @@ -15,8 +16,9 @@ function stringToArgumentArray2()
-----
<?php

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\ProcessHelper;
use Symfony\Component\Console\Output\ConsoleOutput;
namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Symfony\Component\Console\Helper\ProcessHelper;

function stringToArgumentArray2()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use stdClass;

class SkipFormAdd
{
public function run(FormBuilderInterface $formBuilder)
{
$formBuilder->add('q', stdClass::class);

}
}

interface FormBuilderInterface
{
/**
* @param string|FormBuilderInterface $child
* @param string|null $type
*/
public function add($child, $type = null, array $options = []);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

class WithSprintf
{
Expand All @@ -18,7 +18,7 @@ class WithSprintf

namespace Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Fixture;

use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Symfony\Component\Process\Process;

class WithSprintf
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Iterator;
use Rector\Symfony\Rector\New_\StringToArrayArgumentProcessRector;
use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\Process;
use Rector\Symfony\Tests\Rector\New_\StringToArrayArgumentProcessRector\Source\ProcessHelper;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class StringToArrayArgumentProcessRectorTest extends AbstractRectorTestCase
Expand All @@ -21,23 +19,16 @@ public function test(string $file): void
public function provideDataForTest(): Iterator
{
yield [__DIR__ . '/Fixture/fixture.php.inc'];
yield [__DIR__ . '/Fixture/fixture2.php.inc'];
yield [__DIR__ . '/Fixture/process_helper.php.inc'];
yield [__DIR__ . '/Fixture/fixture3.php.inc'];
yield [__DIR__ . '/Fixture/fixture4.php.inc'];
yield [__DIR__ . '/Fixture/with_sprintf.php.inc'];
yield [__DIR__ . '/Fixture/skip_anonymous_class.php.inc'];
yield [__DIR__ . '/Fixture/skip_form_add.php.inc'];
}

/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
protected function getRectorClass(): string
{
return [
StringToArrayArgumentProcessRector::class => [
'$processClass' => Process::class,
'$processHelperClass' => ProcessHelper::class,
],
];
return StringToArrayArgumentProcessRector::class;
}
}
12 changes: 12 additions & 0 deletions stubs/Symfony/Component/Console/Helper/ProcessHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Symfony\Component\Console\Helper;

if (class_exists('Symfony\Component\Console\Helper\ProcessHelper')) {
return;
}

class ProcessHelper
{

}
12 changes: 12 additions & 0 deletions stubs/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Symfony\Component\Process;

if (class_exists('Symfony\Component\Process\Process')) {
return;
}

class Process
{

}