Skip to content

Commit

Permalink
deprecate RectorConfig containerCacheDirectory() as no longer used by…
Browse files Browse the repository at this point in the history
… container, cleanup phpstan errors
  • Loading branch information
TomasVotruba committed Aug 17, 2023
1 parent 81caf1e commit 752dc4e
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 39 deletions.
1 change: 0 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
$rectorConfig->fileExtensions(['php']);

$rectorConfig->cacheDirectory(sys_get_temp_dir() . '/rector_cached_files');
$rectorConfig->containerCacheDirectory(sys_get_temp_dir());

// use faster in-memory cache in CI.
// CI always starts from scratch, therefore IO intensive caching is not worth it
Expand Down
3 changes: 3 additions & 0 deletions packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public function cacheDirectory(string $directoryPath): void
SimpleParameterProvider::setParameter(Option::CACHE_DIR, $directoryPath);
}

/**
* @deprecated Rector no longer user compiled container, but Laravel lazy one. So this option is not needed anymore.
*/
public function containerCacheDirectory(string $directoryPath): void
{
// container cache directory path must be a directory on the first place
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(

$containerFactory = new ContainerFactory(getcwd());
$this->container = $containerFactory->create(
SimpleParameterProvider::provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
sys_get_temp_dir() . '/phpstan-container-for-rector',
$additionalConfigFiles,
[]
);
Expand Down
33 changes: 1 addition & 32 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ parameters:
- '#Parameter \#1 \$node (.*?) of method Rector\\(.*?)Rector\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Core\\Contract\\Rector\\PhpRectorInterface\:\:refactor\(\)#'

# generics
- '#Method Rector\\Core\\PhpParser\\NodeTraverser\\RectorNodeTraverser\:\:traverse\(\) should return array<TNode of PhpParser\\Node\> but returns array<PhpParser\\Node\>#'
- '#Parameter \#1 \$stmts of class Rector\\Core\\PhpParser\\Node\\CustomNode\\FileWithoutNamespace constructor expects array<PhpParser\\Node\\Stmt\>, array<TNode of PhpParser\\Node\> given#'

# strict - resolve later
Expand Down Expand Up @@ -424,9 +423,6 @@ parameters:
message: '#Instead of "instanceof/is_a\(\)" use ReflectionProvider service or "\(new ObjectType\(<desired_type>\)\)\->isSuperTypeOf\(<element_type>\)" for static reflection to work#'
path: packages/Skipper/Skipper/SkipSkipper.php

# the local instanceof for known types
- '#Instead of "instanceof/is_a\(\)" use ReflectionProvider service or "\(new ObjectType\(<desired_type>\)\)\->isSuperTypeOf\(<element_type>\)" for static reflection to work#'

# required for reflection
-
message: '#Function "(.*?)\(\)" cannot be used/left in the code#'
Expand Down Expand Up @@ -518,9 +514,6 @@ parameters:
# useless
- '#Parameter \#1 \$suffix of method PHPUnit\\Framework\\Assert\:\:assertStringEndsWith\(\) expects non\-empty\-string, string given#'

# reported in configs
- '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#'

-
message: '#Function "function_exists\(\)" cannot be used/left in the code#'
path: src/functions/node_helper.php
Expand All @@ -537,9 +530,6 @@ parameters:
- '#Call to deprecated method getDirectClassNames\(\) of class PHPStan\\Type\\TypeUtils.*#'
- '#Parameter 3 should use "PHPStan\\Reflection\\ParameterReflectionWithPhpDocs" type as the only type passed to this method#'

# various usage
- '#Parameters should use "PHPStan\\DependencyInjection\\Container" types as the only types passed to this method#'

# actually used in global scope
-
message: '#Anonymous function has an unused use \$container#'
Expand Down Expand Up @@ -598,9 +588,6 @@ parameters:
message: '#Parameters should use "array" types as the only types passed to this method#'
path: packages/VersionBonding/PhpVersionedFilter.php

# for symfony configs check
- '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\tagged_iterator not found#'

-
message: '#Do not use static property#'
path: src/Configuration/Parameter/SimpleParameterProvider.php
Expand Down Expand Up @@ -633,26 +620,11 @@ parameters:
message: '#Parameters should use "Symfony\\Component\\Console\\Application\|string\|callable" types as the only types passed to this method#'
path: src/Util/Reflection/PrivatesAccessor.php

# false positives
- '#Property Rector\\PhpAttribute\\AnnotationToAttributeMapper\:\:\$annotationToAttributeMappers \(array<Rector\\PhpAttribute\\Contract\\AnnotationToAttributeMapperInterface>\) does not accept iterable<Rector\\PhpAttribute\\Contract\\AnnotationToAttributeMapperInterface>#'

# avoid circular dependency
-
message: '#\$this as argument is not allowed\. Refactor method to service composition#'
path: packages/NodeTypeResolver/NodeTypeResolver.php

- '#Call to an undefined method Rector\\Config\\RectorConfig\:\:(.*?)\(\)#'
- '#Call to an undefined method Illuminate\\Container\\Container\:\:(.*?)\(\)#'
- '#Parameter 1 should use "Illuminate\\Container\\Container" type as the only type passed to this method#'
- '#Parameter \#1 \$container of method Rector\\Core\\DependencyInjection\\LazyContainerFactory\:\:createPHPStanServices\(\) expects Rector\\Config\\RectorConfig, Illuminate\\Container\\Container given#'

- '#Property Rector\\Core\\Configuration\\ConfigInitializer\:\:\$rectors \(array<Rector\\Core\\Contract\\Rector\\RectorInterface>\) does not accept iterable<Rector\\Core\\Contract\\Rector\\RectorInterface>#'

# false positive
- '#Parameter \#1 \$commands of method Symfony\\Component\\Console\\Application\:\:addCommands\(\) expects array<Symfony\\Component\\Console\\Command\\Command>, iterable<Symfony\\Component\\Console\\Command\\Command> given#'

- '#Property Rector\\Core\\Console\\Command\\ListRulesCommand\:\:\$rectors \(array<Rector\\Core\\Contract\\Rector\\RectorInterface>\) does not accept array\|iterable<Rector\\Core\\Contract\\Rector\\RectorInterface>#'

# reflection property change
-
message: '#\$this as argument is not allowed\. Refactor method to service composition#'
Expand All @@ -665,9 +637,6 @@ parameters:

- '#Class "Rector\\Renaming\\Rector\\FileWithoutNamespace\\PseudoNamespaceToNamespaceRector" is missing @see annotation with test case class reference#'

# iterable mix
- '#Property Rector\\Core\\Configuration\\ConfigInitializer\:\:\$rectors \(array<Rector\\Core\\Contract\\Rector\\RectorInterface>\) does not accept array\|iterable<Rector\\Core\\Contract\\Rector\\RectorInterface>#'

# chicken/egg
-
message: '#Function "(d|dd)\(\)" cannot be used/left in the code#'
Expand All @@ -691,4 +660,4 @@ parameters:
message: '#Make callable type explicit\. Here is how\: https\://phpstan\.org/writing\-php\-code/phpdoc\-types\#callables#'
path: packages/Config/RectorConfig.php

- '#Method Rector\\Core\\PhpParser\\NodeTraverser\\RectorNodeTraverser\:\:__construct\(\) has parameter \$phpRectors with no value type specified in iterable type iterable#'
- '#Method Rector\\Core\\PhpParser\\NodeTraverser\\RectorNodeTraverser\:\:traverse\(\) should return array<TNode of PhpParser\\Node> but returns array<PhpParser\\Node>#'
5 changes: 2 additions & 3 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@
$content
),

static function (string $filePath, string $prefix, string $content): string {
static fn(string $filePath, string $prefix, string $content): string =>
// comment out
return str_replace('\\' . $prefix . '\trigger_deprecation(', '// \trigger_deprecation(', $content);
},
str_replace('\\' . $prefix . '\trigger_deprecation(', '// \trigger_deprecation(', $content),

static function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with($filePath, 'src/Application/VersionResolver.php')) {
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ final class Option

/**
* @internal Use @see \Rector\Config\RectorConfig::containerCacheDirectory() method
* @deprecated Rector no longer user compiled container, but Laravel lazy one. So this option is not needed anymore.
* @var string
*/
public const CONTAINER_CACHE_DIRECTORY = 'container-cache-directory';
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ public function create(): RectorConfig
$rectorConfig->indent(' ', 4);

$rectorConfig->fileExtensions(['php']);

$rectorConfig->cacheDirectory(sys_get_temp_dir() . '/rector_cached_files');
$rectorConfig->containerCacheDirectory(sys_get_temp_dir());

// make use of https://github.com/symplify/easy-parallel
$rectorConfig->singleton(Application::class, static function (): Application {
Expand Down

0 comments on commit 752dc4e

Please sign in to comment.