1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 10:07:52 +01:00
This commit is contained in:
Daniil Gentili 2023-10-21 14:28:58 +02:00
parent e19caf0a16
commit 8ff340e588
14 changed files with 63 additions and 80 deletions

View File

@ -22,7 +22,14 @@ final class Aliases
* @internal * @internal
* @psalm-mutation-free * @psalm-mutation-free
*/ */
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 = []) 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 = [],
) {
} }
} }

View File

@ -289,7 +289,11 @@ final class Creator
$nodes = []; $nodes = [];
/** @var string[] */ /** @var string[] */
$php_files = [...glob($current_dir . DIRECTORY_SEPARATOR . '*.php', GLOB_NOSORT) ?: [], ...glob($current_dir . DIRECTORY_SEPARATOR . '**/*.php', GLOB_NOSORT) ?: [], ...glob($current_dir . DIRECTORY_SEPARATOR . '**/**/*.php', GLOB_NOSORT) ?: []]; $php_files = [
...glob($current_dir . DIRECTORY_SEPARATOR . '*.php', GLOB_NOSORT) ?: [],
...glob($current_dir . DIRECTORY_SEPARATOR . '**/*.php', GLOB_NOSORT) ?: [],
...glob($current_dir . DIRECTORY_SEPARATOR . '**/**/*.php', GLOB_NOSORT) ?: [],
];
foreach ($php_files as $php_file) { foreach ($php_files as $php_file) {
$php_file = str_replace($current_dir . DIRECTORY_SEPARATOR, '', $php_file); $php_file = str_replace($current_dir . DIRECTORY_SEPARATOR, '', $php_file);

View File

@ -200,7 +200,7 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer
?string $calling_method_id, ?string $calling_method_id,
array $suppressed_issues, array $suppressed_issues,
?ClassLikeNameOptions $options = null, ?ClassLikeNameOptions $options = null,
bool $check_classes = true bool $check_classes = true,
): ?bool { ): ?bool {
if ($options === null) { if ($options === null) {
$options = new ClassLikeNameOptions(); $options = new ClassLikeNameOptions();

View File

@ -9,7 +9,13 @@ namespace Psalm\Internal\Analyzer;
*/ */
final class ClassLikeNameOptions final class ClassLikeNameOptions
{ {
public function __construct(public bool $inferred = false, public bool $allow_trait = false, public bool $allow_interface = true, public bool $allow_enum = true, public bool $from_docblock = false, public bool $from_attribute = false) public function __construct(
{ public bool $inferred = false,
public bool $allow_trait = false,
public bool $allow_interface = true,
public bool $allow_enum = true,
public bool $from_docblock = false,
public bool $from_attribute = false,
) {
} }
} }

View File

@ -14,7 +14,18 @@ final class DataFlowNodeData
{ {
use ImmutableNonCloneableTrait; use ImmutableNonCloneableTrait;
public function __construct(public string $label, public int $line_from, public int $line_to, public string $file_name, public string $file_path, public string $snippet, public int $from, public int $to, public int $snippet_from, public int $column_from, public int $column_to) public function __construct(
{ public string $label,
public int $line_from,
public int $line_to,
public string $file_name,
public string $file_path,
public string $snippet,
public int $from,
public int $to,
public int $snippet_from,
public int $column_from,
public int $column_to,
) {
} }
} }

View File

@ -99,8 +99,11 @@ class FileAnalyzer extends SourceAnalyzer
private ?Union $return_type = null; private ?Union $return_type = null;
public function __construct(public ProjectAnalyzer $project_analyzer, protected string $file_path, protected string $file_name) public function __construct(
{ public ProjectAnalyzer $project_analyzer,
protected string $file_path,
protected string $file_name,
) {
$this->source = $this; $this->source = $this;
$this->codebase = $project_analyzer->getCodebase(); $this->codebase = $project_analyzer->getCodebase();
} }

View File

@ -134,8 +134,11 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
/** /**
* @param TFunction $function * @param TFunction $function
*/ */
public function __construct(protected Closure|Function_|ClassMethod|ArrowFunction $function, SourceAnalyzer $source, protected FunctionLikeStorage $storage) public function __construct(
{ protected Closure|Function_|ClassMethod|ArrowFunction $function,
SourceAnalyzer $source,
protected FunctionLikeStorage $storage,
) {
$this->source = $source; $this->source = $source;
$this->suppressed_issues = $source->getSuppressedIssues(); $this->suppressed_issues = $source->getSuppressedIssues();
$this->codebase = $source->getCodebase(); $this->codebase = $source->getCodebase();

View File

@ -16,10 +16,7 @@ final class IssueData
public const SEVERITY_INFO = 'info'; public const SEVERITY_INFO = 'info';
public const SEVERITY_ERROR = 'error'; public const SEVERITY_ERROR = 'error';
/** public readonly string $link;
* @readonly
*/
public string $link;
/** /**
* @param self::SEVERITY_* $severity * @param self::SEVERITY_* $severity
@ -30,53 +27,23 @@ final class IssueData
public string $severity, public string $severity,
public int $line_from, public int $line_from,
public int $line_to, public int $line_to,
/** public readonly string $type,
* @readonly public readonly string $message,
*/ public readonly string $file_name,
public string $type, public readonly string $file_path,
/** public readonly string $snippet,
* @readonly public readonly string $selected_text,
*/
public string $message,
/**
* @readonly
*/
public string $file_name,
/**
* @readonly
*/
public string $file_path,
/**
* @readonly
*/
public string $snippet,
/**
* @readonly
*/
public string $selected_text,
public int $from, public int $from,
public int $to, public int $to,
public int $snippet_from, public int $snippet_from,
public int $snippet_to, public int $snippet_to,
/** public readonly int $column_from,
* @readonly public readonly int $column_to,
*/ public readonly int $shortcode = 0,
public int $column_from,
/**
* @readonly
*/
public int $column_to,
/**
* @readonly
*/
public int $shortcode = 0,
public int $error_level = -1, public int $error_level = -1,
public ?array $taint_trace = null, public ?array $taint_trace = null,
public ?array $other_references = null, public ?array $other_references = null,
/** public readonly ?string $dupe_key = null,
* @readonly
*/
public ?string $dupe_key = null,
) { ) {
$this->link = $shortcode ? 'https://psalm.dev/' . str_pad((string) $shortcode, 3, "0", STR_PAD_LEFT) : ''; $this->link = $shortcode ? 'https://psalm.dev/' . str_pad((string) $shortcode, 3, "0", STR_PAD_LEFT) : '';
} }

View File

@ -8,9 +8,7 @@ use PhpParser;
use UnexpectedValueException; use UnexpectedValueException;
use function count; use function count;
use function get_class;
use function is_string; use function is_string;
use function strpos;
use function str_contains; use function str_contains;
use function strtolower; use function strtolower;
use function substr; use function substr;

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Psalm\Internal\LanguageServer; namespace Psalm\Internal\LanguageServer;
use JsonMapper;
use LanguageServerProtocol\LogMessage; use LanguageServerProtocol\LogMessage;
use LanguageServerProtocol\LogTrace; use LanguageServerProtocol\LogTrace;
use Psalm\Internal\LanguageServer\Client\Progress\LegacyProgress; use Psalm\Internal\LanguageServer\Client\Progress\LegacyProgress;

View File

@ -20,14 +20,8 @@ abstract class CodeIssue
public ?string $dupe_key = null; public ?string $dupe_key = null;
public function __construct( public function __construct(
/** public readonly string $message,
* @readonly public readonly CodeLocation $code_location,
*/
public string $message,
/**
* @readonly
*/
public CodeLocation $code_location,
) { ) {
} }

View File

@ -19,14 +19,8 @@ abstract class TaintedInput extends CodeIssue
public function __construct( public function __construct(
string $message, string $message,
CodeLocation $code_location, CodeLocation $code_location,
/** public readonly array $journey,
* @readonly public readonly string $journey_text,
*/
public array $journey,
/**
* @readonly
*/
public string $journey_text,
) { ) {
parent::__construct($message, $code_location); parent::__construct($message, $code_location);
} }

View File

@ -13,10 +13,7 @@ use Psalm\Type\Union;
final class NotInArray extends Assertion final class NotInArray extends Assertion
{ {
public function __construct( public function __construct(
/** public readonly Union $type,
* @readonly
*/
public Union $type,
) { ) {
} }

View File

@ -632,7 +632,7 @@ class EnumTest extends TestCase
$foo = FooEnum::Foo->value; $foo = FooEnum::Foo->value;
noop($foo); noop($foo);
noop(FooEnum::Foo->value); noop(FooEnum::Foo->value);
PHP PHP,
], ],
'backedEnumCaseValueFromClassConstant' => [ 'backedEnumCaseValueFromClassConstant' => [
'code' => <<<'PHP' 'code' => <<<'PHP'