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
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ matrix:
env: STANDALONE=true
- php: '7.3'
env: DOG_FOOD=true
- php: '7.4snapshot'

install:
- composer update $COMPOSER_FLAGS
Expand All @@ -47,14 +46,14 @@ script:
- |
if [[ $STATIC_ANALYSIS == true ]]; then
composer docs
php bin/check_services_in_yaml_configs.php
php bin/run_all_sets.php
php ci/check_services_in_yaml_configs.php
php ci/run_all_sets.php
fi

# Eat your own dog food
- |
if [[ $DOG_FOOD == true ]]; then
bin/rector process src --set dead-code --dry-run
composer rector
fi

# Run standalone install in non-root package, ref https://github.com/rectorphp/rector/issues/732
Expand Down
8 changes: 7 additions & 1 deletion bin/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

declare(strict_types=1);

use Rector\Console\Option\SetOptionResolver;
use Rector\Bootstrap\ConfigResolver;
use Rector\Bootstrap\SetOptionResolver;
use Rector\DependencyInjection\RectorContainerFactory;
use Rector\Exception\Configuration\SetNotFoundException;
use Rector\Set\Set;
Expand Down Expand Up @@ -31,6 +32,11 @@
// remove empty values
$configs = array_filter($configs);

// resolve: parameters > sets
$configResolver = new ConfigResolver();
$parameterSetsConfigs = $configResolver->resolveFromParameterSetsFromConfigFiles($configs);
$configs = array_merge($configs, $parameterSetsConfigs);

// Build DI container
$rectorContainerFactory = new RectorContainerFactory();
return $rectorContainerFactory->createFromConfigs($configs);
File renamed without changes.
3 changes: 1 addition & 2 deletions bin/run_all_sets.php → ci/run_all_sets.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
}

foreach ($errors as $error) {
echo $error;
echo PHP_EOL;
echo $error . PHP_EOL;
}

exit(ShellCode::ERROR);
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"check-cs": "vendor/bin/ecs check bin packages src tests utils --ansi",
"fix-cs": [
"vendor/bin/ecs check bin packages src tests utils --fix --ansi",
"bin/clean_trailing_spaces.sh"
"ci/clean_trailing_spaces.sh"
],
"phpstan": "vendor/bin/phpstan analyse packages src tests --error-format symplify --ansi",
"changelog": [
Expand All @@ -199,7 +199,8 @@
"docs": [
"bin/rector dump-rectors -o markdown > docs/AllRectorsOverview.md",
"bin/rector dump-nodes -o markdown > docs/NodesOverview.md"
]
],
"rector": "bin/rector process packages src --config rector-ci.yaml --dry-run"
},
"scripts-descriptions": {
"docs": "Regenerate descriptions of all Rectors to docs/AllRectorsOverview.md file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ private function resolveFetchedLocalPropertyNameToType(Class_ $class): array
return null;
}

if (! $node->var instanceof Variable) {
return null;
}

if (! $this->isName($node->var, 'this')) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Psr\Container\ContainerInterface;
use Rector\Exception\ShouldNotHappenException;

