Skip to content

Commit

Permalink
[PHPStan] Resolve variable name casing (#2689)
Browse files Browse the repository at this point in the history
* [PHPStan] Resolve variable name casing

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Tomas Votruba <tomas.vot@gmail.com>
  • Loading branch information
3 people committed Jul 20, 2022
1 parent 9cb0a5e commit ae31fb6
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function __construct(

public function getRealPath(): string
{
$realpath = realpath($this->filePath);
if ($realpath === false) {
$realPath = realpath($this->filePath);
if ($realPath === false) {
throw new ShouldNotHappenException();
}

return $realpath;
return $realPath;
}

public function getFilePath(): string
Expand Down
6 changes: 4 additions & 2 deletions packages/StaticTypeMapper/Naming/NameScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ private function resolveTemplateTypesFromNode(Node $node): array
$templateTypes = [];

foreach ($phpDocInfo->getTemplateTagValueNodes() as $templateTagValueNode) {
$phpstanType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($templateTagValueNode, $node);
$templateTypes[$templateTagValueNode->name] = $phpstanType;
$templateTypes[$templateTagValueNode->name] = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType(
$templateTagValueNode,
$node
);
}

return $templateTypes;
Expand Down
8 changes: 4 additions & 4 deletions packages/Testing/TestingParser/TestingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public function parseFilePathToFile(string $filePath): File
/**
* @return Node[]
*/
public function parseFileToDecoratedNodes(string $filepath): array
public function parseFileToDecoratedNodes(string $filePath): array
{
// autoload file
require_once $filepath;
require_once $filePath;

$smartFileInfo = new SmartFileInfo($filepath);
$this->parameterProvider->changeParameter(Option::SOURCE, [$filepath]);
$smartFileInfo = new SmartFileInfo($filePath);
$this->parameterProvider->changeParameter(Option::SOURCE, [$filePath]);

$nodes = $this->rectorParser->parseFile($smartFileInfo);

Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,3 @@ parameters:
count: 1

# @todo resolve later
- '#Lowered variable "(.*?)" is used in various\-cased names\: "(.*?)", unite it to one#'
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class SkipReferenceInSerivceConfigurator
$containerBuilder = $this->createContainerBuilder();
$phpFileLoader = $this->createPhpFileLoader($containerBuilder);

$instanceOf = [];
return new ServicesConfigurator($containerBuilder, $phpFileLoader, $instanceOf);
$instanceof = [];
return new ServicesConfigurator($containerBuilder, $phpFileLoader, $instanceof);
}

private function createPhpFileLoader(ContainerBuilder $containerBuilder): PhpFileLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ private function resolveDuplicatedInstancesOf(BinaryOp $binaryOp): array
});

$uniqueInstanceOfKeys = [];
foreach ($instanceOfs as $instanceOf) {
$uniqueKey = $this->instanceOfUniqueKeyResolver->resolve($instanceOf);
foreach ($instanceOfs as $instanceof) {
$uniqueKey = $this->instanceOfUniqueKeyResolver->resolve($instanceof);
if ($uniqueKey === null) {
continue;
}

// already present before → duplicated
if (in_array($uniqueKey, $uniqueInstanceOfKeys, true)) {
$duplicatedInstanceOfs[] = $instanceOf;
$duplicatedInstanceOfs[] = $instanceof;
}

$uniqueInstanceOfKeys[] = $uniqueKey;
Expand Down
4 changes: 2 additions & 2 deletions rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ private function shouldSkipFromNotTypedParam(Instanceof_ $instanceof): bool
}

$variable = $instanceof->expr;
$isReassign = (bool) $this->betterNodeFinder->findFirstPrevious(
$isReAssign = (bool) $this->betterNodeFinder->findFirstPrevious(
$instanceof,
fn (Node $subNode): bool => $subNode instanceof Assign && $this->nodeComparator->areNodesEqual(
$subNode->var,
$variable
)
);

if ($isReassign) {
if ($isReAssign) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private function createMultipleIfs(Expr $expr, Return_ $return, array $ifs): arr
* @param If_[] $ifs
* @return If_[]
*/
private function collectLeftBooleanOrToIfs(BooleanOr $BooleanOr, Return_ $return, array $ifs): array
private function collectLeftBooleanOrToIfs(BooleanOr $booleanOr, Return_ $return, array $ifs): array
{
$left = $BooleanOr->left;
$left = $booleanOr->left;
if (! $left instanceof BooleanOr) {
return [$this->ifManipulator->createIfStmt($left, new Return_($this->nodeFactory->createTrue()))];
}
Expand Down
3 changes: 1 addition & 2 deletions rules/Strict/NodeFactory/ExactCompareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ private function createTruthyFromUnionType(
}

if ($unionType instanceof TypeWithClassName) {
$instanceOf = new Instanceof_($expr, new FullyQualified($unionType->getClassName()));
return new BooleanNot($instanceOf);
return new BooleanNot(new Instanceof_($expr, new FullyQualified($unionType->getClassName())));
}

$toNullIdentical = new Identical($expr, $this->nodeFactory->createNull());
Expand Down
6 changes: 3 additions & 3 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ private function resolvePhpFilePaths(array $files): array

foreach ($files as $file) {
$smartFileInfo = $file->getSmartFileInfo();
$pathName = $smartFileInfo->getPathname();
$pathname = $smartFileInfo->getPathname();

if (\str_ends_with($pathName, '.php')) {
$filePaths[] = $pathName;
if (\str_ends_with($pathname, '.php')) {
$filePaths[] = $pathname;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/FileSystem/PhpFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ public function findInPaths(array $paths): array

// filter out non-PHP files
foreach ($phpFileInfos as $key => $phpFileInfo) {
$pathName = $phpFileInfo->getPathname();
$pathname = $phpFileInfo->getPathname();

/**
* check .blade.php early so next .php check in next if can be skipped
*/
if (str_ends_with($pathName, '.blade.php')) {
if (str_ends_with($pathname, '.blade.php')) {
unset($phpFileInfos[$key]);
continue;
}

/**
* obvious
*/
if (str_ends_with($pathName, '.php')) {
if (str_ends_with($pathname, '.php')) {
continue;
}

/**
* only check with regex when needed
*/
if (StringUtils::isMatch($pathName, $suffixRegexPattern)) {
if (StringUtils::isMatch($pathname, $suffixRegexPattern)) {
unset($phpFileInfos[$key]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/NodeAnalyzer/TerminatedNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ private function isTerminatedInLastStmtsIf(If_ $if, Stmt $stmt): bool
return false;
}

foreach ($if->elseifs as $elseIf) {
if (! $this->isTerminatedInLastStmts($elseIf->stmts, $stmt)) {
foreach ($if->elseifs as $elseif) {
if (! $this->isTerminatedInLastStmts($elseif->stmts, $stmt)) {
return false;
}
}
Expand Down

0 comments on commit ae31fb6

Please sign in to comment.