Skip to content

Commit

Permalink
Misc (#1312)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Nov 25, 2021
1 parent dc07c1f commit dfe5bcf
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
6 changes: 6 additions & 0 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,10 @@ final class AttributeKey
* @var string
*/
public const CREATED_BY_RULE = 'created_by_rule';

/**
* Provided by PHPStan parser, depth in sense of nesting
* @var string
*/
public const STATEMENT_DEPTH = 'statementDepth';
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class PHPStanNodeScopeResolver
*/
private const ANONYMOUS_CLASS_START_REGEX = '#^AnonymousClass(\w+)#';

/**
* @var string
*/
private const CONTEXT = 'context';

public function __construct(
private ChangedFilesDetector $changedFilesDetector,
private DependencyResolver $dependencyResolver,
Expand Down Expand Up @@ -74,7 +79,7 @@ public function processNodes(array $stmts, SmartFileInfo $smartFileInfo): array

$scopeContext = $this->traitScopeFaker->createDummyClassScopeContext($scope);
$traitScope = clone $scope;
$this->privatesAccessor->setPrivateProperty($traitScope, 'context', $scopeContext);
$this->privatesAccessor->setPrivateProperty($traitScope, self::CONTEXT, $scopeContext);

$traitScope = $traitScope->enterTrait($traitReflectionClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public function refactor(Node $node): ?Node
}

$parent = $node->getAttribute(AttributeKey::PARENT_NODE);

if (! $parent instanceof Node) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class SomeClass
{
public float $someVariable;
public function __construct(float $someVariable = 0.0)
{
public function __construct(
float $someVariable = 0.0
) {
$this->someVariable = $someVariable;
}
}
Expand All @@ -67,8 +68,9 @@ public function __construct(float $someVariable = 0.0)
<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(private float $someVariable = 0.0)
{
public function __construct(
private float $someVariable = 0.0
) {
}
}
CODE_SAMPLE
Expand Down
6 changes: 3 additions & 3 deletions rules/Php80/ValueObject/CondAndExpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
final class CondAndExpr
{
/**
* @param Expr[] $condExprs
* @param Expr[]|null $condExprs
*/
public function __construct(
private array $condExprs,
private array|null $condExprs,
private Expr $expr,
private MatchKind $matchKind
) {
Expand All @@ -25,7 +25,7 @@ public function getExpr(): Expr
}

/**
* @return Expr[]
* @return Expr[]|null
*/
public function getCondExprs(): array|null
{
Expand Down
4 changes: 2 additions & 2 deletions rules/Renaming/Rector/FuncCall/RenameFunctionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function refactor(Node $node): ?Node
}

/**
* @param array<string, array<string, string>> $configuration
* @param array<string, mixed[]> $configuration
*/
public function configure(array $configuration): void
{
$oldFunctionToNewFunction = $configuration[self::OLD_FUNCTION_TO_NEW_FUNCTION] ?? [];
$oldFunctionToNewFunction = $configuration[self::OLD_FUNCTION_TO_NEW_FUNCTION] ?? $configuration ?: [];
Assert::allString($oldFunctionToNewFunction);
Assert::allString(array_values($oldFunctionToNewFunction));

Expand Down
23 changes: 23 additions & 0 deletions tests/Issues/Issue6675/Fixture/bare_stmts.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Core\Tests\Issues\Issue6675\Fixture;

function someFunction()
{
$db = mysql_connect("server", "user", "password");
echo mysql_error();
}

?>
-----
<?php

namespace Rector\Core\Tests\Issues\Issue6675\Fixture;

function someFunction()
{
$db = mysqli_connect("server", "user", "password");
echo mysqli_error($db);
}

?>
4 changes: 2 additions & 2 deletions tests/Issues/Issue6675/Fixture/no_namespace.php.inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

$db = mysql_connect("server","user","password");
$db = mysql_connect("server", "user", "password");
echo mysql_error();

?>
-----
<?php

$db = mysqli_connect("server","user","password");
$db = mysqli_connect("server", "user", "password");
echo mysqli_error($db);

?>

0 comments on commit dfe5bcf

Please sign in to comment.