From 5d94a2cb069df80ccf12efc4f3d27106e34341f3 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 18 Apr 2024 19:03:30 +0530 Subject: [PATCH 1/2] Wrap addPlugin() call in has() check. Cake 5.1 throws exception for duplicate plugin loading and this avoids exception if the TwigView plugin is already loaded from the application. --- src/BakePlugin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BakePlugin.php b/src/BakePlugin.php index 5cba4765..3aac3963 100644 --- a/src/BakePlugin.php +++ b/src/BakePlugin.php @@ -55,7 +55,9 @@ class BakePlugin extends BasePlugin */ public function bootstrap(PluginApplicationInterface $app): void { - $app->addPlugin('Cake/TwigView'); + if (!$app->getPlugins()->has('Cake/TwigView')) { + $app->addPlugin('Cake/TwigView'); + } } /** From c3cf5c0e4e101cba1da60843c84d5fde07b15286 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 2 Jul 2024 19:39:17 +0530 Subject: [PATCH 2/2] Address error reported by static analyzers --- .phive/phars.xml | 4 ++-- phpstan.neon | 3 ++- src/BakePlugin.php | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.phive/phars.xml b/.phive/phars.xml index 1f56b2bc..da575cba 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,5 @@ - - + + diff --git a/phpstan.neon b/phpstan.neon index a1af9249..32434594 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,8 +3,9 @@ includes: parameters: level: 6 - checkMissingIterableValueType: false paths: - src/ bootstrapFiles: - tests/bootstrap.php + ignoreErrors: + - identifier: missingType.iterableValue diff --git a/src/BakePlugin.php b/src/BakePlugin.php index 3aac3963..9e491904 100644 --- a/src/BakePlugin.php +++ b/src/BakePlugin.php @@ -23,6 +23,7 @@ use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Core\PluginApplicationInterface; +use Cake\Http\BaseApplication; use DirectoryIterator; use ReflectionClass; use ReflectionException; @@ -55,6 +56,8 @@ class BakePlugin extends BasePlugin */ public function bootstrap(PluginApplicationInterface $app): void { + assert($app instanceof BaseApplication); + if (!$app->getPlugins()->has('Cake/TwigView')) { $app->addPlugin('Cake/TwigView'); }