Skip to content

Commit d4f8dcf

Browse files
committed
fix: safely cast DateTimeInterface to string in toRawArray
Use method_exists() check before (string) cast to prevent Fatal Error on native PHP DateTime objects that lack __toString(). Fall back to format('Y-m-d H:i:s') when __toString() is not available. Also regenerate phpstan baseline to eliminate stale ignore.unmatched entries.
1 parent 7b47436 commit d4f8dcf

3 files changed

Lines changed: 3 additions & 128 deletions

File tree

system/Entity/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function toRawArray(bool $onlyChanged = false, bool $recursive = false):
235235
$convert = static function ($value) use (&$convert, $recursive) {
236236
// Always convert DateTime objects to string for raw output
237237
if ($value instanceof DateTimeInterface) {
238-
return (string) $value;
238+
return method_exists($value, '__toString') ? (string) $value : $value->format('Y-m-d H:i:s');
239239
}
240240

241241
if (! $recursive) {

utils/phpstan-baseline/argument.type.neon

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
# total 228 errors
1+
# total 68 errors
22

33
parameters:
44
ignoreErrors:
5-
-
6-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\RedirectResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
7-
count: 1
8-
path: ../../system/Config/Services.php
9-
10-
-
11-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
12-
count: 2
13-
path: ../../system/Config/Services.php
14-
155
-
166
message: '#^Parameter \#3 \.\.\.\$arrays of function array_map expects array, int\|string given\.$#'
177
count: 1
@@ -32,26 +22,6 @@ parameters:
3222
count: 1
3323
path: ../../system/Database/SQLite3/Builder.php
3424

35-
-
36-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
37-
count: 1
38-
path: ../../system/HTTP/CURLRequest.php
39-
40-
-
41-
message: '#^Parameter \#1 \$config of method CodeIgniter\\HTTP\\Response\:\:__construct\(\) expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
42-
count: 1
43-
path: ../../system/HTTP/DownloadResponse.php
44-
45-
-
46-
message: '#^Parameter \#1 \$config of class CodeIgniter\\Test\\Mock\\MockResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
47-
count: 2
48-
path: ../../tests/system/API/ResponseTraitTest.php
49-
50-
-
51-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
52-
count: 19
53-
path: ../../tests/system/Cache/ResponseCacheTest.php
54-
5525
-
5626
message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: CodeIgniter\\HTTP\\ResponseInterface given\.$#'
5727
count: 1
@@ -72,11 +42,6 @@ parameters:
7242
count: 1
7343
path: ../../tests/system/CodeIgniterTest.php
7444

75-
-
76-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\RedirectResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
77-
count: 3
78-
path: ../../tests/system/CommonFunctionsTest.php
79-
8045
-
8146
message: '#^Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) expects class\-string\<Config\\TestRegistrar\>, string given\.$#'
8247
count: 1
@@ -87,16 +52,6 @@ parameters:
8752
count: 2
8853
path: ../../tests/system/Config/FactoriesTest.php
8954

90-
-
91-
message: '#^Parameter \#1 \$config of class CodeIgniter\\Test\\Mock\\MockResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
92-
count: 7
93-
path: ../../tests/system/Config/ServicesTest.php
94-
95-
-
96-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
97-
count: 1
98-
path: ../../tests/system/ControllerTest.php
99-
10055
-
10156
message: '#^Parameter \#1 \$from of method CodeIgniter\\Database\\BaseBuilder\:\:from\(\) expects array\|string, null given\.$#'
10257
count: 1
@@ -142,66 +97,16 @@ parameters:
14297
count: 1
14398
path: ../../tests/system/Debug/TimerTest.php
14499

145-
-
146-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\RedirectResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
147-
count: 1
148-
path: ../../tests/system/Filters/PageCacheTest.php
149-
150-
-
151-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
152-
count: 10
153-
path: ../../tests/system/Filters/PageCacheTest.php
154-
155-
-
156-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
157-
count: 1
158-
path: ../../tests/system/HTTP/CURLRequestShareOptionsTest.php
159-
160-
-
161-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
162-
count: 1
163-
path: ../../tests/system/HTTP/CURLRequestTest.php
164-
165-
-
166-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
167-
count: 6
168-
path: ../../tests/system/HTTP/ContentSecurityPolicyTest.php
169-
170100
-
171101
message: '#^Parameter \#1 \$array of method CodeIgniter\\Superglobals\:\:setServerArray\(\) expects array\<string, array\<mixed\>\|float\|int\|string\>, array\<string, string\|null\> given\.$#'
172102
count: 1
173103
path: ../../tests/system/HTTP/MessageTest.php
174104

175-
-
176-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\RedirectResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
177-
count: 15
178-
path: ../../tests/system/HTTP/RedirectResponseTest.php
179-
180-
-
181-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
182-
count: 27
183-
path: ../../tests/system/HTTP/ResponseCookieTest.php
184-
185-
-
186-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
187-
count: 5
188-
path: ../../tests/system/HTTP/ResponseSendTest.php
189-
190105
-
191106
message: '#^Parameter \#3 \$expire of method CodeIgniter\\HTTP\\Response\:\:setCookie\(\) expects int, string given\.$#'
192107
count: 1
193108
path: ../../tests/system/HTTP/ResponseSendTest.php
194109

195-
-
196-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
197-
count: 43
198-
path: ../../tests/system/HTTP/ResponseTest.php
199-
200-
-
201-
message: '#^Parameter \#1 \$config of class CodeIgniter\\Test\\Mock\\MockResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
202-
count: 2
203-
path: ../../tests/system/HTTP/ResponseTest.php
204-
205110
-
206111
message: '#^Parameter \#1 \$data of method CodeIgniter\\HTTP\\Message\:\:setBody\(\) expects string, array\<string, list\<int\>\|string\> given\.$#'
207112
count: 2
@@ -217,11 +122,6 @@ parameters:
217122
count: 1
218123
path: ../../tests/system/HTTP/SiteURITest.php
219124

220-
-
221-
message: '#^Parameter \#1 \$config of class CodeIgniter\\Test\\Mock\\MockResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
222-
count: 1
223-
path: ../../tests/system/Helpers/CookieHelperTest.php
224-
225125
-
226126
message: '#^Parameter \#2 \$value of function form_hidden expects array\|string, null given\.$#'
227127
count: 1
@@ -252,21 +152,11 @@ parameters:
252152
count: 2
253153
path: ../../tests/system/Images/GDHandlerTest.php
254154

255-
-
256-
message: '#^Parameter \#1 \$config of class CodeIgniter\\Test\\Mock\\MockResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
257-
count: 1
258-
path: ../../tests/system/Log/Handlers/ChromeLoggerHandlerTest.php
259-
260155
-
261156
message: '#^Parameter \#2 \$message of method CodeIgniter\\Log\\Handlers\\ChromeLoggerHandler\:\:handle\(\) expects string, stdClass given\.$#'
262157
count: 1
263158
path: ../../tests/system/Log/Handlers/ChromeLoggerHandlerTest.php
264159

265-
-
266-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
267-
count: 2
268-
path: ../../tests/system/RESTful/ResourceControllerTest.php
269-
270160
-
271161
message: '#^Parameter \#1 \$format of method CodeIgniter\\RESTful\\ResourceController\:\:setFormat\(\) expects ''json''\|''xml'', ''Nonsense'' given\.$#'
272162
count: 1
@@ -282,11 +172,6 @@ parameters:
282172
count: 1
283173
path: ../../tests/system/Test/FeatureTestTraitTest.php
284174

285-
-
286-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
287-
count: 2
288-
path: ../../tests/system/Test/TestCaseEmissionsTest.php
289-
290175
-
291176
message: '#^Parameter \#1 \$body of method CodeIgniter\\HTTP\\Response\:\:setJSON\(\) expects array\|object\|string, false given\.$#'
292177
count: 1
@@ -297,16 +182,6 @@ parameters:
297182
count: 1
298183
path: ../../tests/system/Test/TestResponseTest.php
299184

300-
-
301-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\RedirectResponse constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
302-
count: 5
303-
path: ../../tests/system/Test/TestResponseTest.php
304-
305-
-
306-
message: '#^Parameter \#1 \$config of class CodeIgniter\\HTTP\\Response constructor expects CodeIgniter\\HTTP\\App, Config\\App given\.$#'
307-
count: 1
308-
path: ../../tests/system/Test/TestResponseTest.php
309-
310185
-
311186
message: '#^Parameter \#3 \$errors of method CodeIgniter\\Validation\\Validation\:\:check\(\) expects list\<string\>, array\{is_numeric\: ''Nope\. Not a number\.''\} given\.$#'
312187
count: 1

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1972 errors
1+
# total 1812 errors
22

33
includes:
44
- argument.type.neon

0 commit comments

Comments
 (0)