From 5a2a5c8d9cc29fd2f09de3bfa237902192c47c1d Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Wed, 14 Sep 2022 20:41:47 +0200 Subject: [PATCH 1/8] Implement CacheLifetimeBehaviourInterface in ArticleBridge --- Document/Structure/ArticleBridge.php | 7 ++- .../CacheLifetimeBehaviourInterface.php | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Document/Structure/CacheLifetimeBehaviourInterface.php diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 57460a0c..3616f2b5 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -16,7 +16,7 @@ /** * Own structure bridge for articles. */ -class ArticleBridge extends StructureBridge +class ArticleBridge extends StructureBridge implements CacheLifetimeBehaviourInterface { /** * @var string @@ -91,4 +91,9 @@ public function setWebspaceKey($webspace) { $this->webspaceKey = $webspace; } + + public function getCacheLifeTime() + { + return $this->structure->getCacheLifetime(); + } } diff --git a/Document/Structure/CacheLifetimeBehaviourInterface.php b/Document/Structure/CacheLifetimeBehaviourInterface.php new file mode 100644 index 00000000..0fa6687a --- /dev/null +++ b/Document/Structure/CacheLifetimeBehaviourInterface.php @@ -0,0 +1,56 @@ + Date: Wed, 14 Sep 2022 20:49:24 +0200 Subject: [PATCH 2/8] Fix phpstan issue --- Document/Structure/ArticleBridge.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 3616f2b5..9e46f4f5 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -94,6 +94,9 @@ public function setWebspaceKey($webspace) public function getCacheLifeTime() { - return $this->structure->getCacheLifetime(); + /** @var array{type: string, value: string} $cacheLifetime */ + $cacheLifetime = $this->structure->getCacheLifetime(); + + return $cacheLifetime; } } From 39671f2c75f038c8618c060ee9b1fee6b4c9b6e2 Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 11:16:49 +0200 Subject: [PATCH 3/8] Rename CacheLifetimeBehaviourInterface to RoutableStructureInterface --- Document/Structure/ArticleBridge.php | 23 +++++++----- ...ace.php => RoutableStructureInterface.php} | 36 ++++++++++++++++--- 2 files changed, 46 insertions(+), 13 deletions(-) rename Document/Structure/{CacheLifetimeBehaviourInterface.php => RoutableStructureInterface.php} (56%) diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 9e46f4f5..d17efa9b 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -16,7 +16,7 @@ /** * Own structure bridge for articles. */ -class ArticleBridge extends StructureBridge implements CacheLifetimeBehaviourInterface +class ArticleBridge extends StructureBridge implements RoutableStructureInterface { /** * @var string @@ -33,6 +33,19 @@ public function getView(): string return $this->structure->getView(); } + public function getController() + { + return $this->structure->getController(); + } + + public function getCacheLifeTime() + { + /** @var array{type: string, value: string} $cacheLifetime */ + $cacheLifetime = $this->structure->getCacheLifetime(); + + return $cacheLifetime; + } + public function getUuid() { // is set for structure loaded with document from document-manager @@ -91,12 +104,4 @@ public function setWebspaceKey($webspace) { $this->webspaceKey = $webspace; } - - public function getCacheLifeTime() - { - /** @var array{type: string, value: string} $cacheLifetime */ - $cacheLifetime = $this->structure->getCacheLifetime(); - - return $cacheLifetime; - } } diff --git a/Document/Structure/CacheLifetimeBehaviourInterface.php b/Document/Structure/RoutableStructureInterface.php similarity index 56% rename from Document/Structure/CacheLifetimeBehaviourInterface.php rename to Document/Structure/RoutableStructureInterface.php index 0fa6687a..debfd464 100644 --- a/Document/Structure/CacheLifetimeBehaviourInterface.php +++ b/Document/Structure/RoutableStructureInterface.php @@ -13,17 +13,31 @@ namespace Sulu\Bundle\ArticleBundle\Document\Structure; -use Sulu\Component\Content\Compat\CacheLifetimeBehaviourInterface as SuluCacheLifetimeBehaviourInterface; +use Sulu\Component\Content\Compat\RoutableStructureInterface as SuluRoutableStructureInterface; -if (\interface_exists(SuluCacheLifetimeBehaviourInterface::class)) { +if (\interface_exists(SuluRoutableStructureInterface::class)) { /** * @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version, * where this interface exists * * @internal */ - interface CacheLifetimeBehaviourInterface extends SuluCacheLifetimeBehaviourInterface + interface RoutableStructureInterface extends SuluRoutableStructureInterface { + /** + * twig template of template definition. + * + * @return string + */ + public function getView(); + + /** + * controller which renders the twig template. + * + * @return string + */ + public function getController(); + /** * cacheLifeTime of template definition. * @@ -41,8 +55,22 @@ public function getCacheLifeTime(); * * @internal */ - interface CacheLifetimeBehaviourInterface + interface RoutableStructureInterface { + /** + * twig template of template definition. + * + * @return string + */ + public function getView(); + + /** + * controller which renders the twig template. + * + * @return string + */ + public function getController(); + /** * cacheLifeTime of template definition. * From f0462fb7b1d434f74c3fbf6c3bdf637e5cd7f091 Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 14:19:33 +0200 Subject: [PATCH 4/8] Update Document/Structure/RoutableStructureInterface.php Co-authored-by: Alexander Schranz --- .../Structure/RoutableStructureInterface.php | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/Document/Structure/RoutableStructureInterface.php b/Document/Structure/RoutableStructureInterface.php index debfd464..bb9c95ba 100644 --- a/Document/Structure/RoutableStructureInterface.php +++ b/Document/Structure/RoutableStructureInterface.php @@ -24,29 +24,6 @@ */ interface RoutableStructureInterface extends SuluRoutableStructureInterface { - /** - * twig template of template definition. - * - * @return string - */ - public function getView(); - - /** - * controller which renders the twig template. - * - * @return string - */ - public function getController(); - - /** - * cacheLifeTime of template definition. - * - * @return array{ - * type: string, - * value: string, - * } - */ - public function getCacheLifeTime(); } } else { /** From 40cc73b873d573caec04460eea8f3a3fb4a343af Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 14:28:49 +0200 Subject: [PATCH 5/8] Fix phpstan --- Document/Structure/ArticleBridge.php | 16 ++++++++++++++-- phpstan-baseline.neon | 5 ----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index d17efa9b..94cd8500 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -30,14 +30,26 @@ class ArticleBridge extends StructureBridge implements RoutableStructureInterfac public function getView(): string { - return $this->structure->getView(); + /** @var string $view */ + $view = $this->structure->getView(); + + return $view; } + /** + * @return string + */ public function getController() { - return $this->structure->getController(); + /** @var string $controller */ + $controller = $this->structure->getController(); + + return $controller; } + /** + * @return array{type: string, value: string} + */ public function getCacheLifeTime() { /** @var array{type: string, value: string} $cacheLifetime */ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 615cb429..445f8afa 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1525,11 +1525,6 @@ parameters: count: 1 path: Document/Structure/ArticleBridge.php - - - message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Document\\\\Structure\\\\ArticleBridge\\:\\:getView\\(\\) should return string but returns string\\|null\\.$#" - count: 1 - path: Document/Structure/ArticleBridge.php - - message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Document\\\\Structure\\\\ArticleBridge\\:\\:setUuid\\(\\) has no return type specified\\.$#" count: 1 From bc497de7916b6952b132d8b10583197632d3b8c7 Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 14:45:36 +0200 Subject: [PATCH 6/8] Apply suggestions from code review --- Document/Structure/ArticleBridge.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 94cd8500..3ade6bdd 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -36,10 +36,7 @@ public function getView(): string return $view; } - /** - * @return string - */ - public function getController() + public function getController(): string { /** @var string $controller */ $controller = $this->structure->getController(); @@ -50,7 +47,7 @@ public function getController() /** * @return array{type: string, value: string} */ - public function getCacheLifeTime() + public function getCacheLifeTime(): array { /** @var array{type: string, value: string} $cacheLifetime */ $cacheLifetime = $this->structure->getCacheLifetime(); From 71f4d0cccd5065738695842053c1afc9a308c09f Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 15:14:41 +0200 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Alexander Schranz --- Document/Structure/ArticleBridge.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 3ade6bdd..5c980742 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -30,18 +30,14 @@ class ArticleBridge extends StructureBridge implements RoutableStructureInterfac public function getView(): string { - /** @var string $view */ - $view = $this->structure->getView(); - - return $view; + /** @var string */ + return $this->structure->getView();; } public function getController(): string { - /** @var string $controller */ - $controller = $this->structure->getController(); - - return $controller; + /** @var string */ + return $this->structure->getController(); } /** @@ -49,10 +45,8 @@ public function getController(): string */ public function getCacheLifeTime(): array { - /** @var array{type: string, value: string} $cacheLifetime */ - $cacheLifetime = $this->structure->getCacheLifetime(); - - return $cacheLifetime; + /** @var array{type: string, value: string} */ + return $this->structure->getCacheLifetime(); } public function getUuid() From 4935506e26b8b3e92aa5245904a7b4636c76f785 Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 20 Sep 2022 21:52:38 +0200 Subject: [PATCH 8/8] Fix php-cs --- .php-cs-fixer.dist.php | 3 +++ Document/Structure/ArticleBridge.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ae691020..78c1c466 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -31,6 +31,9 @@ 'phpdoc_types_order' => false, 'single_line_throw' => false, 'single_line_comment_spacing' => false, + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line'], + ], ]) ->setFinder($finder); diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 5c980742..3b5a10b2 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -31,7 +31,7 @@ class ArticleBridge extends StructureBridge implements RoutableStructureInterfac public function getView(): string { /** @var string */ - return $this->structure->getView();; + return $this->structure->getView(); } public function getController(): string