diff --git a/system/RESTful/BaseResource.php b/system/RESTful/BaseResource.php index f2e171c8319e..a4168c1ac0b3 100644 --- a/system/RESTful/BaseResource.php +++ b/system/RESTful/BaseResource.php @@ -18,6 +18,7 @@ use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Model; use Psr\Log\LoggerInterface; abstract class BaseResource extends Controller @@ -30,12 +31,12 @@ abstract class BaseResource extends Controller protected $request; /** - * @var string|null The model that holding this resource's data + * @var class-string|string|null The model that holding this resource's data */ protected $modelName; /** - * @var object|null The model that holding this resource's data + * @var Model|object|null The model that holding this resource's data */ protected $model; @@ -55,7 +56,7 @@ public function initController(RequestInterface $request, ResponseInterface $res * Set or change the model this controller is bound to. * Given either the name or the object, determine the other. * - * @param object|string|null $which + * @param class-string|Model|object|string|null $which * * @return void */ @@ -63,7 +64,7 @@ public function setModel($which = null) { if ($which !== null) { $this->model = is_object($which) ? $which : null; - $this->modelName = is_object($which) ? null : $which; + $this->modelName = is_object($which) ? '' : $which; } if (empty($this->model) && ! empty($this->modelName) && class_exists($this->modelName)) { diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index deef63d79821..b390f4f8709f 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -400,7 +400,7 @@ public function testCSRFMeta(): void public function testModelNotExists(): void { - $this->assertNull(model(UnexsistenceClass::class)); // @phpstan-ignore class.notFound + $this->assertNull(model(UnexsistenceClass::class)); // @phpstan-ignore class.notFound, codeigniter.modelArgumentInstanceof } public function testModelExistsBasename(): void diff --git a/utils/phpstan-baseline/codeigniter.modelArgumentInstanceof.neon b/utils/phpstan-baseline/codeigniter.modelArgumentInstanceof.neon index 8d709df14603..d29e43b3aef8 100644 --- a/utils/phpstan-baseline/codeigniter.modelArgumentInstanceof.neon +++ b/utils/phpstan-baseline/codeigniter.modelArgumentInstanceof.neon @@ -1,4 +1,4 @@ -# total 2 errors +# total 1 error parameters: ignoreErrors: @@ -6,8 +6,3 @@ parameters: message: '#^Argument \#1 \$name \(class\-string\) passed to function model does not extend CodeIgniter\\\\Model\.$#' count: 1 path: ../../system/RESTful/BaseResource.php - - - - message: '#^Argument \#1 \$name \(''CodeIgniter\\\\UnexsistenceClass''\) passed to function model does not extend CodeIgniter\\\\Model\.$#' - count: 1 - path: ../../tests/system/CommonFunctionsTest.php