Skip to content

Commit 7aad65d

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents f432f41 + 99ef79b commit 7aad65d

File tree

26 files changed

+245
-58
lines changed

26 files changed

+245
-58
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@
20932093
];
20942094
$ignoreErrors[] = [
20952095
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
2096-
'count' => 6,
2096+
'count' => 5,
20972097
'path' => __DIR__ . '/system/HTTP/IncomingRequest.php',
20982098
];
20992099
$ignoreErrors[] = [

system/Commands/Generators/Views/filter.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class {class} implements FilterInterface
2121
* @param RequestInterface $request
2222
* @param array|null $arguments
2323
*
24-
* @return mixed
24+
* @return RequestInterface|ResponseInterface|string|void
2525
*/
2626
public function before(RequestInterface $request, $arguments = null)
2727
{
@@ -38,7 +38,7 @@ public function before(RequestInterface $request, $arguments = null)
3838
* @param ResponseInterface $response
3939
* @param array|null $arguments
4040
*
41-
* @return mixed
41+
* @return ResponseInterface|void
4242
*/
4343
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
4444
{

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ function is_windows(?bool $mock = null): bool
755755
* A convenience method to translate a string or array of them and format
756756
* the result with the intl extension's MessageFormatter.
757757
*
758-
* @return string
758+
* @return list<string>|string
759759
*/
760760
function lang(string $line, array $args = [], ?string $locale = null)
761761
{

system/HTTP/IncomingRequest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?U
165165
$body = file_get_contents('php://input');
166166
}
167167

168+
// If file_get_contents() returns false or empty string, set null.
169+
if ($body === false || $body === '') {
170+
$body = null;
171+
}
172+
168173
$this->config = $config;
169174
$this->uri = $uri;
170-
$this->body = ! empty($body) ? $body : null;
175+
$this->body = $body;
171176
$this->userAgent = $userAgent;
172177
$this->validLocales = $config->supportedLocales;
173178

system/Language/Language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function getLocale(): string
8888
* Parses the language string for a file, loads the file, if necessary,
8989
* getting the line.
9090
*
91-
* @return string|string[]
91+
* @return list<string>|string
9292
*/
9393
public function getLine(string $line, array $args = [])
9494
{

system/Validation/Rules.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class Rules
2424
/**
2525
* The value does not match another field in $data.
2626
*
27-
* @param array $data Other field/value pairs
27+
* @param string|null $str
28+
* @param array $data Other field/value pairs
2829
*/
29-
public function differs(?string $str, string $field, array $data): bool
30+
public function differs($str, string $field, array $data): bool
3031
{
3132
if (strpos($field, '.') !== false) {
3233
return $str !== dot_array_search($field, $data);
@@ -231,15 +232,16 @@ public function less_than_equal_to($str, string $max): bool
231232
/**
232233
* Matches the value of another field in $data.
233234
*
234-
* @param array $data Other field/value pairs
235+
* @param string|null $str
236+
* @param array $data Other field/value pairs
235237
*/
236-
public function matches(?string $str, string $field, array $data): bool
238+
public function matches($str, string $field, array $data): bool
237239
{
238240
if (strpos($field, '.') !== false) {
239241
return $str === dot_array_search($field, $data);
240242
}
241243

242-
return array_key_exists($field, $data) && $str === $data[$field];
244+
return isset($data[$field]) && $str === $data[$field];
243245
}
244246

245247
/**

system/Validation/StrictRules/Rules.php

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@ public function __construct()
3636
* @param array|bool|float|int|object|string|null $str
3737
* @param array $data Other field/value pairs
3838
*/
39-
public function differs($str, string $field, array $data): bool
40-
{
41-
if (! is_string($str)) {
39+
public function differs(
40+
$str,
41+
string $otherField,
42+
array $data,
43+
?string $error = null,
44+
?string $field = null
45+
): bool {
46+
if (strpos($otherField, '.') !== false) {
47+
return $str !== dot_array_search($otherField, $data);
48+
}
49+
50+
if (! array_key_exists($field, $data)) {
4251
return false;
4352
}
4453

45-
return $this->nonStrictRules->differs($str, $field, $data);
54+
if (! array_key_exists($otherField, $data)) {
55+
return false;
56+
}
57+
58+
return $str !== ($data[$otherField] ?? null);
4659
}
4760

4861
/**
@@ -254,9 +267,26 @@ public function less_than_equal_to($str, string $max): bool
254267
* @param array|bool|float|int|object|string|null $str
255268
* @param array $data Other field/value pairs
256269
*/
257-
public function matches($str, string $field, array $data): bool
258-
{
259-
return $this->nonStrictRules->matches($str, $field, $data);
270+
public function matches(
271+
$str,
272+
string $otherField,
273+
array $data,
274+
?string $error = null,
275+
?string $field = null
276+
): bool {
277+
if (strpos($otherField, '.') !== false) {
278+
return $str === dot_array_search($otherField, $data);
279+
}
280+
281+
if (! array_key_exists($field, $data)) {
282+
return false;
283+
}
284+
285+
if (! array_key_exists($otherField, $data)) {
286+
return false;
287+
}
288+
289+
return $str === ($data[$otherField] ?? null);
260290
}
261291

262292
/**

tests/system/Config/BaseConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testUseDefaultValueTypeIntAndFloatValues(): void
8080
$dotenv->load();
8181
$config = new SimpleConfig();
8282

83-
$this->assertSame(0.0, $config->float);
83+
$this->assertEqualsWithDelta(0.0, $config->float, PHP_FLOAT_EPSILON);
8484
$this->assertSame(999, $config->int);
8585
}
8686

tests/system/Database/Live/SelectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ public function testSelectAvg(): void
8686
{
8787
$result = $this->db->table('job')->selectAvg('id')->get()->getRow();
8888

89-
$this->assertSame(2.5, (float) $result->id);
89+
$this->assertEqualsWithDelta(2.5, (float) $result->id, PHP_FLOAT_EPSILON);
9090
}
9191

9292
public function testSelectAvgWithAlias(): void
9393
{
9494
$result = $this->db->table('job')->selectAvg('id', 'xam')->get()->getRow();
9595

96-
$this->assertSame(2.5, (float) $result->xam);
96+
$this->assertEqualsWithDelta(2.5, (float) $result->xam, PHP_FLOAT_EPSILON);
9797
}
9898

9999
public function testSelectSum(): void

tests/system/Entity/EntityTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ public function testCastFloat(): void
373373
$entity->second = 3;
374374

375375
$this->assertIsFloat($entity->second);
376-
$this->assertSame(3.0, $entity->second);
376+
$this->assertEqualsWithDelta(3.0, $entity->second, PHP_FLOAT_EPSILON);
377377

378378
$entity->second = '3.6';
379379

380380
$this->assertIsFloat($entity->second);
381-
$this->assertSame(3.6, $entity->second);
381+
$this->assertEqualsWithDelta(3.6, $entity->second, PHP_FLOAT_EPSILON);
382382
}
383383

384384
public function testCastDouble(): void
@@ -388,12 +388,12 @@ public function testCastDouble(): void
388388
$entity->third = 3;
389389

390390
$this->assertIsFloat($entity->third);
391-
$this->assertSame(3.0, $entity->third);
391+
$this->assertEqualsWithDelta(3.0, $entity->third, PHP_FLOAT_EPSILON);
392392

393393
$entity->third = '3.6';
394394

395395
$this->assertIsFloat($entity->third);
396-
$this->assertSame(3.6, $entity->third);
396+
$this->assertEqualsWithDelta(3.6, $entity->third, PHP_FLOAT_EPSILON);
397397
}
398398

399399
public function testCastString(): void

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ public function testHeaderContentLengthNotSharedBetweenClients(): void
267267
public function testOptionsDelay(): void
268268
{
269269
$request = $this->getRequest();
270-
$this->assertSame(0.0, $request->getDelay());
270+
$this->assertEqualsWithDelta(0.0, $request->getDelay(), PHP_FLOAT_EPSILON);
271271

272272
$options = [
273273
'delay' => 2000,
274274
'headers' => ['fruit' => 'apple'],
275275
];
276276
$request = $this->getRequest($options);
277-
$this->assertSame(2.0, $request->getDelay());
277+
$this->assertEqualsWithDelta(2.0, $request->getDelay(), PHP_FLOAT_EPSILON);
278278
}
279279

280280
public function testPatchSetsCorrectMethod(): void
@@ -356,10 +356,10 @@ public function testRequestSetsBasicCurlOptions(): void
356356
$this->assertTrue($options[CURLOPT_FRESH_CONNECT]);
357357

358358
$this->assertArrayHasKey(CURLOPT_TIMEOUT_MS, $options);
359-
$this->assertSame(0.0, $options[CURLOPT_TIMEOUT_MS]);
359+
$this->assertEqualsWithDelta(0.0, $options[CURLOPT_TIMEOUT_MS], PHP_FLOAT_EPSILON);
360360

361361
$this->assertArrayHasKey(CURLOPT_CONNECTTIMEOUT_MS, $options);
362-
$this->assertSame(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS]);
362+
$this->assertEqualsWithDelta(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS], PHP_FLOAT_EPSILON);
363363
}
364364

365365
public function testAuthBasicOption(): void
@@ -734,7 +734,7 @@ public function testSendWithDelay(): void
734734
$request->get('products');
735735

736736
// we still need to check the code coverage to make sure this was done
737-
$this->assertSame(0.1, $request->getDelay());
737+
$this->assertEqualsWithDelta(0.1, $request->getDelay(), PHP_FLOAT_EPSILON);
738738
}
739739

740740
public function testSendContinued(): void

tests/system/HTTP/CURLRequestTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ public function testHeaderContentLengthNotSharedBetweenClients(): void
250250
public function testOptionsDelay(): void
251251
{
252252
$request = $this->getRequest();
253-
$this->assertSame(0.0, $request->getDelay());
253+
$this->assertEqualsWithDelta(0.0, $request->getDelay(), PHP_FLOAT_EPSILON);
254254

255255
$options = [
256256
'delay' => 2000,
257257
'headers' => ['fruit' => 'apple'],
258258
];
259259
$request = $this->getRequest($options);
260-
$this->assertSame(2.0, $request->getDelay());
260+
$this->assertEqualsWithDelta(2.0, $request->getDelay(), PHP_FLOAT_EPSILON);
261261
}
262262

263263
public function testPatchSetsCorrectMethod(): void
@@ -339,10 +339,10 @@ public function testRequestSetsBasicCurlOptions(): void
339339
$this->assertTrue($options[CURLOPT_FRESH_CONNECT]);
340340

341341
$this->assertArrayHasKey(CURLOPT_TIMEOUT_MS, $options);
342-
$this->assertSame(0.0, $options[CURLOPT_TIMEOUT_MS]);
342+
$this->assertEqualsWithDelta(0.0, $options[CURLOPT_TIMEOUT_MS], PHP_FLOAT_EPSILON);
343343

344344
$this->assertArrayHasKey(CURLOPT_CONNECTTIMEOUT_MS, $options);
345-
$this->assertSame(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS]);
345+
$this->assertEqualsWithDelta(150000.0, $options[CURLOPT_CONNECTTIMEOUT_MS], PHP_FLOAT_EPSILON);
346346
}
347347

348348
public function testAuthBasicOption(): void
@@ -717,7 +717,7 @@ public function testSendWithDelay(): void
717717
$request->get('products');
718718

719719
// we still need to check the code coverage to make sure this was done
720-
$this->assertSame(0.1, $request->getDelay());
720+
$this->assertEqualsWithDelta(0.1, $request->getDelay(), PHP_FLOAT_EPSILON);
721721
}
722722

723723
public function testSendContinued(): void

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function testCanGetAVariableFromJson(): void
348348
$this->assertSame('buzz', $jsonVar->fizz);
349349
$this->assertSame('buzz', $request->getJsonVar('baz.fizz'));
350350
$this->assertSame(123, $request->getJsonVar('int'));
351-
$this->assertSame(3.14, $request->getJsonVar('float'));
351+
$this->assertEqualsWithDelta(3.14, $request->getJsonVar('float'), PHP_FLOAT_EPSILON);
352352
$this->assertTrue($request->getJsonVar('true'));
353353
$this->assertFalse($request->getJsonVar('false'));
354354
$this->assertNull($request->getJsonVar('null'));
@@ -379,7 +379,7 @@ public function testGetJsonVarAsArray(): void
379379
$this->assertSame('buzz', $jsonVar['fizz']);
380380
$this->assertSame('bar', $jsonVar['foo']);
381381
$this->assertSame(123, $jsonVar['int']);
382-
$this->assertSame(3.14, $jsonVar['float']);
382+
$this->assertEqualsWithDelta(3.14, $jsonVar['float'], PHP_FLOAT_EPSILON);
383383
$this->assertTrue($jsonVar['true']);
384384
$this->assertFalse($jsonVar['false']);
385385
$this->assertNull($jsonVar['null']);
@@ -518,7 +518,7 @@ public function testGetJsonVarReturnsNullFromNullBody(): void
518518
$this->assertNull($request->getJsonVar('myKey'));
519519
}
520520

521-
public function testgetJSONReturnsNullFromNullBody(): void
521+
public function testGetJSONReturnsNullFromNullBody(): void
522522
{
523523
$config = new App();
524524
$config->baseURL = 'http://example.com/';
@@ -847,7 +847,7 @@ public function testGetPostSecondStreams(): void
847847
$this->assertSame(array_merge($_POST, $_GET), $this->request->getGetPost());
848848
}
849849

850-
public function testWithFalseBody(): void
850+
public function testGetBodyWithFalseBody(): void
851851
{
852852
// Use `false` here to simulate file_get_contents returning a false value
853853
$request = $this->createRequest(null, false);
@@ -856,6 +856,13 @@ public function testWithFalseBody(): void
856856
$this->assertNull($request->getBody());
857857
}
858858

859+
public function testGetBodyWithZero(): void
860+
{
861+
$request = $this->createRequest(null, '0');
862+
863+
$this->assertSame('0', $request->getBody());
864+
}
865+
859866
/**
860867
* @see https://github.com/codeigniter4/CodeIgniter4/issues/3020
861868
*/

tests/system/Session/Handlers/Database/RedisHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testSavePathTimeoutFloat(): void
9393

9494
$savePath = $this->getPrivateProperty($handler, 'savePath');
9595

96-
$this->assertSame(2.5, $savePath['timeout']);
96+
$this->assertEqualsWithDelta(2.5, $savePath['timeout'], PHP_FLOAT_EPSILON);
9797
}
9898

9999
public function testSavePathTimeoutInt(): void
@@ -104,7 +104,7 @@ public function testSavePathTimeoutInt(): void
104104

105105
$savePath = $this->getPrivateProperty($handler, 'savePath');
106106

107-
$this->assertSame(10.0, $savePath['timeout']);
107+
$this->assertEqualsWithDelta(10.0, $savePath['timeout'], PHP_FLOAT_EPSILON);
108108
}
109109

110110
public function testOpen(): void

tests/system/Throttle/ThrottleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testFlooding(): void
185185
$throttler = $throttler->setTestTime($time + 10);
186186

187187
$this->assertTrue($throttler->check('127.0.0.1', $rate, MINUTE, 0));
188-
$this->assertSame(10.0, round($this->cache->get('throttler_127.0.0.1')));
188+
$this->assertEqualsWithDelta(10.0, round($this->cache->get('throttler_127.0.0.1')), PHP_FLOAT_EPSILON);
189189
}
190190

191191
/**

0 commit comments

Comments
 (0)