Skip to content

Commit 89fee62

Browse files
authored
refactor: fix phpstan issues on magic properties (#9728)
1 parent f16bf87 commit 89fee62

File tree

10 files changed

+20
-34
lines changed

10 files changed

+20
-34
lines changed

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function showHelp()
142142
{
143143
CLI::write(lang('CLI.helpUsage'), 'yellow');
144144

145-
if (isset($this->usage)) {
145+
if ($this->usage !== null) {
146146
$usage = $this->usage;
147147
} else {
148148
$usage = $this->name;
@@ -154,7 +154,7 @@ public function showHelp()
154154

155155
CLI::write($this->setPad($usage, 0, 0, 2));
156156

157-
if (isset($this->description)) {
157+
if ($this->description !== null) {
158158
CLI::newLine();
159159
CLI::write(lang('CLI.helpDescription'), 'yellow');
160160
CLI::write($this->setPad($this->description, 0, 0, 2));

system/CLI/Commands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function discoverCommands()
129129

130130
$class = new $className($this->logger, $this);
131131

132-
if (isset($class->group) && ! isset($this->commands[$class->name])) {
132+
if ($class->group !== null && ! isset($this->commands[$class->name])) {
133133
$this->commands[$class->name] = [
134134
'class' => $className,
135135
'file' => $file,

system/Database/MySQLi/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function connect(bool $persistent = false)
123123
$this->mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
124124
}
125125

126-
if (isset($this->strictOn)) {
126+
if ($this->strictOn !== null) {
127127
if ($this->strictOn) {
128128
$this->mysqli->options(
129129
MYSQLI_INIT_COMMAND,

system/Database/SQLite3/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function connect(bool $persistent = false)
107107
$this->database = WRITEPATH . $this->database;
108108
}
109109

110-
$sqlite = (! isset($this->password) || $this->password !== '')
110+
$sqlite = ($this->password === null || $this->password !== '')
111111
? new SQLite3($this->database)
112112
: new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password);
113113

system/Test/FeatureTestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ protected function populateGlobals(string $name, Request $request, ?array $param
404404
);
405405
}
406406

407-
$_SESSION = $this->session ?? [];
407+
$_SESSION = $this->session;
408408

409409
return $request;
410410
}

tests/system/Commands/BaseCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function testMagicIssetTrue(): void
3636
{
3737
$command = new AppInfo($this->logger, service('commands'));
3838

39-
$this->assertTrue(isset($command->group));
39+
$this->assertSame($command->group !== null, isset($command->group)); // @phpstan-ignore isset.property
4040
}
4141

4242
public function testMagicIssetFalse(): void
4343
{
4444
$command = new AppInfo($this->logger, service('commands'));
4545

46-
$this->assertFalse(isset($command->foobar));
46+
$this->assertFalse(isset($command->foobar)); // @phpstan-ignore property.notFound
4747
}
4848

4949
public function testMagicGet(): void
@@ -57,6 +57,6 @@ public function testMagicGetMissing(): void
5757
{
5858
$command = new AppInfo($this->logger, service('commands'));
5959

60-
$this->assertNull($command->foobar);
60+
$this->assertNull($command->foobar); // @phpstan-ignore property.notFound
6161
}
6262
}

tests/system/Database/BaseConnectionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ public function testMagicIssetTrue(): void
169169
{
170170
$db = new MockConnection($this->options);
171171

172-
$this->assertTrue(isset($db->charset));
172+
$this->assertSame($db->charset !== null, isset($db->charset)); // @phpstan-ignore isset.property
173173
}
174174

175175
public function testMagicIssetFalse(): void
176176
{
177177
$db = new MockConnection($this->options);
178178

179-
$this->assertFalse(isset($db->foobar));
179+
$this->assertFalse(isset($db->foobar)); // @phpstan-ignore property.notFound
180180
}
181181

182182
public function testMagicGet(): void
@@ -190,7 +190,7 @@ public function testMagicGetMissing(): void
190190
{
191191
$db = new MockConnection($this->options);
192192

193-
$this->assertNull($db->foobar);
193+
$this->assertNull($db->foobar); // @phpstan-ignore property.notFound
194194
}
195195

196196
/**

tests/system/I18n/TimeDifferenceTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testGetterUTC(): void
245245
$this->assertSame(8, $diff->getDays());
246246
$this->assertSame(8, $diff->days);
247247
$this->assertSame(-8, (int) round($diff->getDays(true)));
248-
$this->assertNull($diff->nonsense);
248+
$this->assertNull($diff->nonsense); // @phpstan-ignore property.notFound
249249
}
250250

251251
public function testGetterDST(): void
@@ -259,23 +259,23 @@ public function testGetterDST(): void
259259

260260
// The raw value does not take Daylight Saving Time into account.
261261
$this->assertSame(-8, (int) round($diff->getDays(true)));
262-
$this->assertNull($diff->nonsense);
262+
$this->assertNull($diff->nonsense); // @phpstan-ignore property.notFound
263263
}
264264

265265
public function testMagicIssetTrue(): void
266266
{
267267
$current = Time::parse('March 10, 2017', 'America/Chicago');
268268
$diff = $current->difference('March 18, 2017', 'America/Chicago');
269269

270-
$this->assertTrue(isset($diff->days));
271-
$this->assertFalse(isset($diff->nonsense));
270+
$this->assertTrue(isset($diff->days)); // @phpstan-ignore isset.property
271+
$this->assertFalse(isset($diff->nonsense)); // @phpstan-ignore property.notFound
272272
}
273273

274274
public function testMagicIssetFalse(): void
275275
{
276276
$current = Time::parse('March 10, 2017', 'America/Chicago');
277277
$diff = $current->difference('March 18, 2017', 'America/Chicago');
278278

279-
$this->assertFalse(isset($diff->nonsense));
279+
$this->assertFalse(isset($diff->nonsense)); // @phpstan-ignore property.notFound
280280
}
281281
}

utils/phpstan-baseline/loader.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# total 2808 errors
1+
# total 2800 errors
2+
23
includes:
34
- argument.type.neon
45
- assign.propertyType.neon

utils/phpstan-baseline/property.notFound.neon

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 59 errors
1+
# total 51 errors
22

33
parameters:
44
ignoreErrors:
@@ -27,16 +27,6 @@ parameters:
2727
count: 1
2828
path: ../../system/Session/Handlers/RedisHandler.php
2929

30-
-
31-
message: '#^Access to an undefined property Tests\\Support\\Commands\\AppInfo\:\:\$foobar\.$#'
32-
count: 2
33-
path: ../../tests/system/Commands/BaseCommandTest.php
34-
35-
-
36-
message: '#^Access to an undefined property CodeIgniter\\Test\\Mock\\MockConnection\:\:\$foobar\.$#'
37-
count: 2
38-
path: ../../tests/system/Database/BaseConnectionTest.php
39-
4030
-
4131
message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$mysqli\.$#'
4232
count: 1
@@ -102,11 +92,6 @@ parameters:
10292
count: 1
10393
path: ../../tests/system/Encryption/Handlers/SodiumHandlerTest.php
10494

105-
-
106-
message: '#^Access to an undefined property CodeIgniter\\I18n\\TimeDifference\:\:\$nonsense\.$#'
107-
count: 4
108-
path: ../../tests/system/I18n/TimeDifferenceTest.php
109-
11095
-
11196
message: '#^Access to an undefined property CodeIgniter\\I18n\\TimeLegacy\:\:\$foobar\.$#'
11297
count: 1

0 commit comments

Comments
 (0)