Skip to content

Commit

Permalink
Merge branch 'strict_types' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 19, 2023
2 parents 692d4f4 + 7761939 commit c24feaa
Show file tree
Hide file tree
Showing 671 changed files with 1,553 additions and 2,113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ jobs:
run: php bin/generate_testsuites.php $env:CHUNK_COUNT

- name: Run unit tests
run: vendor/bin/paratest -f --processes=$env:PARALLEL_PROCESSES --testsuite=chunk_$env:CHUNK_NUMBER --log-junit build/phpunit/phpunit.xml
run: vendor/bin/paratest --processes=$env:PARALLEL_PROCESSES --testsuite=chunk_$env:CHUNK_NUMBER --log-junit build/phpunit/phpunit.xml
9 changes: 9 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
- [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] 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
6 changes: 0 additions & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
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,10 +249,6 @@
</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"/>
Expand Down
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@f799b68a3cbc91e9056bb972cfe66b7ae0da3f76">
<files psalm-version="dev-master@973a3fa554b4a2016e2a551dce2206fb47084050">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
Expand Down Expand Up @@ -256,6 +256,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 @@ -359,9 +369,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">
<ArgumentTypeCoercion>
Expand Down
24 changes: 10 additions & 14 deletions src/Psalm/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,40 @@ 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 Down
36 changes: 12 additions & 24 deletions src/Psalm/CodeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,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 @@ -78,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 Down
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/DocblockTypeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psalm\FileSource;

/** @psalm-immutable */
class DocblockTypeLocation extends CodeLocation
final class DocblockTypeLocation extends CodeLocation
{
public function __construct(
FileSource $file_source,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/ParseErrorLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function substr_count;

/** @psalm-immutable */
class ParseErrorLocation extends CodeLocation
final class ParseErrorLocation extends CodeLocation
{
public function __construct(
PhpParser\Error $error,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/CodeLocation/Raw.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function substr_count;

/** @psalm-immutable */
class Raw extends CodeLocation
final class Raw extends CodeLocation
{
public function __construct(
string $file_contents,
Expand Down
Loading

0 comments on commit c24feaa

Please sign in to comment.