CategoryUrlPlaceholderReplacementRenderer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFallbackPlaceholderReplacement() 0 3 1
A getPlaceholderReplacement() 0 15 2
A isApplicable() 0 4 2
A __construct() 0 6 1
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\Coremedia\ApiResponse\Renderer;
9
10
use Generated\Shared\Transfer\CoremediaPlaceholderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ediaPlaceholderTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToCategoryStorageClientInterface;
12
use SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToStoreClientInterface;
13
14
class CategoryUrlPlaceholderReplacementRenderer implements PlaceholderReplacementRendererInterface
15
{
16
    protected const PLACEHOLDER_OBJECT_TYPE = 'category';
17
    protected const PLACEHOLDER_RENDER_TYPE = 'url';
18
19
    /**
20
     * @var \SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToCategoryStorageClientInterface
21
     */
22
    protected $categoryStorageClient;
23
24
    /**
25
     * @var \SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToStoreClientInterface
26
     */
27
    protected $storeClient;
28
29
    /**
30
     * @param \SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToCategoryStorageClientInterface $categoryStorageClient
31
     * @param \SprykerEco\Yves\Coremedia\Dependency\Client\CoremediaToStoreClientInterface $storeClient
32
     */
33
    public function __construct(
34
        CoremediaToCategoryStorageClientInterface $categoryStorageClient,
35
        CoremediaToStoreClientInterface $storeClient
36
    ) {
37
        $this->categoryStorageClient = $categoryStorageClient;
38
        $this->storeClient = $storeClient;
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\CoremediaPlaceholderTransfer $coreMediaPlaceholderTransfer
43
     *
44
     * @return bool
45
     */
46
    public function isApplicable(CoremediaPlaceholderTransfer $coreMediaPlaceholderTransfer): bool
47
    {
48
        return $coreMediaPlaceholderTransfer->getObjectType() === static::PLACEHOLDER_OBJECT_TYPE &&
49
            $coreMediaPlaceholderTransfer->getRenderType() === static::PLACEHOLDER_RENDER_TYPE;
50
    }
51
52
    /**
53
     * @param \Generated\Shared\Transfer\CoremediaPlaceholderTransfer $coreMediaPlaceholderTransfer
54
     * @param string $locale
55
     *
56
     * @return string|null
57
     */
58
    public function getPlaceholderReplacement(
59
        CoremediaPlaceholderTransfer $coreMediaPlaceholderTransfer,
60
        string $locale
61
    ): ?string {
62
        if (!$coreMediaPlaceholderTransfer->getCategoryId()) {
63
            return null;
64
        }
65
66
        $categoryNodeStorageTransfer = $this->categoryStorageClient->getCategoryNodeById(
67
            (int)$coreMediaPlaceholderTransfer->getCategoryId(),
68
            $locale,
69
            $this->storeClient->getCurrentStore()->getName()
70
        );
71
72
        return $categoryNodeStorageTransfer->getUrl();
73
    }
74
75
    /**
76
     * @return string|null
77
     */
78
    public function getFallbackPlaceholderReplacement(): ?string
79
    {
80
        return '';
81
    }
82
}
83