diff --git a/lib/Limitation/DataTransformer/UDWBasedValueModelTransformer.php b/lib/Limitation/DataTransformer/UDWBasedValueModelTransformer.php index d190054c9..b330822e2 100644 --- a/lib/Limitation/DataTransformer/UDWBasedValueModelTransformer.php +++ b/lib/Limitation/DataTransformer/UDWBasedValueModelTransformer.php @@ -24,9 +24,6 @@ class UDWBasedValueModelTransformer implements DataTransformerInterface /** @var \eZ\Publish\API\Repository\LocationService */ private $locationService; - /** - * @param \eZ\Publish\API\Repository\LocationService $locationService - */ public function __construct(LocationService $locationService) { $this->locationService = $locationService; @@ -37,7 +34,7 @@ public function __construct(LocationService $locationService) */ public function transform($value) { - if (!is_array($value)) { + if (!\is_array($value)) { return null; } @@ -47,7 +44,9 @@ public function transform($value) $this->extractLocationIdFromPath($path) ); }, $value); - } catch (NotFoundException | UnauthorizedException $e) { + } catch (NotFoundException $e) { + return null; + } catch (UnauthorizedException $e) { throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); } } @@ -57,7 +56,7 @@ public function transform($value) */ public function reverseTransform($value) { - if (!is_array($value)) { + if (!\is_array($value)) { return null; } @@ -66,10 +65,6 @@ public function reverseTransform($value) /** * Extracts and returns an item id from a path, e.g. /1/2/58/ => 58. - * - * @param string $path - * - * @return string|null */ private function extractLocationIdFromPath(string $path): ?string { diff --git a/lib/Limitation/Templating/LimitationBlockRenderer.php b/lib/Limitation/Templating/LimitationBlockRenderer.php index 9aa80e467..4402b04de 100644 --- a/lib/Limitation/Templating/LimitationBlockRenderer.php +++ b/lib/Limitation/Templating/LimitationBlockRenderer.php @@ -7,6 +7,7 @@ */ namespace EzSystems\RepositoryForms\Limitation\Templating; +use eZ\Publish\API\Repository\Exceptions\NotFoundException; use eZ\Publish\API\Repository\Values\User\Limitation; use EzSystems\RepositoryForms\Limitation\Exception\MissingLimitationBlockException; use EzSystems\RepositoryForms\Limitation\Exception\ValueMapperNotFoundException; @@ -36,9 +37,6 @@ class LimitationBlockRenderer implements LimitationBlockRendererInterface /** * LimitationRenderer constructor. - * - * @param LimitationValueMapperRegistryInterface $valueMapperRegistry - * @param Twig_Environment $twig */ public function __construct(LimitationValueMapperRegistryInterface $valueMapperRegistry, Twig_Environment $twig) { @@ -51,7 +49,7 @@ public function renderLimitationValue(Limitation $limitation, array $parameters try { $blockName = $this->getValueBlockName($limitation); $parameters = $this->getValueBlockParameters($limitation, $parameters); - } catch (ValueMapperNotFoundException $exception) { + } catch (ValueMapperNotFoundException | NotFoundException $exception) { $blockName = self::LIMITATION_VALUE_BLOCK_NAME_FALLBACK; $parameters = $this->getValueFallbackBlockParameters($limitation, $parameters); } @@ -82,7 +80,6 @@ public function setLimitationValueResources(array $resources) /** * Generates value block name based on Limitation. * - * @param Limitation $limitation * @return string */ protected function getValueBlockName(Limitation $limitation) @@ -95,12 +92,12 @@ protected function getValueBlockName(Limitation $limitation) * * @param string $blockName * @param string|Twig_Template $localTemplate - * @return null|\Twig_TemplateWrapper + * @return \Twig_TemplateWrapper|null */ protected function findTemplateWithBlock($blockName, $localTemplate = null) { if ($localTemplate !== null) { - if (is_string($localTemplate)) { + if (\is_string($localTemplate)) { $localTemplate = $this->twig->load($localTemplate); } @@ -110,7 +107,7 @@ protected function findTemplateWithBlock($blockName, $localTemplate = null) } foreach ($this->limitationValueResources as &$template) { - if (is_string($template)) { + if (\is_string($template)) { // Load the template if it is necessary $template = $this->twig->load($template); } @@ -126,8 +123,6 @@ protected function findTemplateWithBlock($blockName, $localTemplate = null) /** * Get parameters passed as context of value block render. * - * @param Limitation $limitation - * @param array $parameters * @return array */ protected function getValueBlockParameters(Limitation $limitation, array $parameters) @@ -147,8 +142,6 @@ protected function getValueBlockParameters(Limitation $limitation, array $parame /** * Get parameters passed as context of value fallback block. * - * @param Limitation $limitation - * @param array $parameters * @return array */ protected function getValueFallbackBlockParameters(Limitation $limitation, array $parameters) diff --git a/tests/RepositoryForms/Limitation/DataTransformer/UDWBasedValueModelTransformerTest.php b/tests/RepositoryForms/Limitation/DataTransformer/UDWBasedValueModelTransformerTest.php index 0f04f7a1c..fc82e17d1 100644 --- a/tests/RepositoryForms/Limitation/DataTransformer/UDWBasedValueModelTransformerTest.php +++ b/tests/RepositoryForms/Limitation/DataTransformer/UDWBasedValueModelTransformerTest.php @@ -65,29 +65,28 @@ public function dataProviderForTransform(): array ]; } - /** - * @dataProvider dataProviderForTransformThrowsTransformationFailedException - */ - public function testTransformThrowsTransformationFailedException(string $exceptionClass) + public function testTransformThrowsTransformationFailedException(): void { $this->expectException(TransformationFailedException::class); $this->locationService - ->expects($this->any()) ->method('loadLocation') ->willThrowException( - $this->createMock($exceptionClass) + $this->createMock(UnauthorizedException::class) ); $this->transformer->transform(['/1/2/54']); } - public function dataProviderForTransformThrowsTransformationFailedException(): array + public function testTransformWithDeletedLocation(): void { - return [ - [NotFoundException::class], - [UnauthorizedException::class], - ]; + $this->locationService + ->method('loadLocation') + ->willThrowException( + $this->createMock(NotFoundException::class) + ); + + self::assertNull($this->transformer->transform(['/1/2/54'])); } /**