From 8879734ea2382aaaccf9ce33bcef5df412b15394 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 16 Nov 2021 15:30:53 +0100 Subject: [PATCH] fix: SA: Fix "...does not call parent constructor... and ...Access to an undefined property..." rules. SA stands for Static Analysis. --- phpstan-baseline.neon | 5 -- phpstan-critical.neon | 5 -- .../CRUD/Routing/CRUDRoutesLoader.php | 71 ++++++------------- 3 files changed, 21 insertions(+), 60 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index eaa4dc3b2..9d9a5affd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -35,11 +35,6 @@ parameters: count: 2 path: src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php - - - message: "#^Chill\\\\MainBundle\\\\CRUD\\\\Routing\\\\CRUDRoutesLoader\\:\\:__construct\\(\\) does not call parent constructor from Symfony\\\\Component\\\\Config\\\\Loader\\\\Loader\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php - - message: "#^Cannot unset offset '_token' on array\\{formatter\\: mixed, export\\: mixed, centers\\: mixed, alias\\: string\\}\\.$#" count: 1 diff --git a/phpstan-critical.neon b/phpstan-critical.neon index f7389d8d7..cb0ac38ce 100644 --- a/phpstan-critical.neon +++ b/phpstan-critical.neon @@ -100,11 +100,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\CRUD\\\\Routing\\\\CRUDRoutesLoader\\:\\:\\$apiConfig\\.$#" - count: 2 - path: src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:tempOutput\\(\\)\\.$#" count: 1 diff --git a/src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php b/src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php index 36aadb8b7..85ef4c66c 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php +++ b/src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php @@ -1,22 +1,6 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + +declare(strict_types=1); namespace Chill\MainBundle\CRUD\Routing; @@ -27,22 +11,13 @@ use Symfony\Component\HttpFoundation\Request; use Chill\MainBundle\CRUD\Controller\ApiController; use Chill\MainBundle\CRUD\Controller\CRUDController; -/** - * Class CRUDRoutesLoader - * Load the route for CRUD - * - * @package Chill\MainBundle\CRUD\Routing - */ class CRUDRoutesLoader extends Loader { protected array $crudConfig = []; protected array $apiCrudConfig = []; - - /** - * @var bool - */ - private $isLoaded = false; + + private bool $isLoaded = false; private const ALL_SINGLE_METHODS = [ Request::METHOD_GET, @@ -52,19 +27,15 @@ class CRUDRoutesLoader extends Loader ]; private const ALL_INDEX_METHODS = [ Request::METHOD_GET, Request::METHOD_HEAD ]; - - /** - * CRUDRoutesLoader constructor. - * - * @param $crudConfig the config from cruds - * @param $apicrudConfig the config from api_crud - */ - public function __construct(array $crudConfig, array $apiConfig) + + public function __construct(array $crudConfig, array $apiCrudConfig) { $this->crudConfig = $crudConfig; - $this->apiConfig = $apiConfig; + $this->apiCrudConfig = $apiCrudConfig; + + parent::__construct(); } - + /** * @param mixed $resource * @param null $type @@ -74,7 +45,7 @@ class CRUDRoutesLoader extends Loader { return 'CRUD' === $type; } - + /** * Load routes for CRUD and CRUD Api */ @@ -85,17 +56,17 @@ class CRUDRoutesLoader extends Loader } $collection = new RouteCollection(); - + foreach ($this->crudConfig as $crudConfig) { $collection->addCollection($this->loadCrudConfig($crudConfig)); } - foreach ($this->apiConfig as $crudConfig) { + foreach ($this->apiCrudConfig as $crudConfig) { $collection->addCollection($this->loadApi($crudConfig)); } return $collection; } - + /** * Load routes for CRUD (without api) * @@ -112,7 +83,7 @@ class CRUDRoutesLoader extends Loader $defaults = [ '_controller' => $controller.':'.($action['controller_action'] ?? $name) ]; - + if ($name === 'index') { $path = "{_locale}".$crudConfig['base_path']; $route = new Route($path, $defaults); @@ -126,10 +97,10 @@ class CRUDRoutesLoader extends Loader ]; $route = new Route($path, $defaults, $requirements); } - + $collection->add('chill_crud_'.$crudConfig['name'].'_'.$name, $route); } - + return $collection; } @@ -186,14 +157,14 @@ class CRUDRoutesLoader extends Loader if (count($methods) === 0) { throw new \RuntimeException("The api configuration named \"{$crudConfig['name']}\", action \"{$name}\", ". "does not have any allowed methods. You should remove this action from the config ". - "or allow, at least, one method"); + "or allow, at least, one method"); } if ('_entity' === $name && \in_array(Request::METHOD_POST, $methods)) { unset($methods[\array_search(Request::METHOD_POST, $methods)]); - $entityPostRoute = $this->createEntityPostRoute($name, $crudConfig, $action, + $entityPostRoute = $this->createEntityPostRoute($name, $crudConfig, $action, $controller); - $collection->add("chill_api_single_{$crudConfig['name']}_{$name}_create", + $collection->add("chill_api_single_{$crudConfig['name']}_{$name}_create", $entityPostRoute); } @@ -205,7 +176,7 @@ class CRUDRoutesLoader extends Loader $route = new Route($path, $defaults, $requirements); $route->setMethods($methods); - + $collection->add('chill_api_single_'.$crudConfig['name'].'_'.$name, $route); }