final class StaticContainerGetDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
Expand All @@ -32,7 +31,8 @@ public function getTypeFromMethodCall(
MethodCall $methodCall,
Scope $scope
): Type {
$valueType = $scope->getType($methodCall->args[0]->value);
$value = $methodCall->args[0]->value;
$valueType = $scope->getType($value);

// we don't know what it is
if ($valueType instanceof MixedType) {
Expand All @@ -43,10 +43,7 @@ public function getTypeFromMethodCall(
return new ObjectType($valueType->getValue());
}

throw new ShouldNotHappenException(sprintf(
'%s type given, only "%s" is supported',
get_class($valueType),
ConstantStringType::class
));
// unknown, probably variable
return new MixedType();
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ parameters:

- '#Method Rector\\Symfony\\Bridge\\DefaultAnalyzedSymfonyApplicationContainer\:\:getService\(\) should return object but returns object\|null#'
- '#Call to function property_exists\(\) with string and (.*?) will always evaluate to false#'
- '#Method Rector\\Console\\Option\\SetOptionResolver\:\:separateVersionedAndUnversionedSets\(\) should return array<array<string\>\> but returns array<int, array<int\|string, array<int, string\>\|string\>\>#'
- '#Method Rector\\Bootstrap\\SetOptionResolver\:\:separateVersionedAndUnversionedSets\(\) should return array<array<string\>\> but returns array<int, array<int\|string, array<int, string\>\|string\>\>#'
- '#Access to an undefined property PhpParser\\Node\\FunctionLike\|PhpParser\\Node\\Stmt\\ClassLike\:\:\$stmts#'

- '#Property Rector\\TypeDeclaration\\TypeInferer\\(.*?)\:\:\$(.*?)TypeInferers \(array<Rector\\TypeDeclaration\\Contract\\TypeInferer\\(.*?)TypeInfererInterface\>\) does not accept array<Rector\\TypeDeclaration\\Contract\\TypeInferer\\PriorityAwareTypeInfererInterface\>#'
Expand Down
9 changes: 9 additions & 0 deletions rector-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
exclude_paths:
- "/Fixture/"
- "/Fixtures/"
- "/Source/"
- "/Expected/"

sets:
- "code-quality"
14 changes: 0 additions & 14 deletions sample/ScreenSample.php

This file was deleted.

52 changes: 52 additions & 0 deletions src/Bootstrap/ConfigResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Rector\Bootstrap;

use Rector\Set\Set;

final class ConfigResolver
{
/**
* @var SetOptionResolver
*/
private $setOptionResolver;

/**
* @var SetsResolver
*/
private $setsResolver;

public function __construct()
{
$this->setOptionResolver = new SetOptionResolver();
$this->setsResolver = new SetsResolver();
}

/**
* @param string[] $configFiles
* @return string[]
*/
public function resolveFromParameterSetsFromConfigFiles(array $configFiles): array
{
$configs = [];

$sets = $this->setsResolver->resolveFromConfigFiles($configFiles);
return array_merge($configs, $this->resolveFromSets($sets));
}

/**
* @param string[] $sets
* @return string[]
*/
private function resolveFromSets(array $sets): array
{
$configs = [];
foreach ($sets as $set) {
$configs[] = $this->setOptionResolver->detectFromNameAndDirectory($set, Set::SET_DIRECTORY);
}

return $configs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Console\Option;
namespace Rector\Bootstrap;

use Nette\Utils\ObjectHelpers;
use Nette\Utils\Strings;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function detectFromInputAndDirectory(InputInterface $input, string $confi
return $this->detectFromNameAndDirectory($setName, $configDirectory);
}

public function detectFromNameAndDirectory(string $setName, string $configDirectory): ?string
public function detectFromNameAndDirectory(string $setName, string $configDirectory): string
{
$nearestMatches = $this->findNearestMatchingFiles($configDirectory, $setName);
if (count($nearestMatches) === 0) {
Expand Down
26 changes: 26 additions & 0 deletions src/Bootstrap/SetsResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Rector\Bootstrap;

use Symfony\Component\Yaml\Yaml;

final class SetsResolver
{
/**
* @param string[] $configFiles
* @return string[]
*/
public function resolveFromConfigFiles(array $configFiles): array
{
$sets = [];

foreach ($configFiles as $configFile) {
$configContent = Yaml::parseFile($configFile);
$sets += $configContent['parameters']['sets'] ?? [];
}

return $sets;
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/RectorContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\DependencyInjection;

use Psr\Container\ContainerInterface;
use Rector\Console\Option\SetOptionResolver;
use Rector\Bootstrap\SetOptionResolver;
use Rector\Exception\ShouldNotHappenException;
use Rector\HttpKernel\RectorKernel;
use Rector\Set\Set;
Expand Down