Skip to content

Commit

Permalink
Rectify
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Nov 23, 2024
1 parent 611ed6e commit 023a28a
Show file tree
Hide file tree
Showing 31 changed files with 167 additions and 251 deletions.
26 changes: 5 additions & 21 deletions src/Psalm/CodeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class CodeLocation

protected int $file_end;

protected bool $single_line;

protected int $preview_start;

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

private string $snippet = '';

private ?string $text = null;

public ?int $docblock_start = null;

private ?int $docblock_start_line_number = null;

protected ?int $docblock_line_number = null;

private ?int $regex_type = null;

private bool $have_recalculated = false;

public ?CodeLocation $previous_location = null;

public const VAR_TYPE = 0;
public const FUNCTION_RETURN_TYPE = 1;
public const FUNCTION_PARAM_TYPE = 2;
Expand Down Expand Up @@ -119,11 +109,11 @@ class CodeLocation
public function __construct(

Check failure on line 109 in src/Psalm/CodeLocation.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Parameter 5 of Psalm\CodeLocation#__construct() changed name from selected_text to text

Check failure on line 109 in src/Psalm/CodeLocation.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Parameter 6 of Psalm\CodeLocation#__construct() changed name from comment_line to docblock_line_number
FileSource $file_source,
PhpParser\Node $stmt,
?CodeLocation $previous_location = null,
bool $single_line = false,
?int $regex_type = null,
?string $selected_text = null,
?int $comment_line = null,
public ?CodeLocation $previous_location = null,
protected bool $single_line = false,
private ?int $regex_type = null,
private ?string $text = null,
protected ?int $docblock_line_number = null,
) {
/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
$this->file_start = (int)$stmt->getAttribute('startFilePos');
Expand All @@ -133,10 +123,6 @@ public function __construct(
$this->raw_file_end = $this->file_end;
$this->file_path = $file_source->getFilePath();
$this->file_name = $file_source->getFileName();
$this->single_line = $single_line;
$this->regex_type = $regex_type;
$this->previous_location = $previous_location;
$this->text = $selected_text;

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

/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
$this->raw_line_number = $stmt->getStartLine();

$this->docblock_line_number = $comment_line;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ public function filterCompletionItemsByBeginLiteralPart(array $items, string $li

$res = [];
foreach ($items as $item) {
if ($item->insertText && strpos($item->insertText, $literal_part) === 0) {
if ($item->insertText && str_starts_with($item->insertText, $literal_part)) {
$res[] = $item;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,13 @@ private static function fromXmlAndPaths(
}

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

Expand All @@ -1195,14 +1195,14 @@ private static function fromXmlAndPaths(
$paths_to_add_to_project_files[] = $prospective_path;
}

if ($paths_to_add_to_project_files !== array() && !isset($config_xml->projectFiles)) {
if ($paths_to_add_to_project_files !== [] && !isset($config_xml->projectFiles)) {
if ($config_xml === null) {
$config_xml = new SimpleXMLElement('<psalm/>');
}
$config_xml->addChild('projectFiles');
}

if ($paths_to_add_to_project_files !== array() && isset($config_xml->projectFiles)) {
if ($paths_to_add_to_project_files !== [] && isset($config_xml->projectFiles)) {
foreach ($paths_to_add_to_project_files as $path) {
if (is_dir($path)) {
$child = $config_xml->projectFiles->addChild('directory');
Expand Down Expand Up @@ -2201,7 +2201,7 @@ public function visitPreloadedStubFiles(Codebase $codebase, ?Progress $progress
foreach ($stub_files as $file_path) {
$file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path);
// fix mangled phar paths on Windows
if (strpos($file_path, 'phar:\\\\') === 0) {
if (str_starts_with($file_path, 'phar:\\\\')) {
$file_path = 'phar://'. substr($file_path, 7);
}
$codebase->scanner->addFileToDeepScan($file_path);
Expand Down Expand Up @@ -2290,7 +2290,7 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
foreach ($stub_files as $file_path) {
$file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path);
// fix mangled phar paths on Windows
if (strpos($file_path, 'phar:\\\\') === 0) {
if (str_starts_with($file_path, 'phar:\\\\')) {
$file_path = 'phar://' . substr($file_path, 7);
}
$codebase->scanner->addFileToDeepScan($file_path);
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/FileBasedPluginAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class FileBasedPluginAdapter implements PluginEntryPointInterface
public function __construct(
string $path,
private readonly Config $config,
private Codebase $codebase,
private readonly Codebase $codebase,
) {
if (!$path) {
throw new UnexpectedValueException('$path cannot be empty');
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final class ProjectAnalyzer
/**
* An object representing everything we know about the code
*/
private Codebase $codebase;
private readonly Codebase $codebase;

private readonly FileProvider $file_provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ private static function analyzeOperands(
&& strtolower($non_decimal_type->value) === "decimal\\decimal"
) {
$result_type = Type::combineUnionTypes(
new Union([new TNamedObject("Decimal\\Decimal")]),
new Union([new TNamedObject(\Decimal\Decimal::class)]),
$result_type,
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ private static function verifyCallableInContext(
return false;
}
}
} catch (UnexpectedValueException $e) {
} catch (UnexpectedValueException) {
// do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ private static function handleByRefReadonlyArg(

try {
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
} catch (InvalidArgumentException $_) {
} catch (InvalidArgumentException) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ private static function taintReturnType(
$pattern = trim($pattern);
if ($pattern[0] === '['
&& $pattern[1] === '^'
&& substr($pattern, -1) === ']'
&& str_ends_with($pattern, ']')
) {
$pattern = substr($pattern, 2, -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class HighOrderFunctionArgInfo
*/
public function __construct(
private readonly string $type,
private FunctionLikeStorage $function_storage,
private readonly FunctionLikeStorage $function_storage,
private readonly ?ClassLikeStorage $class_storage = null,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ private function parseStatementDocblock(
if ($this->parsed_docblock === null) {
try {
$this->parsed_docblock = DocComment::parsePreservingLength($docblock, true);
} catch (DocblockParseException $e) {
} catch (DocblockParseException) {
// already reported above
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/TraitAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
Trait_ $class,
SourceAnalyzer $source,
string $fq_class_name,
private Aliases $aliases,
private readonly Aliases $aliases,
) {
$this->source = $source;
$this->file_analyzer = $source->getFileAnalyzer();
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ private static function getHelpText(): string
$formats = [];
/** @var string $value */
foreach ((new ReflectionClass(Report::class))->getConstants() as $constant => $value) {
if (strpos($constant, 'TYPE_') === 0) {
if (str_starts_with($constant, 'TYPE_')) {
$formats[] = $value;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Psalm/Internal/CliUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,7 @@ public static function getPathsToCheck(string|array|false|null $f_paths): ?array
if (str_starts_with($input_path, '--') && strlen($input_path) > 2) {
// ignore --config psalm.xml
// ignore common phpunit args that accept a class instead of a path, as this can cause issues on Windows
$ignored_arguments = array(
'config',
'printer',
'root',
);
$ignored_arguments = ['config', 'printer', 'root'];

if (in_array(substr($input_path, 2), $ignored_arguments, true)) {
++$i;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/InternalCallMapHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public static function getCallablesFromCallMap(string $function_id): ?array
// removes `rw_` leftover from `&rw_haystack` or `&rw_needle` or `&rw_actual_name`
// it doesn't have any specific meaning apart from `&` signifying that
// the parameter is passed by reference (handled above)
if ($by_reference && strlen($arg_name) > 3 && strpos($arg_name, 'rw_') === 0) {
if ($by_reference && strlen($arg_name) > 3 && str_starts_with($arg_name, 'rw_')) {
$arg_name = substr($arg_name, 3);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Codebase/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class Populator
private array $invalid_class_storages = [];

public function __construct(
private ClassLikeStorageProvider $classlike_storage_provider,
private readonly ClassLikeStorageProvider $classlike_storage_provider,
private readonly FileStorageProvider $file_storage_provider,
private readonly ClassLikes $classlikes,
private readonly FileReferenceProvider $file_reference_provider,
Expand Down
Loading

0 comments on commit 023a28a

Please sign in to comment.