Passed
Pull Request — master (#13)
by
unknown
14:18 queued 10:00
created

generateCrefoPayOrderId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Service\CrefoPay\Generator;
9
10
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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\Service\CrefoPay\CrefoPayConfig;
12
use SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface;
13
14
class CrefoPayUniqueIdGenerator implements CrefoPayUniqueIdGeneratorInterface
15
{
16
    /**
17
     * @var \SprykerEco\Service\CrefoPay\CrefoPayConfig
18
     */
19
    protected $crefoPayConfig;
20
21
    /**
22
     * @var \SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface
23
     */
24
    protected $utilTextService;
25
26
    /**
27
     * @param \SprykerEco\Service\CrefoPay\CrefoPayConfig $crefoPayConfig
28
     * @param \SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface $utilTextService
29
     */
30
    public function __construct(
31
        CrefoPayConfig $crefoPayConfig,
32
        CrefoPayToUtilTextServiceInterface $utilTextService
33
    ) {
34
        $this->crefoPayConfig = $crefoPayConfig;
35
        $this->utilTextService = $utilTextService;
36
    }
37
38
    /**
39
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
40
     *
41
     * @return string
42
     */
43
    public function generateCrefoPayOrderId(QuoteTransfer $quoteTransfer): string
44
    {
45
        $crefoPayOrderIdLength = $this->crefoPayConfig->getCrefoPayOrderIdLength();
46
        $randomStringLength = $crefoPayOrderIdLength - strlen($quoteTransfer->getCustomerReference()) - 1;
47
48
        return sprintf(
49
            '%s-%s',
50
            $this->utilTextService->generateRandomString($randomStringLength),
51
            $quoteTransfer->getCustomerReference(),
52
        );
53
    }
54
}
55