Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.10.x' into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 19, 2024
2 parents 2c11df5 + 9338fdf commit aedc049
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 56 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ jobs:
export PHPSTAN_SCOPE_CLASS=MyTestScope
ACTUAL=$(../../bin/phpstan dump-parameters -c phpstan.neon --json -l 9 | jq --raw-output '.scopeClass')
[[ "$ACTUAL" == "MyTestScope" ]];
- script: |
cd e2e/result-cache-8
composer install
../../bin/phpstan
OUTPUT=$(../../bin/phpstan 2>&1)
grep 'Warning: Result cache might not behave correctly' <<< "$OUTPUT"
grep 'ResultCache8E2E\\CustomRule' <<< "$OUTPUT"
steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions e2e/result-cache-8/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
24 changes: 24 additions & 0 deletions e2e/result-cache-8/build/CustomRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ResultCache8E2E;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node>
*/
class CustomRule implements Rule
{
public function getNodeType(): string
{
return Node::class;
}

public function processNode(Node $node, Scope $scope): array
{
return [];
}

}
24 changes: 24 additions & 0 deletions e2e/result-cache-8/build/CustomRule2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ResultCache8E2E;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node>
*/
class CustomRule2 implements Rule
{
public function getNodeType(): string
{
return Node::class;
}

public function processNode(Node $node, Scope $scope): array
{
return [];
}

}
14 changes: 14 additions & 0 deletions e2e/result-cache-8/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-webmozart-assert": "^1.2"
},
"autoload": {
"classmap": ["src"]
},
"autoload-dev": {
"classmap": [
"build"
]
}
}
132 changes: 132 additions & 0 deletions e2e/result-cache-8/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions e2e/result-cache-8/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
paths:
- src
level: 8

rules:
- ResultCache8E2E\CustomRule
- ResultCache8E2E\CustomRule3

services:
-
class: ResultCache8E2E\CustomRule2
tags:
- phpstan.rules.rule
24 changes: 24 additions & 0 deletions e2e/result-cache-8/src/CustomRule3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ResultCache8E2E;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node>
*/
class CustomRule3 implements Rule
{
public function getNodeType(): string
{
return Node::class;
}

public function processNode(Node $node, Scope $scope): array
{
return [];
}

}
8 changes: 8 additions & 0 deletions e2e/result-cache-8/src/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace ResultCache8E2E;

class Foo
{

}
68 changes: 14 additions & 54 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace PHPStan\Analyser\ResultCache;

use Nette\DI\Definitions\Statement;
use Nette\Neon\Neon;
use PHPStan\Analyser\AnalyserResult;
use PHPStan\Analyser\Error;
use PHPStan\Collectors\CollectedData;
use PHPStan\Command\Output;
use PHPStan\Dependency\ExportedNodeFetcher;
use PHPStan\Dependency\RootExportedNode;
use PHPStan\DependencyInjection\ProjectConfigHelper;
use PHPStan\File\CouldNotReadFileException;
use PHPStan\File\FileFinder;
use PHPStan\File\FileWriter;
Expand All @@ -23,15 +23,13 @@
use function array_filter;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function array_unique;
use function array_values;
use function count;
use function get_loaded_extensions;
use function implode;
use function is_array;
use function is_file;
use function is_string;
use function ksort;
use function sha1_file;
use function sort;
Expand Down Expand Up @@ -674,70 +672,32 @@ private function getProjectExtensionFiles(?array $projectConfig, array $dependen
$this->alreadyProcessed = [];
$projectExtensionFiles = [];
if ($projectConfig !== null) {
$services = array_merge(
$projectConfig['services'] ?? [],
$projectConfig['rules'] ?? [],
);
foreach ($services as $service) {
$classes = $this->getClassesFromConfigDefinition($service);
if (is_array($service)) {
foreach (['class', 'factory', 'implement'] as $key) {
if (!isset($service[$key])) {
continue;
}

$classes = array_merge($classes, $this->getClassesFromConfigDefinition($service[$key]));
}
$classes = ProjectConfigHelper::getServiceClassNames($projectConfig);
foreach ($classes as $class) {
if (!$this->reflectionProvider->hasClass($class)) {
continue;
}

foreach (array_unique($classes) as $class) {
if (!$this->reflectionProvider->hasClass($class)) {
continue;
}
$classReflection = $this->reflectionProvider->getClass($class);
$fileName = $classReflection->getFileName();
if ($fileName === null) {
continue;
}

$classReflection = $this->reflectionProvider->getClass($class);
$fileName = $classReflection->getFileName();
if ($fileName === null) {
$allServiceFiles = $this->getAllDependencies($fileName, $dependencies);
foreach ($allServiceFiles as $serviceFile) {
if (array_key_exists($serviceFile, $projectExtensionFiles)) {
continue;
}

$allServiceFiles = $this->getAllDependencies($fileName, $dependencies);
foreach ($allServiceFiles as $serviceFile) {
if (array_key_exists($serviceFile, $projectExtensionFiles)) {
continue;
}

$projectExtensionFiles[$serviceFile] = $this->getFileHash($serviceFile);
}
$projectExtensionFiles[$serviceFile] = $this->getFileHash($serviceFile);
}
}
}

return $projectExtensionFiles;
}

/**
* @param mixed $definition
* @return string[]
*/
private function getClassesFromConfigDefinition($definition): array
{
if (is_string($definition)) {
return [$definition];
}

if ($definition instanceof Statement) {
$entity = $definition->entity;
if (is_string($entity)) {
return [$entity];
} elseif (is_array($entity) && isset($entity[0]) && is_string($entity[0])) {
return [$entity[0]];
}
}

return [];
}

/**
* @param array<string, array<int, string>> $dependencies
* @return array<int, string>
Expand Down
Loading

0 comments on commit aedc049

Please sign in to comment.