Skip to content

Commit

Permalink
Merge branch 'rector_pass' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 20, 2023
2 parents a243252 + 9d3fee4 commit 7ef19c5
Show file tree
Hide file tree
Showing 387 changed files with 2,162 additions and 4,655 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
"amphp/phpunit-util": "^3",
"bamarni/composer-bin-plugin": "^1.4",
"brianium/paratest": "^6.9",
"dg/bypass-finals": "^1.5",
"mockery/mockery": "^1.5",
"nunomaduro/mock-final-classes": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpdoc-parser": "^1.6",
"phpunit/phpunit": "^9.6",
"psalm/plugin-mockery": "^1.1",
"psalm/plugin-phpunit": "^0.18",
"rector/rector": "^0.18.5",
"slevomat/coding-standard": "^8.4",
"squizlabs/php_codesniffer": "^3.6",
"symfony/process": "^4.4 || ^5.0 || ^6.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/TemplateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use function strtolower;
use function trim;

class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer
final class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer
{
const VIEW_CLASS = 'Your\\View\\Class';
final public const VIEW_CLASS = 'Your\\View\\Class';

public function analyze(?Context $file_context = null, ?Context $global_context = null): void
{
Expand Down Expand Up @@ -148,7 +148,7 @@ private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt,
/**
* @param array<PhpParser\Node\Stmt> $stmts
*/
protected function checkWithViewClass(Context $context, array $stmts): void
private function checkWithViewClass(Context $context, array $stmts): void
{
$pseudo_method_stmts = [];

Expand Down
2 changes: 1 addition & 1 deletion examples/TemplateScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class TemplateScanner extends Psalm\Internal\Scanner\FileScanner

Check failure on line 17 in examples/TemplateScanner.php

View workflow job for this annotation

GitHub Actions / build

InvalidExtendClass

examples/TemplateScanner.php:17:31: InvalidExtendClass: Class Psalm\Examples\Template\TemplateScanner may not inherit from final class Psalm\Internal\Scanner\FileScanner (see https://psalm.dev/232)
{
const VIEW_CLASS = 'Your\\View\\Class';
final public const VIEW_CLASS = 'Your\\View\\Class';

public function scan(

Check failure on line 21 in examples/TemplateScanner.php

View workflow job for this annotation

GitHub Actions / build

MethodSignatureMismatch

examples/TemplateScanner.php:21:5: MethodSignatureMismatch: Method Psalm\Internal\Scanner\FileScanner::scan is declared final and cannot be overridden (see https://psalm.dev/042)
Codebase $codebase,
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/ClassUnqualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function strpos;
use function strtolower;

class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface
final class ClassUnqualifier implements AfterClassLikeExistenceCheckInterface
{
public static function afterClassLikeExistenceCheck(
AfterClassLikeExistenceCheckEvent $event
Expand All @@ -29,7 +29,7 @@ public static function afterClassLikeExistenceCheck(
return;
}

if (strpos($candidate_type, '\\' . $fq_class_name) !== false) {
if (str_contains($candidate_type, '\\' . $fq_class_name)) {
$type_tokens = TypeTokenizer::tokenize($candidate_type, false);

foreach ($type_tokens as &$type_token) {
Expand Down
8 changes: 4 additions & 4 deletions examples/plugins/FunctionCasingChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Checks that functions and methods are correctly-cased
*/
class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, AfterMethodCallAnalysisInterface
final class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, AfterMethodCallAnalysisInterface
{
public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $event): void
{
Expand Down Expand Up @@ -55,7 +55,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
} catch (Exception) {
// can throw if storage is missing
}
}
Expand Down Expand Up @@ -93,12 +93,12 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent
$statements_source->getSuppressedIssues(),
);
}
} catch (Exception $e) {
} catch (Exception) {
// can throw if storage is missing
}
}
}

class IncorrectFunctionCasing extends PluginIssue
final class IncorrectFunctionCasing extends PluginIssue
{
}
4 changes: 2 additions & 2 deletions examples/plugins/InternalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

use function strpos;

class InternalChecker implements AfterClassLikeAnalysisInterface
final class InternalChecker implements AfterClassLikeAnalysisInterface
{
/** @return null|false */
public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event): ?bool
{
$storage = $event->getClasslikeStorage();
if (!$storage->internal
&& strpos($storage->name, 'Psalm\\Internal') === 0
&& str_starts_with($storage->name, 'Psalm\\Internal')
&& $storage->location
) {
IssueBuffer::maybeAdd(
Expand Down
4 changes: 2 additions & 2 deletions examples/plugins/PreventFloatAssignmentChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Prevents any assignment to a float value
*/
class PreventFloatAssignmentChecker implements AfterExpressionAnalysisInterface
final class PreventFloatAssignmentChecker implements AfterExpressionAnalysisInterface
{
/**
* Called after an expression has been checked
Expand Down Expand Up @@ -40,6 +40,6 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve
}
}

class NoFloatAssignment extends PluginIssue
final class NoFloatAssignment extends PluginIssue
{
}
2 changes: 1 addition & 1 deletion examples/plugins/SafeArrayKeyChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent;
use Psalm\Plugin\EventHandler\RemoveTaintsInterface;

class SafeArrayKeyChecker implements RemoveTaintsInterface
final class SafeArrayKeyChecker implements RemoveTaintsInterface
{
/**
* Called to see what taints should be removed
Expand Down
6 changes: 3 additions & 3 deletions examples/plugins/StringChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function strpos;
use function strtolower;

class StringChecker implements AfterExpressionAnalysisInterface
final class StringChecker implements AfterExpressionAnalysisInterface
{
/**
* Called after an expression has been checked
Expand All @@ -31,8 +31,8 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve
if ($expr instanceof PhpParser\Node\Scalar\String_) {
$class_or_class_method = '/^\\\?Psalm(\\\[A-Z][A-Za-z0-9]+)+(::[A-Za-z0-9]+)?$/';

if (strpos($statements_source->getFileName(), 'base/DefinitionManager.php') === false
&& strpos($expr->value, 'TestController') === false
if (!str_contains($statements_source->getFileName(), 'base/DefinitionManager.php')
&& !str_contains($expr->value, 'TestController')
&& preg_match($class_or_class_method, $expr->value)
) {
/** @psalm-suppress PossiblyInvalidArrayAccess */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TString;

class EchoChecker implements AfterStatementAnalysisInterface
final class EchoChecker implements AfterStatementAnalysisInterface
{
/**
* Called after a statement has been checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Psalm\Plugin\RegistrationInterface;
use SimpleXMLElement;

class PluginEntryPoint implements PluginEntryPointInterface
final class PluginEntryPoint implements PluginEntryPointInterface
{
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null): void
{
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/autoload.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
Expand Down
50 changes: 2 additions & 48 deletions src/Psalm/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,6 @@

final class Aliases
{
/**
* @var array<lowercase-string, string>
*/
public array $uses;

/**
* @var array<lowercase-string, string>
*/
public array $uses_flipped;

/**
* @var array<lowercase-string, non-empty-string>
*/
public array $functions;

/**
* @var array<lowercase-string, string>
*/
public array $functions_flipped;

/**
* @var array<string, string>
*/
public array $constants;

/**
* @var array<string, string>
*/
public array $constants_flipped;

public ?string $namespace = null;

public ?int $namespace_first_stmt_start = null;

public ?int $uses_start = null;
Expand All @@ -54,21 +22,7 @@ final class Aliases
* @internal
* @psalm-mutation-free
*/
public function __construct(
?string $namespace = null,
array $uses = [],
array $functions = [],
array $constants = [],
array $uses_flipped = [],
array $functions_flipped = [],
array $constants_flipped = [],
) {
$this->namespace = $namespace;
$this->uses = $uses;
$this->functions = $functions;
$this->constants = $constants;
$this->uses_flipped = $uses_flipped;
$this->functions_flipped = $functions_flipped;
$this->constants_flipped = $constants_flipped;
public function __construct(public ?string $namespace = null, public array $uses = [], public array $functions = [], public array $constants = [], public array $uses_flipped = [], public array $functions_flipped = [], public array $constants_flipped = [])
{
}
}
47 changes: 11 additions & 36 deletions src/Psalm/CodeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,42 +219,17 @@ private function calculateRealLocation(): void
}

if ($this->regex_type !== null) {
switch ($this->regex_type) {
case self::VAR_TYPE:
$regex = '/@(?:psalm-)?var[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/';
break;

case self::FUNCTION_RETURN_TYPE:
$regex = '/\\:\s+(\\??\s*[A-Za-z0-9_\\\\\[\]]+)/';
break;

case self::FUNCTION_PARAM_TYPE:
$regex = '/^(\\??\s*[A-Za-z0-9_\\\\\[\]]+)\s/';
break;

case self::FUNCTION_PHPDOC_RETURN_TYPE:
$regex = '/@(?:psalm-)?return[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/';
break;

case self::FUNCTION_PHPDOC_METHOD:
$regex = '/@(?:psalm-)?method[ \t]+(.*)/';
break;

case self::FUNCTION_PHPDOC_PARAM_TYPE:
$regex = '/@(?:psalm-)?param[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/';
break;

case self::FUNCTION_PARAM_VAR:
$regex = '/(\$[^ ]*)/';
break;

case self::CATCH_VAR:
$regex = '/(\$[^ ^\)]*)/';
break;

default:
throw new UnexpectedValueException('Unrecognised regex type ' . $this->regex_type);
}
$regex = match ($this->regex_type) {
self::VAR_TYPE => '/@(?:psalm-)?var[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/',
self::FUNCTION_RETURN_TYPE => '/\\:\s+(\\??\s*[A-Za-z0-9_\\\\\[\]]+)/',
self::FUNCTION_PARAM_TYPE => '/^(\\??\s*[A-Za-z0-9_\\\\\[\]]+)\s/',
self::FUNCTION_PHPDOC_RETURN_TYPE => '/@(?:psalm-)?return[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/',
self::FUNCTION_PHPDOC_METHOD => '/@(?:psalm-)?method[ \t]+(.*)/',
self::FUNCTION_PHPDOC_PARAM_TYPE => '/@(?:psalm-)?param[ \t]+' . CommentAnalyzer::TYPE_REGEX . '/',
self::FUNCTION_PARAM_VAR => '/(\$[^ ]*)/',
self::CATCH_VAR => '/(\$[^ ^\)]*)/',
default => throw new UnexpectedValueException('Unrecognised regex type ' . $this->regex_type),
};

$preview_snippet = mb_strcut(
$file_contents,
Expand Down
Loading

0 comments on commit 7ef19c5

Please sign in to comment.