From 527f3107aa4ab93c3fbfb5f56852fe9eafac9743 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 12 Aug 2017 01:16:09 +0530 Subject: [PATCH 1/2] Bump up phpstan level. --- .travis.yml | 3 +-- phpstan.neon | 9 +++++++++ src/Action/Bulk/DeleteAction.php | 2 +- src/Action/Bulk/SetValueAction.php | 2 +- src/Action/Bulk/ToggleAction.php | 2 +- src/Controller/Component/CrudComponent.php | 4 ++-- src/Event/Subject.php | 2 -- src/Listener/ApiPaginationListener.php | 4 ++-- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e3d5ff9a..09b145d0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,11 +43,10 @@ script: - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 1 src; fi + - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 3 src; fi after_success: - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi notifications: email: false - diff --git a/phpstan.neon b/phpstan.neon index a972ee0ae..35c2a9711 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,12 @@ parameters: excludes_analyse: - */src/TestSuite/* + universalObjectCratesClasses: + - Crud\Event\Subject + ignoreErrors: + - '#Access to an undefined property Exception::\$response#' + - '#Access to an undefined property Cake\\Controller\\Controller::\$dispatchComponents#' + - '#Access to an undefined property Cake\\Controller\\Controller::\$Crud#' + - '#Call to an undefined method Crud\\Action\\BaseAction::view\(\)#' + - '#Call to an undefined method Crud\\Action\\BaseAction::viewVar\(\)#' + - '#Call to an undefined method Crud\\Action\\BaseAction::findMethod\(\)#' diff --git a/src/Action/Bulk/DeleteAction.php b/src/Action/Bulk/DeleteAction.php index e712581e3..8ef6abf26 100644 --- a/src/Action/Bulk/DeleteAction.php +++ b/src/Action/Bulk/DeleteAction.php @@ -45,6 +45,6 @@ protected function _bulk(Query $query = null) $statement = $query->execute(); $statement->closeCursor(); - return $statement->rowCount(); + return (bool)$statement->rowCount(); } } diff --git a/src/Action/Bulk/SetValueAction.php b/src/Action/Bulk/SetValueAction.php index dff31b622..89e34e7d3 100644 --- a/src/Action/Bulk/SetValueAction.php +++ b/src/Action/Bulk/SetValueAction.php @@ -65,6 +65,6 @@ protected function _bulk(Query $query = null) $statement = $query->execute(); $statement->closeCursor(); - return $statement->rowCount(); + return (bool)$statement->rowCount(); } } diff --git a/src/Action/Bulk/ToggleAction.php b/src/Action/Bulk/ToggleAction.php index a6181084f..4da0d0470 100644 --- a/src/Action/Bulk/ToggleAction.php +++ b/src/Action/Bulk/ToggleAction.php @@ -65,6 +65,6 @@ protected function _bulk(Query $query = null) $statement = $query->execute(); $statement->closeCursor(); - return $statement->rowCount(); + return (bool)$statement->rowCount(); } } diff --git a/src/Controller/Component/CrudComponent.php b/src/Controller/Component/CrudComponent.php index b4275728d..d4b99971c 100644 --- a/src/Controller/Component/CrudComponent.php +++ b/src/Controller/Component/CrudComponent.php @@ -180,7 +180,7 @@ public function initialize(array $config) { parent::initialize($config); - $this->_action = $this->_controller->request->action; + $this->_action = $this->_controller->request->param('action'); $this->_request = $this->_controller->request; if (!isset($this->_controller->dispatchComponents)) { @@ -600,7 +600,7 @@ public function table() * Returns new entity * * @param array $data Data - * @return \Cake\ORM\Entity + * @return \Cake\Datasource\EntityInterface */ public function entity(array $data = []) { diff --git a/src/Event/Subject.php b/src/Event/Subject.php index 63809779f..5d22d4884 100644 --- a/src/Event/Subject.php +++ b/src/Event/Subject.php @@ -8,8 +8,6 @@ * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt - * - * @property string $action */ class Subject { diff --git a/src/Listener/ApiPaginationListener.php b/src/Listener/ApiPaginationListener.php index c39616dac..2ca8f66e3 100644 --- a/src/Listener/ApiPaginationListener.php +++ b/src/Listener/ApiPaginationListener.php @@ -19,12 +19,12 @@ class ApiPaginationListener extends BaseListener * * We attach at priority 10 so normal bound events can run before us * - * @return array|void + * @return array|null */ public function implementedEvents() { if (!$this->_checkRequestType('api')) { - return; + return null; } return [ From 09ef0e5b48f0c386f9582d32e4c56f497072333c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 12 Aug 2017 01:32:45 +0530 Subject: [PATCH 2/2] Fix test --- tests/TestCase/Controller/Component/CrudComponentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Controller/Component/CrudComponentTest.php b/tests/TestCase/Controller/Component/CrudComponentTest.php index 13af5cb16..0b14dfd4e 100644 --- a/tests/TestCase/Controller/Component/CrudComponentTest.php +++ b/tests/TestCase/Controller/Component/CrudComponentTest.php @@ -395,7 +395,7 @@ public function testIsActionMappedYes() $result = $this->Crud->isActionMapped('index'); $this->assertTrue($result); - $this->controller->request->action = 'edit'; + $this->controller->request->param('action', 'edit'); $this->Crud->initialize([]); $result = $this->Crud->isActionMapped(); $this->assertTrue($result);