Skip to content

Commit 6343647

Browse files
committed
refactor: Fix phpstan codeigniter.modelArgumentInstanceOf
1 parent 8fa633d commit 6343647

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

system/RESTful/BaseResource.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\HTTP\IncomingRequest;
1919
use CodeIgniter\HTTP\RequestInterface;
2020
use CodeIgniter\HTTP\ResponseInterface;
21+
use CodeIgniter\Model;
2122
use Psr\Log\LoggerInterface;
2223

2324
abstract class BaseResource extends Controller
@@ -30,12 +31,12 @@ abstract class BaseResource extends Controller
3031
protected $request;
3132

3233
/**
33-
* @var string|null The model that holding this resource's data
34+
* @var class-string<Model>|string|null The model that holding this resource's data
3435
*/
3536
protected $modelName;
3637

3738
/**
38-
* @var object|null The model that holding this resource's data
39+
* @var Model|object|null The model that holding this resource's data
3940
*/
4041
protected $model;
4142

@@ -55,15 +56,15 @@ public function initController(RequestInterface $request, ResponseInterface $res
5556
* Set or change the model this controller is bound to.
5657
* Given either the name or the object, determine the other.
5758
*
58-
* @param object|string|null $which
59+
* @param class-string<Model>|Model|object|string|null $which
5960
*
6061
* @return void
6162
*/
6263
public function setModel($which = null)
6364
{
6465
if ($which !== null) {
6566
$this->model = is_object($which) ? $which : null;
66-
$this->modelName = is_object($which) ? null : $which;
67+
$this->modelName = is_object($which) ? '' : $which;
6768
}
6869

6970
if (empty($this->model) && ! empty($this->modelName) && class_exists($this->modelName)) {

tests/system/CommonFunctionsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public function testCSRFMeta(): void
400400

401401
public function testModelNotExists(): void
402402
{
403-
$this->assertNull(model(UnexsistenceClass::class)); // @phpstan-ignore class.notFound
403+
$this->assertNull(model(UnexsistenceClass::class)); // @phpstan-ignore class.notFound, codeigniter.modelArgumentInstanceof
404404
}
405405

406406
public function testModelExistsBasename(): void
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# total 2 errors
1+
# total 1 error
22

33
parameters:
44
ignoreErrors:
55
-
66
message: '#^Argument \#1 \$name \(class\-string\) passed to function model does not extend CodeIgniter\\\\Model\.$#'
77
count: 1
88
path: ../../system/RESTful/BaseResource.php
9-
10-
-
11-
message: '#^Argument \#1 \$name \(''CodeIgniter\\\\UnexsistenceClass''\) passed to function model does not extend CodeIgniter\\\\Model\.$#'
12-
count: 1
13-
path: ../../tests/system/CommonFunctionsTest.php

0 commit comments

Comments
 (0)