CmsSlotContentReader::getDocumentFragment()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 19
rs 9.9332
c 0
b 0
f 0
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\Reader\CmsSlotContent;
9
10
use Generated\Shared\Transfer\CmsSlotContentRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tContentRequestTransfer 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 Generated\Shared\Transfer\CmsSlotContentResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ContentResponseTransfer 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...
12
use SprykerEco\Client\Coremedia\CoremediaClientInterface;
13
use SprykerEco\Yves\Coremedia\ApiResponse\ApiResponsePreparatorInterface;
14
use SprykerEco\Yves\Coremedia\Mapper\ApiContextMapperInterface;
15
16
class CmsSlotContentReader implements CmsSlotContentReaderInterface
17
{
18
    /**
19
     * @var \SprykerEco\Client\Coremedia\CoremediaClientInterface
20
     */
21
    protected $coreMediaClient;
22
23
    /**
24
     * @var \SprykerEco\Yves\Coremedia\Mapper\ApiContextMapperInterface
25
     */
26
    protected $apiContextMapper;
27
28
    /**
29
     * @var \SprykerEco\Yves\Coremedia\ApiResponse\ApiResponsePreparatorInterface
30
     */
31
    protected $apiResponsePreparator;
32
33
    /**
34
     * @param \SprykerEco\Client\Coremedia\CoremediaClientInterface $coreMediaClient
35
     * @param \SprykerEco\Yves\Coremedia\Mapper\ApiContextMapperInterface $apiContextMapper
36
     * @param \SprykerEco\Yves\Coremedia\ApiResponse\ApiResponsePreparatorInterface $apiResponsePreparator
37
     */
38
    public function __construct(
39
        CoremediaClientInterface $coreMediaClient,
40
        ApiContextMapperInterface $apiContextMapper,
41
        ApiResponsePreparatorInterface $apiResponsePreparator
42
    ) {
43
        $this->coreMediaClient = $coreMediaClient;
44
        $this->apiContextMapper = $apiContextMapper;
45
        $this->apiResponsePreparator = $apiResponsePreparator;
46
    }
47
48
    /**
49
     * @param \Generated\Shared\Transfer\CmsSlotContentRequestTransfer $cmsSlotContentRequestTransfer
50
     *
51
     * @return \Generated\Shared\Transfer\CmsSlotContentResponseTransfer
52
     */
53
    public function getDocumentFragment(
54
        CmsSlotContentRequestTransfer $cmsSlotContentRequestTransfer
55
    ): CmsSlotContentResponseTransfer {
56
        $coreMediaFragmentRequestTransfer = $this->apiContextMapper->mapCmsSlotContentRequestToCoremediaFragmentRequest(
57
            $cmsSlotContentRequestTransfer
58
        );
59
        $coreMediaApiResponseTransfer = $this->coreMediaClient->getDocumentFragment($coreMediaFragmentRequestTransfer);
60
61
        if (!$coreMediaApiResponseTransfer->getIsSuccessful()) {
62
            return (new CmsSlotContentResponseTransfer())->setContent('');
63
        }
64
65
        $coreMediaApiResponseTransfer = $this->apiResponsePreparator->prepare(
66
            $coreMediaApiResponseTransfer,
67
            $coreMediaFragmentRequestTransfer->getLocale()
68
        );
69
70
        return $this->apiContextMapper
71
            ->mapCoremediaApiResponseTransferToCmsSlotContentResponseTransfer($coreMediaApiResponseTransfer);
72
    }
73
}
74