Skip to content

Commit

Permalink
Update PHP 8.3 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Jan 28, 2024
1 parent ea60d1b commit 55ddbe0
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 8.1, 8.2 ]
php-version: [ 8.1, 8.2, 8.3 ]
coverage: [ xdebug, none ]
composer_flags: [ "--prefer-lowest", "" ]
steps:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.1, 8.2 ]
php-version: [ 8.1, 8.2, 8.3 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.1, 8.2 ]
php-version: [ 8.1, 8.2, 8.3 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^7.0",
"jbzoo/data" : "^7.0",
"symfony/process" : ">=4.4"
"jbzoo/toolbox-dev" : "^7.1",
"jbzoo/data" : "^7.1",
"symfony/process" : ">=6.4"
},

"suggest" : {
Expand Down
4 changes: 2 additions & 2 deletions src/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public static function timezone(null|\DateTimeZone|string $timezone = null): \Da
return $timezone;
}

$timezone = isStrEmpty($timezone) ? \date_default_timezone_get() : $timezone;
$timezone = ($timezone === '' || $timezone === null) ? \date_default_timezone_get() : $timezone;

return new \DateTimeZone((string)$timezone);
return new \DateTimeZone($timezone);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public static function digits(?string $value): string
// we need to remove - and + because they're allowed in the filter
$cleaned = \str_replace(['-', '+'], '', (string)$value);

/**
* @psalm-suppress RedundantCast
*/
return (string)\filter_var($cleaned, \FILTER_SANITIZE_NUMBER_INT);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static function getHeaders(): array
$authorizationHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
}

if ($authorizationHeader) {
if (bool($authorizationHeader)) {
$authorizationHeader = (string)$authorizationHeader;
if (\stripos($authorizationHeader, 'basic ') === 0) {
// Decode AUTHORIZATION header into PHP_AUTH_USER
// and PHP_AUTH_PW when authorization header is basic
Expand Down
13 changes: 8 additions & 5 deletions src/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public static function mean(?array $values): float
return 0;
}

\array_walk($values, static function (null|float|int|string &$value): void {
$value = float($value);
});
$sum = \array_sum($values);

if ($sum === 0) {
Expand Down Expand Up @@ -148,8 +151,8 @@ public static function histogram(
*/
public static function renderAverage(array $values, int $rounding = 3): string
{
$avg = \number_format(self::mean($values), $rounding);
$stdDev = \number_format(self::stdDev($values), $rounding);
$avg = \number_format(\round(self::mean($values), $rounding), $rounding);
$stdDev = \number_format(\round(self::stdDev($values), $rounding), $rounding);

return "{$avg}±{$stdDev}";
}
Expand All @@ -159,10 +162,10 @@ public static function renderAverage(array $values, int $rounding = 3): string
*/
public static function renderMedian(array $values, int $rounding = 3): string
{
$avg = \number_format(self::median($values), $rounding);
$stdDev = \number_format(self::stdDev($values), $rounding);
$median = \number_format(\round(self::median($values), $rounding), $rounding);
$stdDev = \number_format(\round(self::stdDev($values), $rounding), $rounding);

return "{$avg}±{$stdDev}";
return "{$median}±{$stdDev}";
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public static function path(): ?string
// Get the rest of the URL
if (!\array_key_exists('REQUEST_URI', $_SERVER)) {
// Microsoft IIS doesn't set REQUEST_URI by default
if ($queryString = $_SERVER['QUERY_STRING'] ?? null) {
$queryString = $_SERVER['QUERY_STRING'] ?? null;
if ($queryString !== null) {
$url .= '?' . $queryString;
}
} else {
Expand Down
1 change: 0 additions & 1 deletion tests/SerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function testFix(): void

\unserialize($brokenSerialization, []);

is($expectedError['errno'], $reportedError['errno']);
// Because HHVM's unserialize() error message does not contain enough info to properly test.
if (!\defined('HHVM_VERSION')) {
is($expectedError['errstr'], $reportedError['errstr']);
Expand Down
26 changes: 21 additions & 5 deletions tests/StatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function testMean(): void
isSame(2.0, Stats::mean([1, 3]));
isSame(2.0, Stats::mean(['1', 3]));
isSame(2.25, Stats::mean(['1.5', 3]));
isSame(5.5, Stats::mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
isSame(5.5, Stats::mean(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']));

$data = [72, 57, 66, 92, 32, 17, 146];
isSame(68.857142857, Stats::mean($data));
Expand Down Expand Up @@ -84,21 +86,34 @@ public function testHistogram(): void
isSame(['2' => 0], Stats::histogram([1, 2, 1], 5, 2, 2));
}

public function testRenderAverageEmpty(): void
{
isSame('0.000±0.000', Stats::renderAverage([]));
}

public function testRenderAverage(): void
{
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
isSame('5.500±2.872', Stats::renderAverage($data));
isSame('5.5±2.9', Stats::renderAverage($data, 1));
isSame('5.5000±2.8723', Stats::renderAverage($data, 4));
isSame('5.500±2.872', Stats::renderAverage($data, 3));
isSame('5.50±2.87', Stats::renderAverage($data, 2));
isSame('5.5±2.9', Stats::renderAverage($data, 1));
isSame('6±3', Stats::renderAverage($data, 0));
isSame('6±3', Stats::renderAverage($data, -1));
isSame('10±0', Stats::renderAverage($data, -1));

$data = [72, 57, 66, 92, 32, 17, 146];
isSame('68.857±39.084', Stats::renderAverage($data));
isSame('68.9±39.1', Stats::renderAverage($data, 1));
isSame('68.86±39.08', Stats::renderAverage($data, 2));
isSame('69±39', Stats::renderAverage($data, 0));
isSame('69±39', Stats::renderAverage($data, -1));
isSame('70±40', Stats::renderAverage($data, -1));
isSame('100±0', Stats::renderAverage($data, -2));
}

public function testRenderMedianEmpty(): void
{
isSame('0.000±0.000', Stats::renderMedian([]));
}

public function testRenderMedian(): void
Expand All @@ -108,14 +123,15 @@ public function testRenderMedian(): void
isSame('5.5±2.9', Stats::renderMedian($data, 1));
isSame('5.50±2.87', Stats::renderMedian($data, 2));
isSame('6±3', Stats::renderMedian($data, 0));
isSame('6±3', Stats::renderMedian($data, -1));
isSame('10±0', Stats::renderMedian($data, -1));

$data = [72, 57, 66, 92, 32, 17, 146];
isSame('66.000±39.084', Stats::renderMedian($data));
isSame('66.0±39.1', Stats::renderMedian($data, 1));
isSame('66.00±39.08', Stats::renderMedian($data, 2));
isSame('66±39', Stats::renderMedian($data, 0));
isSame('66±39', Stats::renderMedian($data, -1));
isSame('70±40', Stats::renderMedian($data, -1));
isSame('100±0', Stats::renderMedian($data, -2));
}

public function testPercentile(): void
Expand Down

0 comments on commit 55ddbe0

Please sign in to comment.