Skip to content

Commit

Permalink
remove nette/utils dependency, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 6, 2024
1 parent 7b650d9 commit d6301ad
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/downgraded_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
# avoid infinite looping, skip tags that ends with ".72"
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches
- '*'
- '!**.72'

jobs:
downgrade_release:
Expand All @@ -31,10 +30,10 @@ jobs:

# get rector to "rector-local" directory, to avoid downgrading itself in the /vendor
- run: mkdir rector-local
- run: composer require rector/rector:^0.17.1 --working-dir rector-local --ansi
- run: composer require rector/rector:^1.1 --working-dir rector-local --ansi

# downgrade to PHP 7.2
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi
- run: rector-local/vendor/bin/rector process src --config build/rector-downgrade-php-72.php --ansi

# clear the dev files
- run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig
Expand All @@ -43,7 +42,7 @@ jobs:
- run: cp -r build/target-repository/. .

# clear the dev files
- run: rm -rf build monorepo-builder.php full-tool-build.sh rector.php phpstan-for-tests.neon tests
- run: rm -rf build full-tool-build.sh rector.php tests

# setup git user
-
Expand Down
13 changes: 1 addition & 12 deletions build/rector-downgrade-php-72.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveInterfacesRector;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();

$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);

$rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [
DocumentedRuleInterface::class,
ConfigurableRuleInterface::class,
]);

$rectorConfig->skip(['*/Tests/*', '*/tests/*', __DIR__ . '/../../tests']);
$rectorConfig->skip(['*/tests/*']);
};

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"require": {
"php": "^8.2",
"phpstan/phpstan": "^1.11",
"webmozart/assert": "^1.11",
"nette/utils": "^4.0"
"webmozart/assert": "^1.11"
},
"require-dev": {
"nikic/php-parser": "^4.19",
Expand Down
2 changes: 1 addition & 1 deletion full-tool-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ rm -rf tests
# downgrade with rector
mkdir rector-local
composer require rector/rector --working-dir rector-local
rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php-72.php --ansi
rector-local/vendor/bin/rector process src --config build/rector-downgrade-php-72.php --ansi
6 changes: 4 additions & 2 deletions src/Reflection/ReflectionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\TypePerfect\Reflection;

use Nette\Utils\FileSystem;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\NodeFinder;
Expand Down Expand Up @@ -47,7 +46,10 @@ private function parseFilenameToClass(string $fileName): ClassLike|null
}

try {
$stmts = $this->parser->parse(FileSystem::read($fileName));
/** @var string $fileContents */
$fileContents = file_get_contents($fileName);

$stmts = $this->parser->parse($fileContents);
if (! is_array($stmts)) {
return null;
}
Expand Down
20 changes: 18 additions & 2 deletions src/Rules/NarrowPublicClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\TypePerfect\Rules;

use Nette\Utils\Arrays;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\CollectedDataNode;
Expand Down Expand Up @@ -92,7 +91,8 @@ private function resolveClassMethodReferenceToArgTypes(CollectedDataNode $collec

// these should be skipped completely, as we have no idea what is being passed there
$methodCallablesByFilePath = $collectedDataNode->get(MethodCallableCollector::class);
$methodFirstClassCallables = Arrays::flatten($methodCallablesByFilePath);

$methodFirstClassCallables = $this->flattenCollectedData($methodCallablesByFilePath);

// group call references and types
$classMethodReferenceToTypes = [];
Expand Down Expand Up @@ -143,4 +143,20 @@ private function resolveUniqueArgTypesString(

return $collectedArgTypes[0];
}

/**
* @param mixed[] $methodCallablesByFilePath
* @return mixed[]
*/
private function flattenCollectedData(array $methodCallablesByFilePath): array
{
$methodFirstClassCallables = [];
foreach ($methodCallablesByFilePath as $collectedData) {
foreach ($collectedData as $collectedItem) {
$methodFirstClassCallables[] = $collectedItem[0];
}
}

return $methodFirstClassCallables;
}
}

0 comments on commit d6301ad

Please sign in to comment.