-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DX] Remove PackageBuilder classes (#2885)
- Loading branch information
1 parent
3c07468
commit 6cdebe4
Showing
12 changed files
with
196 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Console\Style; | ||
|
||
use Rector\Core\Util\Reflection\PrivatesAccessor; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class SymfonyStyleFactory | ||
{ | ||
public function __construct(private readonly PrivatesAccessor $privatesAccessor) | ||
{ | ||
} | ||
|
||
public function create(): SymfonyStyle | ||
{ | ||
// to prevent missing argv indexes | ||
if (! isset($_SERVER['argv'])) { | ||
$_SERVER['argv'] = []; | ||
} | ||
|
||
$argvInput = new ArgvInput(); | ||
$consoleOutput = new ConsoleOutput(); | ||
|
||
// to configure all -v, -vv, -vvv options without memory-lock to Application run() arguments | ||
$this->privatesAccessor->callPrivateMethod(new Application(), 'configureIO', [$argvInput, $consoleOutput]); | ||
|
||
// --debug is called | ||
if ($argvInput->hasParameterOption('--debug')) { | ||
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG); | ||
} | ||
|
||
// disable output for tests | ||
if ($this->isPHPUnitRun()) { | ||
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_QUIET); | ||
} | ||
|
||
return new SymfonyStyle($argvInput, $consoleOutput); | ||
} | ||
|
||
/** | ||
* Never ever used static methods if not neccesary, this is just handy for tests + src to prevent duplication. | ||
*/ | ||
private function isPHPUnitRun(): bool | ||
{ | ||
return defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Exception/Reflection/InvalidPrivatePropertyTypeException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Exception\Reflection; | ||
|
||
use Exception; | ||
|
||
final class InvalidPrivatePropertyTypeException extends Exception | ||
{ | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Exception/Reflection/MissingPrivatePropertyException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Exception\Reflection; | ||
|
||
use Exception; | ||
|
||
final class MissingPrivatePropertyException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Util; | ||
|
||
final class ArrayParametersMerger | ||
{ | ||
/** | ||
* Merges configurations. Left has higher priority than right one. | ||
* | ||
* @autor David Grudl (https://davidgrudl.com) | ||
* @source https://github.com/nette/di/blob/8eb90721a131262f17663e50aee0032a62d0ef08/src/DI/Config/Helpers.php#L31 | ||
*/ | ||
public function merge(mixed $left, mixed $right): mixed | ||
{ | ||
if (is_array($left) && is_array($right)) { | ||
return $this->mergeLeftToRightWithCallable( | ||
$left, | ||
$right, | ||
fn ($leftValue, $rightValue) => $this->merge($leftValue, $rightValue) | ||
); | ||
} | ||
|
||
if ($left !== null) { | ||
return $left; | ||
} | ||
|
||
if (! is_array($right)) { | ||
return $left; | ||
} | ||
|
||
return $right; | ||
} | ||
|
||
/** | ||
* The same as above, just with the case if both values being non-array, it will combined them to array: | ||
* | ||
* $this->mergeWithCombine(1, 2); // [1, 2] | ||
*/ | ||
public function mergeWithCombine(mixed $left, mixed $right): mixed | ||
{ | ||
if (is_array($left) && is_array($right)) { | ||
return $this->mergeLeftToRightWithCallable( | ||
$left, | ||
$right, | ||
fn ($leftValue, $rightValue) => $this->mergeWithCombine($leftValue, $rightValue) | ||
); | ||
} | ||
|
||
if ($left === null && is_array($right)) { | ||
return $right; | ||
} | ||
|
||
if (! empty($right) && (array) $left !== (array) $right) { | ||
return $this->mergeWithCombine((array) $right, (array) $left); | ||
} | ||
|
||
return $left; | ||
} | ||
|
||
/** | ||
* @param array<int|string, mixed> $left | ||
* @param array<int|string, mixed> $right | ||
* @return mixed[] | ||
*/ | ||
private function mergeLeftToRightWithCallable(array $left, array $right, callable $mergeCallback): array | ||
{ | ||
foreach ($left as $key => $val) { | ||
if (is_int($key)) { | ||
// prevent duplicated values in unindexed arrays | ||
if (! in_array($val, $right, true)) { | ||
$right[] = $val; | ||
} | ||
} else { | ||
if (isset($right[$key])) { | ||
$val = $mergeCallback($val, $right[$key]); | ||
} | ||
|
||
$right[$key] = $val; | ||
} | ||
} | ||
|
||
return $right; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters