Skip to content

Commit 55ddbe0

Browse files
authored
Update PHP 8.3 (#47)
1 parent ea60d1b commit 55ddbe0

File tree

9 files changed

+44
-21
lines changed

9 files changed

+44
-21
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
3535
strategy:
3636
matrix:
37-
php-version: [ 8.1, 8.2 ]
37+
php-version: [ 8.1, 8.2, 8.3 ]
3838
coverage: [ xdebug, none ]
3939
composer_flags: [ "--prefer-lowest", "" ]
4040
steps:
@@ -77,7 +77,7 @@ jobs:
7777
runs-on: ubuntu-latest
7878
strategy:
7979
matrix:
80-
php-version: [ 8.1, 8.2 ]
80+
php-version: [ 8.1, 8.2, 8.3 ]
8181
steps:
8282
- name: Checkout code
8383
uses: actions/checkout@v3
@@ -111,7 +111,7 @@ jobs:
111111
runs-on: ubuntu-latest
112112
strategy:
113113
matrix:
114-
php-version: [ 8.1, 8.2 ]
114+
php-version: [ 8.1, 8.2, 8.3 ]
115115
steps:
116116
- name: Checkout code
117117
uses: actions/checkout@v3

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
},
5757

5858
"require-dev" : {
59-
"jbzoo/toolbox-dev" : "^7.0",
60-
"jbzoo/data" : "^7.0",
61-
"symfony/process" : ">=4.4"
59+
"jbzoo/toolbox-dev" : "^7.1",
60+
"jbzoo/data" : "^7.1",
61+
"symfony/process" : ">=6.4"
6262
},
6363

6464
"suggest" : {

src/Dates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public static function timezone(null|\DateTimeZone|string $timezone = null): \Da
7474
return $timezone;
7575
}
7676

77-
$timezone = isStrEmpty($timezone) ? \date_default_timezone_get() : $timezone;
77+
$timezone = ($timezone === '' || $timezone === null) ? \date_default_timezone_get() : $timezone;
7878

79-
return new \DateTimeZone((string)$timezone);
79+
return new \DateTimeZone($timezone);
8080
}
8181

8282
/**

src/Filter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ public static function digits(?string $value): string
190190
// we need to remove - and + because they're allowed in the filter
191191
$cleaned = \str_replace(['-', '+'], '', (string)$value);
192192

193+
/**
194+
* @psalm-suppress RedundantCast
195+
*/
193196
return (string)\filter_var($cleaned, \FILTER_SANITIZE_NUMBER_INT);
194197
}
195198

src/Http.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public static function getHeaders(): array
145145
$authorizationHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
146146
}
147147

148-
if ($authorizationHeader) {
148+
if (bool($authorizationHeader)) {
149+
$authorizationHeader = (string)$authorizationHeader;
149150
if (\stripos($authorizationHeader, 'basic ') === 0) {
150151
// Decode AUTHORIZATION header into PHP_AUTH_USER
151152
// and PHP_AUTH_PW when authorization header is basic

src/Stats.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public static function mean(?array $values): float
6060
return 0;
6161
}
6262

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

6568
if ($sum === 0) {
@@ -148,8 +151,8 @@ public static function histogram(
148151
*/
149152
public static function renderAverage(array $values, int $rounding = 3): string
150153
{
151-
$avg = \number_format(self::mean($values), $rounding);
152-
$stdDev = \number_format(self::stdDev($values), $rounding);
154+
$avg = \number_format(\round(self::mean($values), $rounding), $rounding);
155+
$stdDev = \number_format(\round(self::stdDev($values), $rounding), $rounding);
153156

154157
return "{$avg}±{$stdDev}";
155158
}
@@ -159,10 +162,10 @@ public static function renderAverage(array $values, int $rounding = 3): string
159162
*/
160163
public static function renderMedian(array $values, int $rounding = 3): string
161164
{
162-
$avg = \number_format(self::median($values), $rounding);
163-
$stdDev = \number_format(self::stdDev($values), $rounding);
165+
$median = \number_format(\round(self::median($values), $rounding), $rounding);
166+
$stdDev = \number_format(\round(self::stdDev($values), $rounding), $rounding);
164167

165-
return "{$avg}±{$stdDev}";
168+
return "{$median}±{$stdDev}";
166169
}
167170

168171
/**

src/Url.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public static function path(): ?string
127127
// Get the rest of the URL
128128
if (!\array_key_exists('REQUEST_URI', $_SERVER)) {
129129
// Microsoft IIS doesn't set REQUEST_URI by default
130-
if ($queryString = $_SERVER['QUERY_STRING'] ?? null) {
130+
$queryString = $_SERVER['QUERY_STRING'] ?? null;
131+
if ($queryString !== null) {
131132
$url .= '?' . $queryString;
132133
}
133134
} else {

tests/SerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function testFix(): void
120120

121121
\unserialize($brokenSerialization, []);
122122

123-
is($expectedError['errno'], $reportedError['errno']);
124123
// Because HHVM's unserialize() error message does not contain enough info to properly test.
125124
if (!\defined('HHVM_VERSION')) {
126125
is($expectedError['errstr'], $reportedError['errstr']);

tests/StatsTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function testMean(): void
3131
isSame(2.0, Stats::mean([1, 3]));
3232
isSame(2.0, Stats::mean(['1', 3]));
3333
isSame(2.25, Stats::mean(['1.5', 3]));
34+
isSame(5.5, Stats::mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
35+
isSame(5.5, Stats::mean(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']));
3436

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

89+
public function testRenderAverageEmpty(): void
90+
{
91+
isSame('0.000±0.000', Stats::renderAverage([]));
92+
}
93+
8794
public function testRenderAverage(): void
8895
{
8996
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
9097
isSame('5.500±2.872', Stats::renderAverage($data));
91-
isSame('5.5±2.9', Stats::renderAverage($data, 1));
98+
isSame('5.5000±2.8723', Stats::renderAverage($data, 4));
99+
isSame('5.500±2.872', Stats::renderAverage($data, 3));
92100
isSame('5.50±2.87', Stats::renderAverage($data, 2));
101+
isSame('5.5±2.9', Stats::renderAverage($data, 1));
93102
isSame('6±3', Stats::renderAverage($data, 0));
94-
isSame('6±3', Stats::renderAverage($data, -1));
103+
isSame('10±0', Stats::renderAverage($data, -1));
95104

96105
$data = [72, 57, 66, 92, 32, 17, 146];
97106
isSame('68.857±39.084', Stats::renderAverage($data));
98107
isSame('68.9±39.1', Stats::renderAverage($data, 1));
99108
isSame('68.86±39.08', Stats::renderAverage($data, 2));
100109
isSame('69±39', Stats::renderAverage($data, 0));
101-
isSame('69±39', Stats::renderAverage($data, -1));
110+
isSame('70±40', Stats::renderAverage($data, -1));
111+
isSame('100±0', Stats::renderAverage($data, -2));
112+
}
113+
114+
public function testRenderMedianEmpty(): void
115+
{
116+
isSame('0.000±0.000', Stats::renderMedian([]));
102117
}
103118

104119
public function testRenderMedian(): void
@@ -108,14 +123,15 @@ public function testRenderMedian(): void
108123
isSame('5.5±2.9', Stats::renderMedian($data, 1));
109124
isSame('5.50±2.87', Stats::renderMedian($data, 2));
110125
isSame('6±3', Stats::renderMedian($data, 0));
111-
isSame('6±3', Stats::renderMedian($data, -1));
126+
isSame('10±0', Stats::renderMedian($data, -1));
112127

113128
$data = [72, 57, 66, 92, 32, 17, 146];
114129
isSame('66.000±39.084', Stats::renderMedian($data));
115130
isSame('66.0±39.1', Stats::renderMedian($data, 1));
116131
isSame('66.00±39.08', Stats::renderMedian($data, 2));
117132
isSame('66±39', Stats::renderMedian($data, 0));
118-
isSame('66±39', Stats::renderMedian($data, -1));
133+
isSame('70±40', Stats::renderMedian($data, -1));
134+
isSame('100±0', Stats::renderMedian($data, -2));
119135
}
120136

121137
public function testPercentile(): void

0 commit comments

Comments
 (0)