Skip to content

Commit

Permalink
Merge pull request #77 from Hi-Folks/livestreaming/upgrade
Browse files Browse the repository at this point in the history
Upgrade RectorPHP v2 and PHPStan v2
  • Loading branch information
roberto-butti authored Dec 13, 2024
2 parents 35de12b + 06303aa commit 16c8adf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.0 - 2024-12-13
- Upgrading RectorPHP v 2
- Upgrading PHPStan v 2

## 1.0.2 - 2024-12-10
- NormalDist class, with `cdf()` and `pdf()`
- Fix deprecations for PHP 8.4
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"require-dev": {
"laravel/pint": "^1.13",
"pestphp/pest": "^2.0",
"phpstan/phpstan": "^1.3",
"rector/rector": "^1"
"phpstan/phpstan": "^2",
"rector/rector": "^2"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 8
treatPhpDocTypesAsCertain: false
paths:
- src
6 changes: 6 additions & 0 deletions src/Freq.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public static function cumulativeRelativeFrequencies(array $data): array
public static function frequencyTableBySize(array $data, int $chunkSize = 1): array
{
$result = [];
if ($data === []) {
return $result;
}
$min = floor((float) min($data));
$max = ceil((float) max($data));
//$limit = ceil(($max - $min) / $category);
Expand Down Expand Up @@ -146,6 +149,9 @@ public static function frequencyTableBySize(array $data, int $chunkSize = 1): ar
public static function frequencyTable(array $data, ?int $category = null): array
{
$result = [];
if ($data === []) {
return $result;
}
$min = floor((float) min($data));
$max = ceil((float) max($data));
if (is_null($category)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Stat.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static function mean(array $data): int|float|null
if (self::count($data) === 0) {
throw new InvalidDataInputException('The data must not be empty.');
}
// @phpstan-ignore-next-line
if (array_filter($data, 'is_string') !== []) {
throw new InvalidDataInputException('The data array contains a string.');
}
Expand All @@ -65,7 +64,7 @@ public static function median(array $data, string $medianType = self::MEDIAN_TYP
if ($count === 0) {
throw new InvalidDataInputException('The data must not be empty.');
}
$index = floor($count / 2); // cache the index
$index = (int) floor($count / 2); // cache the index
if (($count & 1) !== 0) { // count is odd
return $data[$index];
}
Expand Down Expand Up @@ -126,7 +125,7 @@ public static function medianHigh(array $data): mixed
public static function mode(array $data, bool $multimode = false): mixed
{
$frequencies = Freq::frequencies($data);
if (self::count($frequencies) === 0) {
if ($frequencies === []) {
throw new InvalidDataInputException('The data must not be empty.');
}
$sameMode = true;
Expand All @@ -140,6 +139,7 @@ public static function mode(array $data, bool $multimode = false): mixed
if ($sameMode) {
return null;
}

$highestFreq = max($frequencies);
$modes = array_keys($frequencies, $highestFreq, true);
if ($multimode) {
Expand Down
6 changes: 6 additions & 0 deletions src/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public function cumulativeFrequencies(): array
*/
public function max(): mixed
{
if ($this->values === []) {
return 0;
}
return max($this->values);
}

Expand All @@ -128,6 +131,9 @@ public function max(): mixed
*/
public function min(): mixed
{
if ($this->values === []) {
return 0;
}
return min($this->values);
}

Expand Down

0 comments on commit 16c8adf

Please sign in to comment.