From f9fc46447238a657a4860ac69c293a3de5b02a8a Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 18 Apr 2018 02:34:12 +0530 Subject: [PATCH] Fix errors reported by phpstan. --- .travis.yml | 15 ++++++++------- src/Model/Behavior/TrashBehavior.php | 8 +++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4de404..3bbeda9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,21 +19,23 @@ matrix: fast_finish: true include: - - php: 7.0 + - php: 7.1 env: PHPCS=1 DEFAULT=0 - - php: 7.0 + - php: 7.1 env: PHPSTAN=1 DEFAULT=0 - php: 5.6 env: PREFER_LOWEST=1 before_script: - - if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $TRAVIS_PHP_VERSION != 7.1 ]]; then phpenv config-rm xdebug.ini; fi - if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction ; fi - if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi + - if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi + - if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi @@ -41,15 +43,14 @@ before_script: - if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi script: - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 5 src; fi after_success: - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi notifications: email: false diff --git a/src/Model/Behavior/TrashBehavior.php b/src/Model/Behavior/TrashBehavior.php index 1441156..1b18550 100644 --- a/src/Model/Behavior/TrashBehavior.php +++ b/src/Model/Behavior/TrashBehavior.php @@ -106,7 +106,7 @@ public function beforeDelete(Event $event, EntityInterface $entity, ArrayObject $event->stopPropagation(); /** @var \Cake\ORM\Table $table */ - $table = $event->subject(); + $table = $event->getSubject(); $table->dispatchEvent('Model.afterDelete', [ 'entity' => $entity, 'options' => $options, @@ -127,8 +127,10 @@ public function trash(EntityInterface $entity, array $options = []) { $primaryKey = (array)$this->_table->getPrimaryKey(); - if (!$entity->has($primaryKey)) { - throw new RuntimeException(); + foreach ($primaryKey as $field) { + if (!$entity->has($field)) { + throw new RuntimeException(); + } } foreach ($this->_table->associations() as $association) {