Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

[PHPStan] fixes #2876

Merged
merged 5 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ocramius/package-versions": "^1.4",
"phar-io/version": "^3.0.3",
"phpstan/phpdoc-parser": "^0.4.9",
"phpstan/phpstan": "^0.12.64",
"phpstan/phpstan": "^0.12.64, <0.12.70",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some bug with abstract class resolution in PHPStan 0.12.70, so we need to fallback.
It can be spotted in Symplify\PHPStanRules\Rules\NoParentMethodCallOnEmptyStatementInParentMethodRule while parsing parent method content by php-parser

"phpunit/phpunit": "^9.5",
"psr/simple-cache": "^1.0",
"sebastian/diff": "^3.0|^4.0",
Expand Down Expand Up @@ -65,8 +65,7 @@
"symfony/security-core": "^4.4|^5.1",
"symfony/templating": "^4.4|^5.1",
"symfony/translation": "^4.4|^5.1",
"symfony/twig-bundle": "^4.4|^5.1",
"tracy/tracy": "^2.8.1"
"symfony/twig-bundle": "^4.4|^5.1"
},
"autoload": {
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function detectRepositoryUrlFromGit(): string

private function detectRepositoryName(ContainerBuilder $containerBuilder): string
{
$repositoryUrl = $containerBuilder->getParameter(Option::REPOSITORY_URL);
$repositoryUrl = (string) $containerBuilder->getParameter(Option::REPOSITORY_URL);

return Strings::substring($repositoryUrl, Strings::length('https://github.com/'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@

declare(strict_types=1);

namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;
namespace Symplify\MonorepoBuilder\Merge\Arrays;

use Symplify\MonorepoBuilder\Merge\Arrays\ArraySorter;
use Symplify\PackageBuilder\Yaml\ParametersMerger;

abstract class AbstractComposerKeyMerger
final class SortedParameterMerger
{
/**
* @var ParametersMerger
*/
protected $parametersMerger;
private $parametersMerger;

/**
* @var ArraySorter
*/
protected $arraySorter;
private $arraySorter;

/**
* @required
*/
public function autowireAbstractComposerKeyMerger(
ParametersMerger $parametersMerger,
ArraySorter $arraySorter
): void {
public function __construct(ParametersMerger $parametersMerger, ArraySorter $arraySorter)
{
$this->parametersMerger = $parametersMerger;
$this->arraySorter = $arraySorter;
}

/**
* @return mixed[]
*/
protected function mergeRecursiveAndSort(array $firstArray, array $secondArray): array
public function mergeRecursiveAndSort(array $firstArray, array $secondArray): array
{
$mergedArray = $this->parametersMerger->mergeWithCombine($firstArray, $secondArray);

Expand All @@ -43,7 +37,7 @@ protected function mergeRecursiveAndSort(array $firstArray, array $secondArray):
/**
* @return mixed[]
*/
protected function mergeAndSort(array $firstArray, array $secondArray): array
public function mergeAndSort(array $firstArray, array $secondArray): array
{
$mergedArray = $this->parametersMerger->merge($firstArray, $secondArray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class AuthorComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class AuthorComposerKeyMerger implements ComposerKeyMergerInterface
{
public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;
use Symplify\MonorepoBuilder\Merge\Validation\AutoloadPathValidator;

final class AutoloadComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class AutoloadComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var AutoloadPathValidator
*/
private $autoloadPathValidator;

public function __construct(AutoloadPathValidator $autoloadPathValidator)
{
/**
* @var SortedParameterMerger
*/
private $sortedParameterMerger;

public function __construct(
AutoloadPathValidator $autoloadPathValidator,
SortedParameterMerger $sortedParameterMerger
) {
$this->autoloadPathValidator = $autoloadPathValidator;
$this->sortedParameterMerger = $sortedParameterMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
Expand All @@ -28,7 +37,10 @@ public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJ

$this->autoloadPathValidator->ensureAutoloadPathExists($newComposerJson);

$autoload = $this->mergeRecursiveAndSort($mainComposerJson->getAutoload(), $newComposerJson->getAutoload());
$autoload = $this->sortedParameterMerger->mergeRecursiveAndSort(
$mainComposerJson->getAutoload(),
$newComposerJson->getAutoload()
);
$mainComposerJson->setAutoload($autoload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;
use Symplify\MonorepoBuilder\Merge\Validation\AutoloadPathValidator;

final class AutoloadDevComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class AutoloadDevComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var AutoloadPathValidator
*/
private $autoloadPathValidator;

public function __construct(AutoloadPathValidator $autoloadPathValidator)
{
/**
* @var SortedParameterMerger
*/
private $sortedParameterMerger;

public function __construct(
AutoloadPathValidator $autoloadPathValidator,
SortedParameterMerger $sortedParameterMerger
) {
$this->autoloadPathValidator = $autoloadPathValidator;
$this->sortedParameterMerger = $sortedParameterMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
Expand All @@ -28,7 +37,7 @@ public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJ

$this->autoloadPathValidator->ensureAutoloadPathExists($newComposerJson);

$autoloadDev = $this->mergeRecursiveAndSort(
$autoloadDev = $this->sortedParameterMerger->mergeRecursiveAndSort(
$mainComposerJson->getAutoloadDev(),
$newComposerJson->getAutoloadDev()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;
use Symplify\PackageBuilder\Yaml\ParametersMerger;

final class ExtraComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class ExtraComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var string
*/
private const PHPSTAN = 'phpstan';

/**
* @var ParametersMerger
*/
private $parametersMerger;

public function __construct(ParametersMerger $parametersMerger)
{
$this->parametersMerger = $parametersMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
if ($newComposerJson->getExtra() === []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class MinimalStabilityKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class MinimalStabilityKeyMerger implements ComposerKeyMergerInterface
{
public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class PreferStableKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class PreferStableKeyMerger implements ComposerKeyMergerInterface
{
public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class RepositoriesComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class RepositoriesComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var SortedParameterMerger
*/
private $sortedParameterMerger;

public function __construct(SortedParameterMerger $sortedParameterMerger)
{
$this->sortedParameterMerger = $sortedParameterMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
if ($newComposerJson->getRepositories() === []) {
return;
}

$repositories = $this->mergeRecursiveAndSort(
$repositories = $this->sortedParameterMerger->mergeRecursiveAndSort(
$mainComposerJson->getRepositories(),
$newComposerJson->getRepositories()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@
namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class RequireComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class RequireComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var SortedParameterMerger
*/
private $sortedParameterMerger;

public function __construct(SortedParameterMerger $sortedParameterMerger)
{
$this->sortedParameterMerger = $sortedParameterMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
if ($newComposerJson->getRequire() === []) {
return;
}

$require = $this->mergeAndSort($newComposerJson->getRequire(), $mainComposerJson->getRequire());
$require = $this->sortedParameterMerger->mergeAndSort(
$newComposerJson->getRequire(),
$mainComposerJson->getRequire()
);
$mainComposerJson->setRequire($require);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@
namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger;

use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger;
use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface;

final class RequireDevComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface
final class RequireDevComposerKeyMerger implements ComposerKeyMergerInterface
{
/**
* @var SortedParameterMerger
*/
private $sortedParameterMerger;

public function __construct(SortedParameterMerger $sortedParameterMerger)
{
$this->sortedParameterMerger = $sortedParameterMerger;
}

public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void
{
if ($newComposerJson->getRequireDev() === []) {
return;
}

$requireDev = $this->mergeAndSort($newComposerJson->getRequireDev(), $mainComposerJson->getRequireDev());
$requireDev = $this->sortedParameterMerger->mergeAndSort(
$newComposerJson->getRequireDev(),
$mainComposerJson->getRequireDev()
);
$mainComposerJson->setRequireDev($requireDev);
}
}
8 changes: 7 additions & 1 deletion packages/phpstan-rules/src/ParentClassMethodNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Parser;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use ReflectionMethod;
use Symplify\SmartFileSystem\SmartFileSystem;
use Throwable;

Expand Down Expand Up @@ -48,7 +49,12 @@ public function resolveParentClassMethodNodes(Scope $scope, string $methodName):
/** @var ClassReflection[] $parentClassReflections */
$parentClassReflections = $this->getParentClassReflections($scope);
foreach ($parentClassReflections as $parentClassReflection) {
$fileName = $parentClassReflection->getFileName();
if (! $parentClassReflection->hasMethod($methodName)) {
continue;
}

$parentMethodReflection = new ReflectionMethod($parentClassReflection->getName(), $methodName);
$fileName = $parentMethodReflection->getFileName();
if ($fileName === false) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Symplify\PHPStanRules\Rules;

use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createDatabase(): void
{
/** @var Connection $connection */
$connection = $this->container->get('doctrine.dbal.default_connection');
$databaseName = $this->container->getParameter('database_name');
$databaseName = (string) $this->container->getParameter('database_name');

/** @var AbstractSchemaManager $schemaManager */
$schemaManager = $connection->getSchemaManager();
Expand Down
9 changes: 8 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- packages/phpstan-extensions/config/config.neon
- packages/phpstan-rules/config/symplify-rules.neon
# for cognitive rules
Expand Down Expand Up @@ -425,3 +424,11 @@ parameters:
path: packages/coding-standard/src/Php/PhpContentAnalyzer.php

- '#Content of method "create\(\)" is duplicated with method "create\(\)" in "Symplify\\MarkdownDiff\\Diff\\Output\\CompleteUnifiedDiffOutputBuilderFactory" class\. Use unique content or abstract service instead#'
- '#Content of method "create\(\)" is duplicated with method "create\(\)" in "Symplify\\ConsoleColorDiff\\Diff\\Output\\CompleteUnifiedDiffOutputBuilderFactory" class\. Use unique content or abstract service instead#'

# parameters in tests
-
message: '#Cannot cast array\|bool\|float\|int\|string\|null to string#'
paths:
- packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php
- packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php