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; |
|
|
|
|
11
|
|
|
use SprykerEco\Service\CrefoPay\CrefoPayConfig; |
12
|
|
|
use SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface; |
13
|
|
|
|
14
|
|
|
class CrefoPayUserIdGenerator implements CrefoPayUserIdGeneratorInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
protected const GUEST_USER_ID_LENGTH = 6; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected const USER_ID_B2B_SUFFIX = '-B2B'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected const USER_ID_B2C_SUFFIX = '-B2C'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \SprykerEco\Service\CrefoPay\CrefoPayConfig |
33
|
|
|
*/ |
34
|
|
|
protected CrefoPayConfig $crefoPayConfig; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface |
38
|
|
|
*/ |
39
|
|
|
protected CrefoPayToUtilTextServiceInterface $utilTextService; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \SprykerEco\Service\CrefoPay\CrefoPayConfig $crefoPayConfig |
43
|
|
|
* @param \SprykerEco\Service\CrefoPay\Dependency\Service\CrefoPayToUtilTextServiceInterface $utilTextService |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
CrefoPayConfig $crefoPayConfig, |
47
|
|
|
CrefoPayToUtilTextServiceInterface $utilTextService |
48
|
|
|
) { |
49
|
|
|
$this->crefoPayConfig = $crefoPayConfig; |
50
|
|
|
$this->utilTextService = $utilTextService; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function generateUserId(QuoteTransfer $quoteTransfer): string |
59
|
|
|
{ |
60
|
|
|
$userIdBase = $quoteTransfer->getCustomerReference(); |
61
|
|
|
|
62
|
|
|
if ($userIdBase === null || $quoteTransfer->getCustomerOrFail()->getIsGuest()) { |
63
|
|
|
$userIdBase = $this->createGuestUserIdBase(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$userTypeSuffix = $this->getUserTypeSuffix(); |
67
|
|
|
$maxUserIdLength = $this->crefoPayConfig->getCrefoPayUserIdMaxLength() - strlen($userTypeSuffix); |
68
|
|
|
|
69
|
|
|
if ($maxUserIdLength < strlen($userIdBase)) { |
70
|
|
|
$userIdBase = substr($userIdBase, 0, $maxUserIdLength); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return sprintf('%s%s', $userIdBase, $userTypeSuffix); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function createGuestUserIdBase(): string |
80
|
|
|
{ |
81
|
|
|
return sprintf( |
82
|
|
|
'GUEST-USER-%s', |
83
|
|
|
$this->utilTextService->generateRandomString(static::GUEST_USER_ID_LENGTH), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
protected function getUserTypeSuffix(): string |
91
|
|
|
{ |
92
|
|
|
return $this->crefoPayConfig->isBusinessToBusiness() ? static::USER_ID_B2B_SUFFIX : static::USER_ID_B2C_SUFFIX; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths