Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm v6: strict_types=1 #10044

Merged
merged 51 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
07b013d
Enable strict_types
danog Jul 24, 2023
51cb9c7
Fix
danog Jul 24, 2023
7975164
Small fix
danog Jul 24, 2023
b65d793
Fix scanning of intersection types
danog Jul 24, 2023
d320f07
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 24, 2023
93443f2
Small fix
danog Jul 24, 2023
1ad9fc6
Fixes
danog Jul 25, 2023
6b54ea2
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 25, 2023
8cc5af9
Fix thread data merging
danog Jul 25, 2023
a281117
Fix
danog Jul 25, 2023
ac5dd77
Remove mistakenly (?) ignored functions
danog Jul 25, 2023
d3bea28
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 25, 2023
f21390d
Remove extremely strange logic
danog Jul 25, 2023
e8b8aa3
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 25, 2023
5e77f1b
Fixes
danog Jul 25, 2023
9d85198
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 25, 2023
7e605f0
Fixup
danog Jul 25, 2023
964080e
Fixup
danog Jul 25, 2023
db9ac3a
Fixes
danog Jul 25, 2023
e402813
Fixes
danog Jul 25, 2023
197668a
Fix file references
danog Jul 25, 2023
08133db
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 25, 2023
e67ea0b
Simplify
danog Jul 26, 2023
efcdc27
Simplify
danog Jul 26, 2023
ede8367
Revert for now
danog Jul 26, 2023
b8b4540
Merge branch 'fix_intersection_scanning' into strict_types
danog Jul 26, 2023
dea3856
Merge branch 'amp_v3' into strict_types
danog Jul 26, 2023
f68e071
Update UPGRADING.md
danog Jul 26, 2023
08e7db1
Merge branch 'amp_v3' into strict_types
danog Jul 28, 2023
c957aa8
fix
danog Jul 28, 2023
c7ab837
cs-fix
danog Jul 28, 2023
6cbc7f1
Merge branch 'amp_v3' into strict_types
danog Jul 28, 2023
4141d79
Merge remote-tracking branch 'hub/5.x' into strict_types
danog Jul 29, 2023
f894cde
Merge remote-tracking branch 'hub/master' into strict_types
danog Jul 29, 2023
ec959e9
Merge remote-tracking branch 'origin/master' into strict_types
danog Oct 19, 2023
a233e62
cs-fix
danog Oct 19, 2023
5953b1c
Fixes
danog Oct 19, 2023
1745c83
Finalize all classes
danog Oct 19, 2023
5088dc0
Minor fix
danog Oct 19, 2023
3e6294e
Simplify
danog Oct 19, 2023
fe4928c
Add suppression and note
danog Oct 19, 2023
394e385
Strict types everywhere
danog Oct 19, 2023
1c9092e
Update baseline
danog Oct 19, 2023
0f41831
Fix windows CI
danog Oct 19, 2023
076bd85
Fixes
danog Oct 19, 2023
989d171
Fixes
danog Oct 19, 2023
7761939
Strict properties
danog Oct 19, 2023
efb86f8
cs-fix
danog Oct 19, 2023
1988be4
One more type
danog Oct 19, 2023
09a606c
Readonly
danog Oct 19, 2023
2d43c16
Revert due to reset() in getSingleAtomic
danog Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@

