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

Github Actions: Add Phpstan #40

Merged
merged 5 commits into from
Aug 23, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
if: success() || matrix.allow_failure
run: phpcs -wps --colors

- name: PHPStan
uses: php-actions/phpstan@v3
if: success() || matrix.allow_failure

test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
46 changes: 46 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
parameters:
ignoreErrors:
-
message: "#^Cannot cast mixed to string\\.$#"
count: 2
path: src/Filter.php

-
message: "#^Dead catch \\- Exception is never thrown in the try block\\.$#"
count: 1
path: src/Filter.php

-
message: "#^Class ipl\\\\Stdlib\\\\Filter\\\\Chain implements generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Filter/Chain.php

-
message: "#^Cannot access offset 'data' on mixed\\.$#"
count: 1
path: src/PriorityQueue.php

-
message: "#^Cannot access offset 'priority' on mixed\\.$#"
count: 1
path: src/PriorityQueue.php

-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
path: src/PriorityQueue.php

-
message: "#^Class ipl\\\\Stdlib\\\\PriorityQueue extends generic class SplPriorityQueue but does not specify its types\\: TPriority, TValue$#"
count: 1
path: src/PriorityQueue.php

-
message: "#^Trying to invoke mixed but it's not a callable\\.$#"
count: 2
path: src/Seq.php

-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
count: 3
path: src/Str.php
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
includes:
- phpstan-baseline.neon

parameters:
level: max

checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
treatPhpDocTypesAsCertain: false

paths:
- src

