PlaceholderResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 24 3
A __construct() 0 8 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\Resolver;
9
10
use Generated\Shared\Transfer\CoremediaApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ediaApiResponseTransfer 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\ApiResponse\Parser\PlaceholderParserInterface;
12
use SprykerEco\Yves\Coremedia\ApiResponse\PostProcessor\PlaceholderPostProcessorInterface;
13
use SprykerEco\Yves\Coremedia\ApiResponse\Replacer\PlaceholderReplacerInterface;
14
15
class PlaceholderResolver implements ApiResponseResolverInterface
16
{
17
    /**
18
     * @var \SprykerEco\Yves\Coremedia\ApiResponse\Parser\PlaceholderParserInterface
19
     */
20
    protected $placeholderParser;
21
22
    /**
23
     * @var \SprykerEco\Yves\Coremedia\ApiResponse\PostProcessor\PlaceholderPostProcessorInterface
24
     */
25
    protected $placeholderPostProcessor;
26
27
    /**
28
     * @var \SprykerEco\Yves\Coremedia\ApiResponse\Replacer\PlaceholderReplacerInterface
29
     */
30
    protected $placeholderReplacer;
31
32
    /**
33
     * @param \SprykerEco\Yves\Coremedia\ApiResponse\Parser\PlaceholderParserInterface $placeholderParser
34
     * @param \SprykerEco\Yves\Coremedia\ApiResponse\PostProcessor\PlaceholderPostProcessorInterface $placeholderPostProcessor
35
     * @param \SprykerEco\Yves\Coremedia\ApiResponse\Replacer\PlaceholderReplacerInterface $placeholderReplacer
36
     */
37
    public function __construct(
38
        PlaceholderParserInterface $placeholderParser,
39
        PlaceholderPostProcessorInterface $placeholderPostProcessor,
40
        PlaceholderReplacerInterface $placeholderReplacer
41
    ) {
42
        $this->placeholderParser = $placeholderParser;
43
        $this->placeholderPostProcessor = $placeholderPostProcessor;
44
        $this->placeholderReplacer = $placeholderReplacer;
45
    }
46
47
    /**
48
     * @param \Generated\Shared\Transfer\CoremediaApiResponseTransfer $coreMediaApiResponseTransfer
49
     * @param string $locale
50
     *
51
     * @return \Generated\Shared\Transfer\CoremediaApiResponseTransfer
52
     */
53
    public function resolve(
54
        CoremediaApiResponseTransfer $coreMediaApiResponseTransfer,
55
        string $locale
56
    ): CoremediaApiResponseTransfer {
57
        $coreMediaPlaceholderTransfers = $this->placeholderParser->parse($coreMediaApiResponseTransfer->getData());
58
59
        if (!$coreMediaPlaceholderTransfers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $coreMediaPlaceholderTransfers of type Generated\Shared\Transfe...iaPlaceholderTransfer[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
60
            return $coreMediaApiResponseTransfer;
61
        }
62
63
        foreach ($coreMediaPlaceholderTransfers as $coreMediaPlaceholderTransfer) {
64
            $coreMediaPlaceholderTransfer = $this->placeholderPostProcessor->addReplacement(
65
                $coreMediaPlaceholderTransfer,
66
                $locale
67
            );
68
            $coreMediaApiResponseTransfer->setData(
69
                $this->placeholderReplacer->replace(
70
                    $coreMediaApiResponseTransfer->getData(),
71
                    $coreMediaPlaceholderTransfer
72
                )
73
            );
74
        }
75
76
        return $coreMediaApiResponseTransfer;
77
    }
78
}
79