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

Support psalm v5 #369

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"friendsofphp/php-cs-fixer": "^3.4.0",
"phpbench/phpbench": "^1.2.3",
"phpunit/phpunit": "^9.5.16",
"vimeo/psalm": "^4.21.0",
"php-standard-library/psalm-plugin": "^2.0.2",
"vimeo/psalm": "^5.0.0",
"php-standard-library/psalm-plugin": "^2.1.0",
"php-coveralls/php-coveralls": "^2.5.2",
"roave/infection-static-analysis-plugin": "^1.23.0"
"roave/infection-static-analysis-plugin": "^1.26.0"
},
"autoload": {
"psr-4": {
Expand Down
272 changes: 109 additions & 163 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/component/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [create_temporary_file](./../../src/Psl/Filesystem/create_temporary_file.php#L26)
- [delete_directory](./../../src/Psl/Filesystem/delete_directory.php#L23)
- [delete_file](./../../src/Psl/Filesystem/delete_file.php#L21)
- [exists](./../../src/Psl/Filesystem/exists.php#L16)
- [exists](./../../src/Psl/Filesystem/exists.php#L14)
- [file_size](./../../src/Psl/Filesystem/file_size.php#L22)
- [get_access_time](./../../src/Psl/Filesystem/get_access_time.php#L20)
- [get_basename](./../../src/Psl/Filesystem/get_basename.php#L23)
Expand Down
2 changes: 2 additions & 0 deletions src/Psl/Collection/MutableVector.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ public function slice(int $start, ?int $length = null): MutableVector
* `MutableVector` split into chunks of the given size.
*
* @psalm-mutation-free
*
* @psalm-suppress LessSpecificImplementedReturnType - I don't see how this one is less specific than its inherited.
azjezz marked this conversation as resolved.
Show resolved Hide resolved
*/
public function chunk(int $size): MutableVector
{
Expand Down
2 changes: 2 additions & 0 deletions src/Psl/Collection/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ public function slice(int $start, ?int $length = null): Vector
* into chunks of the given size.
*
* @psalm-mutation-free
*
* @psalm-suppress LessSpecificImplementedReturnType - I don't see how this one is less specific than its inherited.
*/
public function chunk(int $size): Vector
{
Expand Down
4 changes: 1 addition & 3 deletions src/Psl/Filesystem/exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
/**
* Check whether $node exists.
*
* @param string $node Path, absolute or relative to the current working directory.
*
* @psalm-assert-if-true non-empty-string $node
azjezz marked this conversation as resolved.
Show resolved Hide resolved
* @param non-empty-string $node Path, absolute or relative to the current working directory.
*/
function exists(string $node): bool
{
Expand Down
1 change: 1 addition & 0 deletions src/Psl/Hash/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function update(string $data): Context
$internal_context = hash_copy($this->internalContext);

// @codeCoverageIgnoreStart
/** @psalm-suppress ImpureFunctionCall - it creates a copy of the context, so we can consider it pure! */
if (!hash_update($internal_context, $data)) {
throw new Exception\RuntimeException('Unable to pump data into the active hashing context.');
}
Expand Down
1 change: 1 addition & 0 deletions src/Psl/IO/Internal/ResourceHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ResourceHandle implements IO\CloseSeekReadWriteStreamHandleInterface
*/
public function __construct(mixed $stream, bool $read, bool $write, bool $seek, private bool $close)
{
/** @psalm-suppress RedundantConditionGivenDocblockType - The stream is always a resource, but we want to make sure it is a stream resource. */
$this->stream = Type\resource('stream')->assert($stream);

/** @psalm-suppress UnusedFunctionCall */
Expand Down
2 changes: 2 additions & 0 deletions src/Psl/Iter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static function from(Closure $factory): Iterator
/**
* Create an iterator from an iterable.
*
* @psalm-suppress DocblockTypeContradiction - Psalm gets lost on Generator, which is a perfectly valid iterable type.
*
* @template Tsk
* @template Tsv
*
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Json/decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function decode(string $json, bool $assoc = true): mixed
JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR,
);
} catch (JsonException $e) {
throw new Exception\DecodeException(Str\format('%s.', $e->getMessage()), (int)$e->getCode(), $e);
throw new Exception\DecodeException(Str\format('%s.', $e->getMessage()), $e->getCode(), $e);
}

return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Json/encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function encode(mixed $value, bool $pretty = false, int $flags = 0): string
try {
$json = json_encode($value, $flags);
} catch (JsonException $e) {
throw new Exception\EncodeException(Str\format('%s.', $e->getMessage()), (int)$e->getCode(), $e);
throw new Exception\EncodeException(Str\format('%s.', $e->getMessage()), $e->getCode(), $e);
}

return $json;
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Json/typed.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ function typed(string $json, Type\TypeInterface $type): mixed
try {
return $type->coerce(decode($json));
} catch (Type\Exception\CoercionException $e) {
throw new Exception\DecodeException($e->getMessage(), (int)$e->getCode(), $e);
throw new Exception\DecodeException($e->getMessage(), $e->getCode(), $e);
}
}
1 change: 0 additions & 1 deletion src/Psl/Str/Byte/split.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function split(string $string, string $delimiter, ?int $limit = null): array
return [$string];
}

/** @var positive-int $length */
$length = $limit - 1;

$result = chunk(slice($string, 0, $length));
Expand Down
1 change: 0 additions & 1 deletion src/Psl/Str/split.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function split(string $string, string $delimiter, ?int $limit = null, Encoding $
return [$string];
}

/** @var positive-int $length */
$length = $limit - 1;

$result = chunk(slice($string, 0, $length, $encoding), 1, $encoding);
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark/Type/Asset/ExplicitStringableObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class ExplicitStringableObject implements Stringable
{
public function __toString()
public function __toString(): string
{
return '123';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark/Type/Asset/ImplicitStringableObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class ImplicitStringableObject
{
public function __toString()
public function __toString(): string
{
return '123';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/static-analysis/Fun/pipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function test_variadic_and_default_params(): void
*
* @see https://github.com/vimeo/psalm/issues/7244
*
* @psalm-suppress InvalidScalarArgument
* @psalm-suppress InvalidArgument
*/
function test_empty_pipe(): void
{
Expand Down