Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Fix phpstan codeigniter.modelArgumentInstanceOf #9391

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ parameters:
RESTful:
- +API
- +Controller
- +Model
Router:
- HTTP
Security:
Expand Down
9 changes: 5 additions & 4 deletions system/RESTful/BaseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Model>|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;

Expand All @@ -55,15 +56,15 @@ 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>|Model|object|string|null $which
*
* @return void
*/
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)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# total 2 errors
# total 1 error

parameters:
ignoreErrors:
-
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
Loading