Skip to content

Commit

Permalink
refactor: Fix phpstan codeigniter.modelArgumentInstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Jan 9, 2025
1 parent 42a00ff commit 02138c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
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 @@ -30,12 +31,12 @@ abstract class BaseResource extends Controller
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 @@ -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

0 comments on commit 02138c8

Please sign in to comment.