Skip to content

Commit 023a28a

Browse files
committed
Rectify
1 parent 611ed6e commit 023a28a

31 files changed

+167
-251
lines changed

src/Psalm/CodeLocation.php

+5-21
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class CodeLocation
5151

5252
protected int $file_end;
5353

54-
protected bool $single_line;
55-
5654
protected int $preview_start;
5755

5856
private int $preview_end = -1;
@@ -67,20 +65,12 @@ class CodeLocation
6765

6866
private string $snippet = '';
6967

70-
private ?string $text = null;
71-
7268
public ?int $docblock_start = null;
7369

7470
private ?int $docblock_start_line_number = null;
7571

76-
protected ?int $docblock_line_number = null;
77-
78-
private ?int $regex_type = null;
79-
8072
private bool $have_recalculated = false;
8173

82-
public ?CodeLocation $previous_location = null;
83-
8474
public const VAR_TYPE = 0;
8575
public const FUNCTION_RETURN_TYPE = 1;
8676
public const FUNCTION_PARAM_TYPE = 2;
@@ -119,11 +109,11 @@ class CodeLocation
119109
public function __construct(
120110
FileSource $file_source,
121111
PhpParser\Node $stmt,
122-
?CodeLocation $previous_location = null,
123-
bool $single_line = false,
124-
?int $regex_type = null,
125-
?string $selected_text = null,
126-
?int $comment_line = null,
112+
public ?CodeLocation $previous_location = null,
113+
protected bool $single_line = false,
114+
private ?int $regex_type = null,
115+
private ?string $text = null,
116+
protected ?int $docblock_line_number = null,
127117
) {
128118
/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
129119
$this->file_start = (int)$stmt->getAttribute('startFilePos');
@@ -133,10 +123,6 @@ public function __construct(
133123
$this->raw_file_end = $this->file_end;
134124
$this->file_path = $file_source->getFilePath();
135125
$this->file_name = $file_source->getFileName();
136-
$this->single_line = $single_line;
137-
$this->regex_type = $regex_type;
138-
$this->previous_location = $previous_location;
139-
$this->text = $selected_text;
140126

141127
/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
142128
$doc_comment = $stmt->getDocComment();
@@ -148,8 +134,6 @@ public function __construct(
148134

149135
/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
150136
$this->raw_line_number = $stmt->getStartLine();
151-
152-
$this->docblock_line_number = $comment_line;
153137
}
154138

155139
/**

src/Psalm/Codebase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ public function filterCompletionItemsByBeginLiteralPart(array $items, string $li
17491749

17501750
$res = [];
17511751
foreach ($items as $item) {
1752-
if ($item->insertText && strpos($item->insertText, $literal_part) === 0) {
1752+
if ($item->insertText && str_starts_with($item->insertText, $literal_part)) {
17531753
$res[] = $item;
17541754
}
17551755
}

src/Psalm/Config.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1166,13 +1166,13 @@ private static function fromXmlAndPaths(
11661166
}
11671167

11681168
if ($paths_to_check !== null) {
1169-
$paths_to_add_to_project_files = array();
1169+
$paths_to_add_to_project_files = [];
11701170
foreach ($paths_to_check as $path) {
11711171
// if we have an .xml arg here, the files passed are invalid
11721172
// valid cases (in which we don't want to add CLI passed files to projectFiles though)
11731173
// are e.g. if running phpunit tests for psalm itself
1174-
if (substr($path, -4) === '.xml') {
1175-
$paths_to_add_to_project_files = array();
1174+
if (str_ends_with($path, '.xml')) {
1175+
$paths_to_add_to_project_files = [];
11761176
break;
11771177
}
11781178

@@ -1195,14 +1195,14 @@ private static function fromXmlAndPaths(
11951195
$paths_to_add_to_project_files[] = $prospective_path;
11961196
}
11971197

1198-
if ($paths_to_add_to_project_files !== array() && !isset($config_xml->projectFiles)) {
1198+
if ($paths_to_add_to_project_files !== [] && !isset($config_xml->projectFiles)) {
11991199
if ($config_xml === null) {
12001200
$config_xml = new SimpleXMLElement('<psalm/>');
12011201
}
12021202
$config_xml->addChild('projectFiles');
12031203
}
12041204

1205-
if ($paths_to_add_to_project_files !== array() && isset($config_xml->projectFiles)) {
1205+
if ($paths_to_add_to_project_files !== [] && isset($config_xml->projectFiles)) {
12061206
foreach ($paths_to_add_to_project_files as $path) {
12071207
if (is_dir($path)) {
12081208
$child = $config_xml->projectFiles->addChild('directory');
@@ -2201,7 +2201,7 @@ public function visitPreloadedStubFiles(Codebase $codebase, ?Progress $progress
22012201
foreach ($stub_files as $file_path) {
22022202
$file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path);
22032203
// fix mangled phar paths on Windows
2204-
if (strpos($file_path, 'phar:\\\\') === 0) {
2204+
if (str_starts_with($file_path, 'phar:\\\\')) {
22052205
$file_path = 'phar://'. substr($file_path, 7);
22062206
}
22072207
$codebase->scanner->addFileToDeepScan($file_path);
@@ -2290,7 +2290,7 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
22902290
foreach ($stub_files as $file_path) {
22912291
$file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path);
22922292
// fix mangled phar paths on Windows
2293-
if (strpos($file_path, 'phar:\\\\') === 0) {
2293+
if (str_starts_with($file_path, 'phar:\\\\')) {
22942294
$file_path = 'phar://' . substr($file_path, 7);
22952295
}
22962296
$codebase->scanner->addFileToDeepScan($file_path);

src/Psalm/FileBasedPluginAdapter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class FileBasedPluginAdapter implements PluginEntryPointInterface
2727
public function __construct(
2828
string $path,
2929
private readonly Config $config,
30-
private Codebase $codebase,
30+
private readonly Codebase $codebase,
3131
) {
3232
if (!$path) {
3333
throw new UnexpectedValueException('$path cannot be empty');

src/Psalm/Internal/Analyzer/ProjectAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ final class ProjectAnalyzer
109109
/**
110110
* An object representing everything we know about the code
111111
*/
112-
private Codebase $codebase;
112+
private readonly Codebase $codebase;
113113

114114
private readonly FileProvider $file_provider;
115115

src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ private static function analyzeOperands(
688688
&& strtolower($non_decimal_type->value) === "decimal\\decimal"
689689
) {
690690
$result_type = Type::combineUnionTypes(
691-
new Union([new TNamedObject("Decimal\\Decimal")]),
691+
new Union([new TNamedObject(\Decimal\Decimal::class)]),
692692
$result_type,
693693
);
694694
} else {

src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ private static function verifyCallableInContext(
14151415
return false;
14161416
}
14171417
}
1418-
} catch (UnexpectedValueException $e) {
1418+
} catch (UnexpectedValueException) {
14191419
// do nothing
14201420
}
14211421
}

