Skip to content

Commit

Permalink
Merge pull request #10044 from nicelocal/strict_types
Browse files Browse the repository at this point in the history
Psalm v6: strict_types=1
  • Loading branch information
orklah authored Oct 21, 2023
2 parents 24168f6 + 2d43c16 commit 75fcfe3
Show file tree
Hide file tree
Showing 1,206 changed files with 4,499 additions and 3,359 deletions.
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 @@ class CodeLocation
{
use ImmutableNonCloneableTrait;

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

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

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

private int $end_line_number = -1;

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

/** @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 @@ class CodeLocation

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 @@ public function __construct(
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
{
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

0 comments on commit 75fcfe3

Please sign in to comment.