diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bca7243..4ec3158 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,6 +9,8 @@ jobs: runs-on: ubuntu-22.04 strategy: + fail-fast: false + experimental: [false] matrix: php-version: - 7.3 @@ -17,6 +19,9 @@ jobs: - 8.1 - 8.2 - 8.3 + include: + - php: 8.2 + analysis: true steps: @@ -35,5 +40,9 @@ jobs: with: composer-options: --prefer-dist + - name: Static analysis + if: matrix.analysis + run: vendor/bin/phpstan + - name: Run Tests run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index ab5bc1e..f92c309 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,6 @@ "name": "kohanaworld/hmmmath", "description": "Collection of math related PHP functions (PHP >=7.2 <=8.3", "license": "MIT", - "version": "0.9.0", "authors": [ { "name": "Lars Strojny", @@ -24,9 +23,11 @@ } }, "require": { - "php": "^7.3|^8.0" + "php": "^7.4|^8.0" }, "require-dev": { - "phpunit/phpunit": "^9" + "phpunit/phpunit": "^9", + "phpstan/phpstan": "^1.11", + "squizlabs/php_codesniffer": "3.*" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..16c0677 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,5 @@ +parameters: + level: 2 + paths: + - src + - tests \ No newline at end of file diff --git a/src/hmmmath/Exception/BadMethodCallException.php b/src/hmmmath/Exception/BadMethodCallException.php index f4d6ac8..95e1fda 100644 --- a/src/hmmmath/Exception/BadMethodCallException.php +++ b/src/hmmmath/Exception/BadMethodCallException.php @@ -3,7 +3,7 @@ use InvalidArgumentException as BaseBadMethodCallException; -class BadMethodCallException extends BaseBadMethodCallException +final class BadMethodCallException extends BaseBadMethodCallException { public static function invalidMethod(string $className, string $methodName): self { diff --git a/src/hmmmath/Exception/InvalidArgumentException.php b/src/hmmmath/Exception/InvalidArgumentException.php index 1c644e8..ff38d66 100644 --- a/src/hmmmath/Exception/InvalidArgumentException.php +++ b/src/hmmmath/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ use InvalidArgumentException as BaseInvalidArgumentException; -class InvalidArgumentException extends BaseInvalidArgumentException +final class InvalidArgumentException extends BaseInvalidArgumentException { /** * @param mixed $actualValue diff --git a/src/hmmmath/Fibonacci/FibonacciFactory.php b/src/hmmmath/Fibonacci/FibonacciFactory.php index 753adea..d77c968 100644 --- a/src/hmmmath/Fibonacci/FibonacciFactory.php +++ b/src/hmmmath/Fibonacci/FibonacciFactory.php @@ -1,18 +1,24 @@ |LimitIterator /** Create fibonacci number */ public static function number(int $start = 0, int $increment = 1): FibonacciNumber { diff --git a/src/hmmmath/Fibonacci/FibonacciNumber.php b/src/hmmmath/Fibonacci/FibonacciNumber.php index 71bbe1c..6432563 100644 --- a/src/hmmmath/Fibonacci/FibonacciNumber.php +++ b/src/hmmmath/Fibonacci/FibonacciNumber.php @@ -3,8 +3,8 @@ class FibonacciNumber { - private $start; - private $increment; + private int $start; + private int $increment; public function __construct(int $start, int $increment) { diff --git a/src/hmmmath/Fibonacci/FibonacciSequence.php b/src/hmmmath/Fibonacci/FibonacciSequence.php index 8602d4f..4827128 100644 --- a/src/hmmmath/Fibonacci/FibonacciSequence.php +++ b/src/hmmmath/Fibonacci/FibonacciSequence.php @@ -5,50 +5,70 @@ use Iterator; use hmmmath\Exception\BadMethodCallException; + +/** + * @implements Iterator + * @implements ArrayAccess + */ class FibonacciSequence implements Iterator, ArrayAccess { /** @var FibonacciNumber */ - private $number; + private FibonacciNumber $number; /** @var FibonacciNumber */ - private $initial; + private FibonacciNumber $initial; /** @var int */ - private $key = 0; + private int $key = 0; public function __construct(int $start = 0, int $increment = 1) { $this->number = $this->initial = new FibonacciNumber($start, $increment); } - public function current(): int + /** + * @return int + */ + public function current(): int { return $this->number->getCurrent(); } - public function key(): int + /** + * @return int + */ + public function key(): int { return $this->key; } - public function valid(): bool + /** + * @return bool + */ + public function valid(): bool { return true; } - public function rewind(): void + /** + * @return void + */ + public function rewind(): void { $this->key = 0; $this->number = $this->initial; } - public function next(): void + /** + * @return void + */ + public function next(): void { ++$this->key; $this->number = $this->number->getNext(); } - public function offsetExists($offset): bool // @codingStandardsIgnoreLine + public function offsetExists($offset): bool // @codingStandardsIgnoreLine { return true; } @@ -64,7 +84,7 @@ public function offsetGet($offset): int // @codingStandardsIgnoreLine return $number->getCurrent(); } - public function offsetSet($offset, $value): void // @codingStandardsIgnoreLine + public function offsetSet($offset, $value): void // @codingStandardsIgnoreLine { throw BadMethodCallException::invalidMethod(__CLASS__, __FUNCTION__); } diff --git a/src/hmmmath/Percentile/Percentile.php b/src/hmmmath/Percentile/Percentile.php index 03e4332..8355600 100644 --- a/src/hmmmath/Percentile/Percentile.php +++ b/src/hmmmath/Percentile/Percentile.php @@ -19,7 +19,7 @@ public static function percentile( string $mode = self::NEAREST_RANK, bool $sort = true ): float { - InvalidArgumentException::assertParameterType('2', 'double', $percentile, '0..1'); + InvalidArgumentException::assertParameterType(2, 'double', $percentile, '0..1'); if ($sort) { sort($numbers);