PunchoutCatalogsReader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 14
c 3
b 0
f 0
dl 0
loc 53
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findConnectionById() 0 3 1
A findConnectionByIdWithPassword() 0 14 2
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\Zed\PunchoutCatalogs\Business\Reader;
9
10
use Generated\Shared\Transfer\PunchoutCatalogConnectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...talogConnectionTransfer 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\Zed\PunchoutCatalogs\Dependency\Facade\PunchoutCatalogsToVaultFacadeInterface;
12
use SprykerEco\Zed\PunchoutCatalogs\Persistence\PunchoutCatalogsRepositoryInterface;
13
14
class PunchoutCatalogsReader implements PunchoutCatalogsReaderInterface
15
{
16
    protected const CATALOG_CONNECTION_PASSWORD_VAULT_DATA_TYPE = 'pwg_punchout_catalog_connection.password';
17
18
    /**
19
     * @var \SprykerEco\Zed\PunchoutCatalogs\Persistence\PunchoutCatalogsRepositoryInterface
20
     */
21
    protected $punchoutCatalogsRepository;
22
23
    /**
24
     * @var \SprykerEco\Zed\PunchoutCatalogs\Dependency\Facade\PunchoutCatalogsToVaultFacadeInterface
25
     */
26
    protected $vaultFacade;
27
28
    /**
29
     * @param \SprykerEco\Zed\PunchoutCatalogs\Persistence\PunchoutCatalogsRepositoryInterface $punchoutCatalogsRepository
30
     * @param \SprykerEco\Zed\PunchoutCatalogs\Dependency\Facade\PunchoutCatalogsToVaultFacadeInterface $vaultFacade
31
     */
32
    public function __construct(PunchoutCatalogsRepositoryInterface $punchoutCatalogsRepository, PunchoutCatalogsToVaultFacadeInterface $vaultFacade)
33
    {
34
        $this->punchoutCatalogsRepository = $punchoutCatalogsRepository;
35
        $this->vaultFacade = $vaultFacade;
36
    }
37
38
    /**
39
     * @param int $idConnection
40
     *
41
     * @return \Generated\Shared\Transfer\PunchoutCatalogConnectionTransfer|null
42
     */
43
    public function findConnectionById(int $idConnection): ?PunchoutCatalogConnectionTransfer
44
    {
45
        return $this->punchoutCatalogsRepository->findConnectionById($idConnection);
46
    }
47
48
    /**
49
     * @param int $idConnection
50
     *
51
     * @return \Generated\Shared\Transfer\PunchoutCatalogConnectionTransfer|null
52
     */
53
    public function findConnectionByIdWithPassword(int $idConnection): ?PunchoutCatalogConnectionTransfer
54
    {
55
        $punchoutCatalogConnectionTransfer = $this->punchoutCatalogsRepository->findConnectionById($idConnection);
56
57
        if (!$punchoutCatalogConnectionTransfer) {
58
            return $punchoutCatalogConnectionTransfer;
59
        }
60
61
        $password = $this->vaultFacade->retrieve(
62
            static::CATALOG_CONNECTION_PASSWORD_VAULT_DATA_TYPE,
63
            (string)$punchoutCatalogConnectionTransfer->getIdPunchoutCatalogConnection()
64
        );
65
66
        return $punchoutCatalogConnectionTransfer->setPassword($password);
67
    }
68
}
69