From c85cbc612a8482cf076bca9828ed957a902a01f8 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 22 Sep 2022 19:12:47 +0530 Subject: [PATCH 1/3] Update as per updates to ORM --- src/Model/Behavior/TimedBehavior.php | 20 ++++++++++---------- src/Model/Table/PanelsTable.php | 8 ++++---- src/Model/Table/RequestsTable.php | 14 ++++++-------- tests/TestCase/Panel/VariablesPanelTest.php | 2 +- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Model/Behavior/TimedBehavior.php b/src/Model/Behavior/TimedBehavior.php index 70dd6cc5..21ab8f0b 100644 --- a/src/Model/Behavior/TimedBehavior.php +++ b/src/Model/Behavior/TimedBehavior.php @@ -15,9 +15,9 @@ */ namespace DebugKit\Model\Behavior; -use Cake\Event\Event; +use Cake\Event\EventInterface; use Cake\ORM\Behavior; -use Cake\ORM\Query; +use Cake\ORM\Query\SelectQuery; use DebugKit\DebugTimer; /** @@ -28,11 +28,11 @@ class TimedBehavior extends Behavior /** * beforeFind, starts a timer for a find operation. * - * @param \Cake\Event\Event $event The beforeFind event - * @param \Cake\ORM\Query $query Query - * @return \Cake\ORM\Query + * @param \Cake\Event\EventInterface $event The beforeFind event + * @param \Cake\ORM\Query\SelectQuery $query SelectQuery + * @return \Cake\ORM\Query\SelectQuery */ - public function beforeFind(Event $event, Query $query): Query + public function beforeFind(EventInterface $event, SelectQuery $query): SelectQuery { $alias = $event->getSubject()->getAlias(); DebugTimer::start($alias . '_find', $alias . '->find()'); @@ -47,10 +47,10 @@ public function beforeFind(Event $event, Query $query): Query /** * beforeSave, starts a time before a save is initiated. * - * @param \Cake\Event\Event $event The beforeSave event + * @param \Cake\Event\EventInterface $event The beforeSave event * @return void */ - public function beforeSave(Event $event): void + public function beforeSave(EventInterface $event): void { $alias = $event->getSubject()->getAlias(); DebugTimer::start($alias . '_save', $alias . '->save()'); @@ -59,10 +59,10 @@ public function beforeSave(Event $event): void /** * afterSave, stop the timer started from a save. * - * @param \Cake\Event\Event $event The afterSave event + * @param \Cake\Event\EventInterface $event The afterSave event * @return void */ - public function afterSave(Event $event): void + public function afterSave(EventInterface $event): void { $alias = $event->getSubject()->getAlias(); DebugTimer::stop($alias . '_save'); diff --git a/src/Model/Table/PanelsTable.php b/src/Model/Table/PanelsTable.php index f6068494..402a0a19 100644 --- a/src/Model/Table/PanelsTable.php +++ b/src/Model/Table/PanelsTable.php @@ -14,7 +14,7 @@ */ namespace DebugKit\Model\Table; -use Cake\ORM\Query; +use Cake\ORM\Query\SelectQuery; use Cake\ORM\Table; use RuntimeException; @@ -50,12 +50,12 @@ public function initialize(array $config): void /** * Find panels by requestid * - * @param \Cake\ORM\Query $query The query + * @param \Cake\ORM\Query\SelectQuery $query The query * @param array $options The options to use. - * @return \Cake\ORM\Query The query. + * @return \Cake\ORM\Query\SelectQuery The query. * @throws \RuntimeException */ - public function findByRequest(Query $query, array $options): Query + public function findByRequest(SelectQuery $query, array $options): SelectQuery { if (empty($options['requestId'])) { throw new RuntimeException(__d('debug_kit', 'Missing request id in {0}.', 'findByRequest()')); diff --git a/src/Model/Table/RequestsTable.php b/src/Model/Table/RequestsTable.php index a280c180..5d610d9c 100644 --- a/src/Model/Table/RequestsTable.php +++ b/src/Model/Table/RequestsTable.php @@ -17,7 +17,7 @@ use Cake\Core\Configure; use Cake\Database\Driver\Sqlite; use Cake\Log\Log; -use Cake\ORM\Query; +use Cake\ORM\Query\SelectQuery; use Cake\ORM\Table; use PDOException; @@ -69,11 +69,11 @@ public static function defaultConnectionName(): string /** * Finder method to get recent requests as a simple array * - * @param \Cake\ORM\Query $query The query + * @param \Cake\ORM\Query\SelectQuery $query The query * @param array $options The options - * @return \Cake\ORM\Query The query. + * @return \Cake\ORM\Query\SelectQuery The query. */ - public function findRecent(Query $query, array $options): Query + public function findRecent(SelectQuery $query, array $options): SelectQuery { return $query->order(['Requests.requested_at' => 'DESC']) ->limit(10); @@ -118,14 +118,12 @@ public function gc(): void return; } - $query = $this->Panels->query() - ->delete() + $query = $this->Panels->deleteQuery() ->where(['request_id NOT IN' => $noPurge]); $statement = $query->execute(); $statement->closeCursor(); - $query = $this->query() - ->delete() + $query = $this->deleteQuery() ->where(['id NOT IN' => $noPurge]); $statement = $query->execute(); diff --git a/tests/TestCase/Panel/VariablesPanelTest.php b/tests/TestCase/Panel/VariablesPanelTest.php index a2c07b0a..0c0f21d7 100644 --- a/tests/TestCase/Panel/VariablesPanelTest.php +++ b/tests/TestCase/Panel/VariablesPanelTest.php @@ -66,7 +66,7 @@ public function testShutdown() $result = $requests->find()->all(); $unbufferedQuery = $requests->find('all'); $unbufferedQuery->toArray(); //toArray call would normally happen somewhere in View, usually implicitly - $update = $requests->query()->update(); + $update = $requests->updateQuery(); $debugInfoException = $requests->query()->contain('NonExistentAssociation'); $unserializable = new stdClass(); From 9a3bd23ce9edb857253422090ada743ddd140e29 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 22 Sep 2022 19:29:52 +0530 Subject: [PATCH 2/3] Fix CS error --- src/DebugSql.php | 2 +- tests/test_app/Stub/DebugSqlStub.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DebugSql.php b/src/DebugSql.php index fd7bc0ca..6b73996e 100644 --- a/src/DebugSql.php +++ b/src/DebugSql.php @@ -174,7 +174,7 @@ public static function sqld( * * @return bool */ - protected static function isCli() + protected static function isCli(): bool { return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg'; } diff --git a/tests/test_app/Stub/DebugSqlStub.php b/tests/test_app/Stub/DebugSqlStub.php index c4e7ae96..1dfc4c11 100644 --- a/tests/test_app/Stub/DebugSqlStub.php +++ b/tests/test_app/Stub/DebugSqlStub.php @@ -9,7 +9,7 @@ class DebugSqlStub extends DebugSql { public static $isCli = true; - protected static function isCli() + protected static function isCli(): bool { return static::$isCli; } From 3ab01b6a3112506cb4c85b81bff3f968eec289b5 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 22 Sep 2022 19:37:15 +0530 Subject: [PATCH 3/3] Fix psalm error --- src/Panel/PanelRegistry.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Panel/PanelRegistry.php b/src/Panel/PanelRegistry.php index c19d34f2..5c635ade 100644 --- a/src/Panel/PanelRegistry.php +++ b/src/Panel/PanelRegistry.php @@ -24,6 +24,8 @@ /** * Registry object for panels. + * + * @extends \Cake\Core\ObjectRegistry<\DebugKit\DebugPanel> */ class PanelRegistry extends ObjectRegistry implements EventDispatcherInterface { @@ -73,11 +75,10 @@ protected function _throwMissingClassError(string $class, ?string $plugin): void * * Part of the template method for Cake\Utility\ObjectRegistry::load() * - * @param string $class The classname to create. + * @param \DebugKit\DebugPanel|class-string<\DebugKit\DebugPanel> $class The classname to create. * @param string $alias The alias of the panel. * @param array $config An array of config to use for the panel. * @return \DebugKit\DebugPanel The constructed panel class. - * @psalm-param class-string<\DebugKit\DebugPanel> $class */ protected function _create(object|string $class, string $alias, array $config): DebugPanel {