- [BC] The return type of `Psalm\Internal\LanguageServer\ProtocolWriter#write() changed from `Amp\Promise` to `void` due to the switch to Amp v3

- [BC] All parameters, properties and return typehints are now strictly typed.

- [BC] `strict_types` is now applied to all files of the Psalm codebase.

- [BC] Properties `Psalm\Type\Atomic\TLiteralFloat::$value` and `Psalm\Type\Atomic\TLiteralInt::$value` became typed (`float` and `int` respectively)

- [BC] Property `Psalm\Storage\EnumCaseStorage::$value` changed from `int|string|null` to `TLiteralInt|TLiteralString|null`

- [BC] `Psalm\CodeLocation\Raw`, `Psalm\CodeLocation\ParseErrorLocation`, `Psalm\CodeLocation\DocblockTypeLocation`, `Psalm\Report\CountReport`, `Psalm\Type\Atomic\TNonEmptyArray` are now all final.

# Upgrading from Psalm 4 to Psalm 5
## Changed

Expand Down
2 changes: 2 additions & 0 deletions bin/generate_issues_list_doc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

$docs_dir = dirname(__DIR__) . DIRECTORY_SEPARATOR . "docs"
. DIRECTORY_SEPARATOR . "running_psalm" . DIRECTORY_SEPARATOR;
$issues_index = "{$docs_dir}issues.md";
Expand Down
2 changes: 2 additions & 0 deletions bin/generate_levels_doc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Psalm\Config\IssueHandler;
use Psalm\Issue\CodeIssue;

Expand Down
4 changes: 3 additions & 1 deletion bin/generate_testsuites.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

if (count($argv) < 2) {
fwrite(STDERR, 'Usage: ' . $argv[0] . ' <number_of_chunks>' . PHP_EOL);
exit(1);
Expand Down Expand Up @@ -35,7 +37,7 @@
);
array_multisort($order, $files);

$chunks = array_chunk($files, ceil(count($files) / $number_of_chunks));
$chunks = array_chunk($files, (int) ceil(count($files) / $number_of_chunks));

$phpunit_config = new DOMDocument('1.0', 'UTF-8');
$phpunit_config->preserveWhiteSpace = false;
Expand Down
2 changes: 2 additions & 0 deletions bin/improve_class_alias.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$vendor_path = 'vendor-bin/box/vendor/humbug/php-scoper/src/PhpParser/NodeVisitor/ClassAliasStmtAppender.php';

if (!file_exists($vendor_path)) {
Expand Down
2 changes: 2 additions & 0 deletions bin/max_used_shortcode.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Psalm\Config\IssueHandler;

require_once(dirname(__DIR__) . '/vendor/autoload.php');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"lint": "parallel-lint ./src ./tests",
"phpunit": [
"Composer\\Config::disableProcessTimeout",
"paratest --runner=WrapperRunner"
"paratest -f --runner=WrapperRunner"
],
"phpunit-std": [
"Composer\\Config::disableProcessTimeout",
Expand Down
10 changes: 3 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Configuration *
************************************************************************************************************** -->

<config name="php_version" value="70400"/>
<config name="php_version" value="80100"/>
<config name="installed_paths" value="../../slevomat/coding-standard"/>

<arg name="basepath" value="."/>
Expand Down Expand Up @@ -91,8 +91,6 @@
<property name="linesCountAfterDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>

<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>
</rule>

<!--
Expand Down Expand Up @@ -251,13 +249,11 @@
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
<!-- TODO: Remove in Psalm 6 -->
<include-pattern>bin/*</include-pattern>
<include-pattern>src/Psalm/Internal/*</include-pattern>
<include-pattern>tests/*</include-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/>
</ruleset>
15 changes: 11 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@77650e7b153ee3a96507ba6902ce2807def23221">
<files psalm-version="dev-master@973a3fa554b4a2016e2a551dce2206fb47084050">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
Expand Down Expand Up @@ -251,6 +251,16 @@
<code>$stub</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Codebase/Methods.php">
<InvalidArgument>
<code><![CDATA[$class_storage->methods[$declaring_method_name]->stubbed]]></code>
</InvalidArgument>
</file>
<file src="src/Psalm/Internal/Codebase/Populator.php">
<InvalidArgument>
<code><![CDATA[$storage->methods[$implementing_method_id->method_name]->abstract]]></code>
</InvalidArgument>
</file>
<file src="src/Psalm/Internal/Codebase/Properties.php">
<PossiblyUndefinedIntArrayOffset>
<code>$property_name</code>
Expand Down Expand Up @@ -346,9 +356,6 @@
<PossiblyUndefinedIntArrayOffset>
<code>$since_parts[1]</code>
</PossiblyUndefinedIntArrayOffset>
<RedundantCondition>
<code><![CDATA[count($line_parts) > 0]]></code>
</RedundantCondition>
</file>
<file src="src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php">
<PossiblyUndefinedArrayOffset>
Expand Down
28 changes: 13 additions & 15 deletions src/Psalm/Aliases.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
<?php

declare(strict_types=1);

namespace Psalm;

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

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

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

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

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

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

/** @var string|null */
public $namespace;
public ?string $namespace = null;

/** @var ?int */
public $namespace_first_stmt_start;
public ?int $namespace_first_stmt_start = null;

/** @var ?int */
public $uses_start;
public ?int $uses_start = null;

/** @var ?int */
public $uses_end;
public ?int $uses_end = null;

/**
* @param array<lowercase-string, string> $uses
Expand All @@ -63,7 +61,7 @@ public function __construct(
array $constants = [],
array $uses_flipped = [],
array $functions_flipped = [],
array $constants_flipped = []
array $constants_flipped = [],
) {
$this->namespace = $namespace;
$this->uses = $uses;
Expand Down
40 changes: 15 additions & 25 deletions src/Psalm/CodeLocation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Psalm;

use Exception;
Expand Down Expand Up @@ -33,34 +35,25 @@
{
use ImmutableNonCloneableTrait;

/** @var string */
public $file_path;
public string $file_path;

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

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Type of property Psalm\CodeLocation#$file_path changed from having no type to string

/** @var string */
public $file_name;
public string $file_name;

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

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Type of property Psalm\CodeLocation#$file_name changed from having no type to string

/** @var int */
public $raw_line_number;
public int $raw_line_number;

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

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Type of property Psalm\CodeLocation#$raw_line_number changed from having no type to int

private int $end_line_number = -1;

/** @var int */
public $raw_file_start;
public int $raw_file_start;

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

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Type of property Psalm\CodeLocation#$raw_file_start changed from having no type to int

/** @var int */
public $raw_file_end;
public int $raw_file_end;

/** @var int */
protected $file_start;
protected int $file_start;

/** @var int */
protected $file_end;
protected int $file_end;

/** @var bool */
protected $single_line;
protected bool $single_line;

/** @var int */
protected $preview_start;
protected int $preview_start;

private int $preview_end = -1;

Expand All @@ -76,20 +69,17 @@

private ?string $text = null;

/** @var int|null */
public $docblock_start;
public ?int $docblock_start = null;

private ?int $docblock_start_line_number = null;

/** @var int|null */
protected $docblock_line_number;
protected ?int $docblock_line_number = null;

private ?int $regex_type = null;

private bool $have_recalculated = false;

/** @var null|CodeLocation */
public $previous_location;
public ?CodeLocation $previous_location = null;

public const VAR_TYPE = 0;
public const FUNCTION_RETURN_TYPE = 1;
Expand All @@ -107,7 +97,7 @@
bool $single_line = false,
?int $regex_type = null,
?string $selected_text = null,
?int $comment_line = null
?int $comment_line = null,
) {
/** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */
$this->file_start = (int)$stmt->getAttribute('startFilePos');
Expand Down
6 changes: 4 additions & 2 deletions src/Psalm/CodeLocation/DocblockTypeLocation.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

declare(strict_types=1);

namespace Psalm\CodeLocation;

use Psalm\CodeLocation;
use Psalm\FileSource;

/** @psalm-immutable */
class DocblockTypeLocation extends CodeLocation
final class DocblockTypeLocation extends CodeLocation
{
public function __construct(
FileSource $file_source,
int $file_start,
int $file_end,
int $line_number
int $line_number,
) {
$this->file_start = $file_start;
// matches how CodeLocation works
Expand Down
6 changes: 4 additions & 2 deletions src/Psalm/CodeLocation/ParseErrorLocation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Psalm\CodeLocation;

use PhpParser;
Expand All @@ -9,13 +11,13 @@
use function substr_count;

/** @psalm-immutable */
class ParseErrorLocation extends CodeLocation
final class ParseErrorLocation extends CodeLocation
{
public function __construct(
PhpParser\Error $error,
string $file_contents,
string $file_path,
string $file_name
string $file_name,
) {
/** @psalm-suppress PossiblyUndefinedStringArrayOffset, ImpureMethodCall */
$this->file_start = (int)$error->getAttributes()['startFilePos'];
Expand Down
6 changes: 4 additions & 2 deletions src/Psalm/CodeLocation/Raw.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Psalm\CodeLocation;

use Psalm\CodeLocation;
Expand All @@ -8,14 +10,14 @@
use function substr_count;

/** @psalm-immutable */
class Raw extends CodeLocation
final class Raw extends CodeLocation

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Class Psalm\CodeLocation\Raw became final

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Property Psalm\CodeLocation#$file_start was removed

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Property Psalm\CodeLocation#$file_end was removed

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Property Psalm\CodeLocation#$single_line was removed

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Property Psalm\CodeLocation#$preview_start was removed

Check failure on line 13 in src/Psalm/CodeLocation/Raw.php

View workflow job for this annotation

GitHub Actions / Check backward compatibility

Property Psalm\CodeLocation#$docblock_line_number was removed
{
public function __construct(
string $file_contents,
string $file_path,
string $file_name,
int $file_start,
int $file_end
int $file_end,
) {
$this->file_start = $file_start;
$this->file_end = $file_end;
Expand Down
Loading