src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ private static function handleByRefReadonlyArg(
12781278

12791279
try {
12801280
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
1281-
} catch (InvalidArgumentException $_) {
1281+
} catch (InvalidArgumentException) {
12821282
return;
12831283
}
12841284

src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ private static function taintReturnType(
637637
$pattern = trim($pattern);
638638
if ($pattern[0] === '['
639639
&& $pattern[1] === '^'
640-
&& substr($pattern, -1) === ']'
640+
&& str_ends_with($pattern, ']')
641641
) {
642642
$pattern = substr($pattern, 2, -1);
643643

src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class HighOrderFunctionArgInfo
2727
*/
2828
public function __construct(
2929
private readonly string $type,
30-
private FunctionLikeStorage $function_storage,
30+
private readonly FunctionLikeStorage $function_storage,
3131
private readonly ?ClassLikeStorage $class_storage = null,
3232
) {
3333
}

src/Psalm/Internal/Analyzer/StatementsAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ private function parseStatementDocblock(
798798
if ($this->parsed_docblock === null) {
799799
try {
800800
$this->parsed_docblock = DocComment::parsePreservingLength($docblock, true);
801-
} catch (DocblockParseException $e) {
801+
} catch (DocblockParseException) {
802802
// already reported above
803803
}
804804
}

src/Psalm/Internal/Analyzer/TraitAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
Trait_ $class,
2121
SourceAnalyzer $source,
2222
string $fq_class_name,
23-
private Aliases $aliases,
23+
private readonly Aliases $aliases,
2424
) {
2525
$this->source = $source;
2626
$this->file_analyzer = $source->getFileAnalyzer();

src/Psalm/Internal/Cli/Psalm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ private static function getHelpText(): string
12411241
$formats = [];
12421242
/** @var string $value */
12431243
foreach ((new ReflectionClass(Report::class))->getConstants() as $constant => $value) {
1244-
if (strpos($constant, 'TYPE_') === 0) {
1244+
if (str_starts_with($constant, 'TYPE_')) {
12451245
$formats[] = $value;
12461246
}
12471247
}

src/Psalm/Internal/CliUtils.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,7 @@ public static function getPathsToCheck(string|array|false|null $f_paths): ?array
289289
if (str_starts_with($input_path, '--') && strlen($input_path) > 2) {
290290
// ignore --config psalm.xml
291291
// ignore common phpunit args that accept a class instead of a path, as this can cause issues on Windows
292-
$ignored_arguments = array(
293-
'config',
294-
'printer',
295-
'root',
296-
);
292+
$ignored_arguments = ['config', 'printer', 'root'];
297293

298294
if (in_array(substr($input_path, 2), $ignored_arguments, true)) {
299295
++$i;

src/Psalm/Internal/Codebase/InternalCallMapHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public static function getCallablesFromCallMap(string $function_id): ?array
299299
// removes `rw_` leftover from `&rw_haystack` or `&rw_needle` or `&rw_actual_name`
300300
// it doesn't have any specific meaning apart from `&` signifying that
301301
// the parameter is passed by reference (handled above)
302-
if ($by_reference && strlen($arg_name) > 3 && strpos($arg_name, 'rw_') === 0) {
302+
if ($by_reference && strlen($arg_name) > 3 && str_starts_with($arg_name, 'rw_')) {
303303
$arg_name = substr($arg_name, 3);
304304
}
305305

src/Psalm/Internal/Codebase/Populator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class Populator
5252
private array $invalid_class_storages = [];
5353

5454
public function __construct(
55-
private ClassLikeStorageProvider $classlike_storage_provider,
55+
private readonly ClassLikeStorageProvider $classlike_storage_provider,
5656
private readonly FileStorageProvider $file_storage_provider,
5757
private readonly ClassLikes $classlikes,
5858
private readonly FileReferenceProvider $file_reference_provider,

0 commit comments

Comments
 (0)