scanDirectories:
- vendor
2 changes: 1 addition & 1 deletion src/Contract/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function isValid($value);
/**
* Get the validation error messages
*
* @return array
* @return array<string>
*/
public function getMessages();
}
2 changes: 1 addition & 1 deletion src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Data
{
/** @var array */
/** @var array<string, mixed> */
protected $data = [];

/**
Expand Down
16 changes: 11 additions & 5 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function __construct()
* Return whether the given rule matches the given item
*
* @param Rule $rule
* @param array|object $row
* @param array<mixed>|object $row
*
* @return bool
*/
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function matchNone(None $rules, $row)
* Create a rule that matches rows with a column that **equals** the given value
*
* @param string $column
* @param array|bool|float|int|string $value
* @param array<mixed>|bool|float|int|string $value
*
* @return Condition
*/
Expand Down Expand Up @@ -259,8 +259,10 @@ protected function performEqualityMatch($value, $rowValue, $ignoreCase = false)
if ($ignoreCase && is_string($rowValue)) {
$rowValue = strtolower($rowValue);
$value = is_array($value)
? array_map('strtolower', $value)
: strtolower($value);
nilmerg marked this conversation as resolved.
Show resolved Hide resolved
? array_map(function ($val) {
return strtolower((string) $val);
}, $value)
: strtolower((string) $value);
}

if (is_array($value)) {
Expand Down Expand Up @@ -297,6 +299,10 @@ protected function performSimilarityMatch($value, $rowValue, $ignoreCase = false
}

$wildcardSubSegments = preg_split('~\*~', $value);
if (! $wildcardSubSegments) {
$wildcardSubSegments = [];
}

if (count($wildcardSubSegments) === 1) {
return $rowValue === $value;
}
Expand All @@ -315,7 +321,7 @@ protected function performSimilarityMatch($value, $rowValue, $ignoreCase = false
* Create a rule that matches rows with a column that is **unequal** with the given value
*
* @param string $column
* @param array|bool|float|int|string $value
* @param array<mixed>|bool|float|int|string $value
*
* @return Condition
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class Chain implements Rule, MetaDataProvider, IteratorAggregate, Count
{
use MetaData;

/** @var Rule[] */
/** @var array<int, Rule> */
protected $rules = [];

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ public function __clone()
/**
* Get an iterator this chain's rules
*
* @return ArrayIterator
* @return ArrayIterator<int, Rule>
*/
public function getIterator(): Traversable
{
Expand Down
1 change: 1 addition & 0 deletions src/PriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class PriorityQueue extends SplPriorityQueue
{
/** @var int */
protected $serial = PHP_INT_MAX;

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Seq.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Seq
/**
* Check if the traversable contains the given needle
*
* @param array|iterable $traversable
* @param array<mixed>|iterable<mixed> $traversable
* @param mixed $needle Might also be a closure
* @param bool $caseSensitive Whether strings should be compared case-sensitive
*
Expand All @@ -26,11 +26,12 @@ public static function contains($traversable, $needle, $caseSensitive = true)
/**
* Search in the traversable for the given needle and return its key and value
*
* @param array|iterable $traversable
* @param array<mixed>|iterable<mixed> $traversable
* @param mixed $needle Might also be a closure
* @param bool $caseSensitive Whether strings should be compared case-sensitive
*
* @return array An array with two entries, the first is the key, then the value. Both are null if nothing is found.
* @return array<mixed> An array with two entries, the first is the key, then the value.
* Both are null if nothing is found.
*/
public static function find($traversable, $needle, $caseSensitive = true)
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public static function find($traversable, $needle, $caseSensitive = true)
/**
* Search in the traversable for the given needle and return its key
*
* @param array|iterable $traversable
* @param array<mixed>|iterable<mixed> $traversable
* @param mixed $needle Might also be a closure
* @param bool $caseSensitive Whether strings should be compared case-sensitive
*
Expand All @@ -76,7 +77,7 @@ public static function findKey($traversable, $needle, $caseSensitive = true)
/**
* Search in the traversable for the given needle and return its value
*
* @param array|iterable $traversable
* @param array<mixed>|iterable<mixed> $traversable
* @param mixed $needle Might also be a closure
* @param bool $caseSensitive Whether strings should be compared case-sensitive
*
Expand Down
22 changes: 11 additions & 11 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Str
*
* The given string may be delimited by the following characters: '_' (underscore), '-' (dash), ' ' (space).
*
* @param string $subject
* @param ?string $subject
*
* @return string
*/
public static function camel($subject)
public static function camel(?string $subject)
{
if ($subject === null) {
return '';
Expand All @@ -30,13 +30,13 @@ public static function camel($subject)
/**
* Check if the given string starts with the specified substring
*
* @param string $subject
* @param ?string $subject
* @param string $start
* @param bool $caseSensitive
*
* @return bool
*/
public static function startsWith($subject, string $start, bool $caseSensitive = true)
public static function startsWith(?string $subject, string $start, bool $caseSensitive = true)
{
$subject = $subject ?? '';
if (! $caseSensitive) {
Expand All @@ -51,14 +51,14 @@ public static function startsWith($subject, string $start, bool $caseSensitive =
*
* This method is a perfect fit if you need default values for symmetric array destructuring.
*
* @param string $subject
* @param ?string $subject
* @param string $delimiter
* @param int $limit
* @param mixed $default
*
* @return array
* @return array<int, mixed>
*/
public static function symmetricSplit($subject, string $delimiter, int $limit, $default = null)
public static function symmetricSplit(?string $subject, string $delimiter, int $limit, $default = null)
{
if ($subject === null) {
return [];
Expand All @@ -70,13 +70,13 @@ public static function symmetricSplit($subject, string $delimiter, int $limit, $
/**
* Split string into an array and trim spaces
*
* @param string $subject
* @param ?string $subject
* @param string $delimiter
* @param int $limit
* @param ?int $limit
*
* @return array
* @return array<string>
*/
public static function trimSplit($subject, string $delimiter = ',', int $limit = null)
public static function trimSplit(?string $subject, string $delimiter = ',', int $limit = null)
{
if ($subject === null) {
return [];
Expand Down
8 changes: 4 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* If subject is an object, the name of the object's class is returned, otherwise the subject's type.
*
* @param $subject
* @param mixed $subject
*
* @return string
*/
Expand All @@ -27,9 +27,9 @@ function get_php_type($subject)
/**
* Get the array value of the given subject
*
* @param array|object|Traversable $subject
* @param array<mixed>|object|Traversable $subject
*
* @return array
* @return array<mixed>
*
* @throws InvalidArgumentException If subject type is invalid
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ function arrayval($subject)
/**
* Get the first key of an iterable
*
* @param iterable $iterable
* @param iterable<mixed> $iterable
*
* @return mixed The first key of the iterable if it is not empty, null otherwise
*/
Expand Down