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 1 commit 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
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;

Check failure on line 21 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\BaseResource must not depend on CodeIgniter\Model (RESTful on Model)

Check failure on line 21 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\ResourceController must not depend on CodeIgniter\Model (RESTful on Model) CodeIgniter\RESTful\BaseResource::24 -> CodeIgniter\Model::21
use Psr\Log\LoggerInterface;

abstract class BaseResource extends Controller
Expand All @@ -29,13 +30,13 @@
*/
protected $request;

/**

Check failure on line 33 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\BaseResource must not depend on CodeIgniter\Model (RESTful on Model)

Check failure on line 33 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\ResourceController must not depend on CodeIgniter\Model (RESTful on Model) CodeIgniter\RESTful\BaseResource::24 -> CodeIgniter\Model::33
* @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;

/**

Check failure on line 38 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\BaseResource must not depend on CodeIgniter\Model (RESTful on Model)

Check failure on line 38 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\ResourceController must not depend on CodeIgniter\Model (RESTful on Model) CodeIgniter\RESTful\BaseResource::24 -> CodeIgniter\Model::38
* @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 @@ -51,19 +52,19 @@
$this->setModel($this->modelName);
}

/**

Check failure on line 55 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\BaseResource must not depend on CodeIgniter\Model (RESTful on Model)

Check failure on line 55 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\BaseResource must not depend on CodeIgniter\Model (RESTful on Model)

Check failure on line 55 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\ResourceController must not depend on CodeIgniter\Model (RESTful on Model) CodeIgniter\RESTful\BaseResource::24 -> CodeIgniter\Model::55

Check failure on line 55 in system/RESTful/BaseResource.php

View workflow job for this annotation

GitHub Actions / Architectural Inspection

CodeIgniter\RESTful\ResourceController must not depend on CodeIgniter\Model (RESTful on Model) CodeIgniter\RESTful\BaseResource::24 -> CodeIgniter\Model::55
* 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