Skip to content

Commit 684e933

Browse files
committed
refactor: fix empty.property errors
1 parent bd60f50 commit 684e933

File tree

6 files changed

+14
-51
lines changed

6 files changed

+14
-51
lines changed

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ protected function resetSelect()
34073407
'QBUnion' => [],
34083408
]);
34093409

3410-
if (! empty($this->db)) {
3410+
if ($this->db instanceof BaseConnection) {
34113411
$this->db->setAliasedTables([]);
34123412
}
34133413

system/Images/Handlers/BaseHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class BaseHandler implements ImageHandlerInterface
3434
/**
3535
* The image/file instance
3636
*
37-
* @var Image
37+
* @var Image|null
3838
*/
3939
protected $image;
4040

@@ -138,6 +138,8 @@ public function __construct($config = null)
138138
* Sets another image for this handler to work on.
139139
* Keeps us from needing to continually instantiate the handler.
140140
*
141+
* @phpstan-assert Image $this->image
142+
*
141143
* @return $this
142144
*/
143145
public function withFile(string $path)
@@ -176,7 +178,7 @@ public function getFile()
176178
/**
177179
* Verifies that a file has been supplied and it is an image.
178180
*
179-
* @return Image The image instance
181+
* @phpstan-assert Image $this->image
180182
*
181183
* @throws ImageException
182184
*/
@@ -187,7 +189,7 @@ protected function image(): Image
187189
}
188190

189191
// Verify withFile has been called
190-
if (empty($this->image)) {
192+
if ($this->image === null) {
191193
throw ImageException::forMissingImage();
192194
}
193195

system/Test/ControllerTestTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function setUpControllerTestTrait(): void
9595
// The URL helper is always loaded by the system so ensure it is available.
9696
helper('url');
9797

98-
if (empty($this->appConfig)) {
98+
if (! $this->appConfig instanceof App) {
9999
$this->appConfig = config(App::class);
100100
}
101101

@@ -104,7 +104,7 @@ protected function setUpControllerTestTrait(): void
104104
$this->uri = $factory->createFromGlobals();
105105
}
106106

107-
if (empty($this->request)) {
107+
if (! $this->request instanceof IncomingRequest) {
108108
// Do some acrobatics, so we can use the Request service with our own URI
109109
$tempUri = service('uri');
110110
Services::injectMock('uri', $this->uri);
@@ -115,11 +115,11 @@ protected function setUpControllerTestTrait(): void
115115
Services::injectMock('uri', $tempUri);
116116
}
117117

118-
if (empty($this->response)) {
118+
if (! $this->response instanceof ResponseInterface) {
119119
$this->response = service('response', $this->appConfig, false);
120120
}
121121

122-
if (empty($this->logger)) {
122+
if (! $this->logger instanceof LoggerInterface) {
123123
$this->logger = service('logger');
124124
}
125125
}

utils/phpstan-baseline/empty.notAllowed.neon

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 271 errors
1+
# total 265 errors
22

33
parameters:
44
ignoreErrors:
@@ -39,7 +39,7 @@ parameters:
3939

4040
-
4141
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
42-
count: 29
42+
count: 28
4343
path: ../../system/Database/BaseBuilder.php
4444

4545
-
@@ -289,7 +289,7 @@ parameters:
289289

290290
-
291291
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
292-
count: 3
292+
count: 2
293293
path: ../../system/Images/Handlers/BaseHandler.php
294294

295295
-
@@ -367,11 +367,6 @@ parameters:
367367
count: 1
368368
path: ../../tests/system/Session/SessionTest.php
369369

370-
-
371-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
372-
count: 4
373-
path: ../../tests/system/Test/ControllerTestTraitTest.php
374-
375370
-
376371
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
377372
count: 1

utils/phpstan-baseline/empty.property.neon

Lines changed: 0 additions & 33 deletions
This file was deleted.

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 3760 errors
1+
# total 3748 errors
22
includes:
33
- argument.type.neon
44
- assign.propertyType.neon
@@ -10,7 +10,6 @@ includes:
1010
- codeigniter.unknownServiceMethod.neon
1111
- deadCode.unreachable.neon
1212
- empty.notAllowed.neon
13-
- empty.property.neon
1413
- function.alreadyNarrowedType.neon
1514
- generator.valueType.neon
1615
- isset.property.neon

0 commit comments

Comments
 (0)