|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Manager\Strategy\Badge; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
6
|
|
|
use VideoGamesRecords\CoreBundle\Contracts\BadgeInterface; |
|
7
|
|
|
|
|
8
|
|
|
abstract class AbstractBadgeStrategy implements BadgeInterface |
|
9
|
|
|
{ |
|
10
|
|
|
private TranslatorInterface $translator; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @param TranslatorInterface $translator |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct(TranslatorInterface $translator) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->translator = $translator; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @return TranslatorInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function getTranslator(): TranslatorInterface |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->translator; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param Contribution $rule |
|
31
|
|
|
* |
|
32
|
|
|
* @return string |
|
33
|
|
|
* |
|
34
|
|
|
* @throws \UnexpectedValueException |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function extractRuleProductType(Contribution $rule): string |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$ruleProductType = $rule->getProductType(); |
|
39
|
|
|
|
|
40
|
|
|
if (!array_key_exists($ruleProductType, $this->productTypeMapping)) { |
|
|
|
|
|
|
41
|
|
|
throw new \UnexpectedValueException(sprintf('Could not extract product type from %s', $ruleProductType)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$category = $this->productTypeMapping[$ruleProductType]; |
|
45
|
|
|
|
|
46
|
|
|
if (!array_key_exists($category, $this->productCategoryMapping)) { |
|
|
|
|
|
|
47
|
|
|
throw new \UnexpectedValueException(sprintf('Could not get type for category %s', $category)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $this->productCategoryMapping[$category]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param int $companyId |
|
55
|
|
|
* @param bool $isInternal |
|
56
|
|
|
* @param string $ruleType |
|
57
|
|
|
* @param string $campaignType |
|
58
|
|
|
* @param string $productType |
|
59
|
|
|
* |
|
60
|
|
|
* @return int |
|
61
|
|
|
* |
|
62
|
|
|
* @throws DuplicateGlobalRuleException |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function insertBaseRule( |
|
65
|
|
|
int $companyId, |
|
66
|
|
|
bool $isInternal, |
|
67
|
|
|
string $ruleType, |
|
68
|
|
|
string $campaignType = self::TYPE_ALL, |
|
|
|
|
|
|
69
|
|
|
string $productType = self::TYPE_ALL |
|
70
|
|
|
): int |
|
71
|
|
|
{ |
|
72
|
|
|
try { |
|
73
|
|
|
|
|
74
|
|
|
$this->connection->executeStatement( |
|
|
|
|
|
|
75
|
|
|
'INSERT INTO rule_company |
|
76
|
|
|
(company_id, campaign_type, product_type, is_internal, rule_type) |
|
77
|
|
|
VALUES (:companyId, :campaignType, :productType, :isInternal, :ruleType)', |
|
78
|
|
|
[ |
|
79
|
|
|
'companyId' => $companyId, |
|
80
|
|
|
'campaignType' => $campaignType, |
|
81
|
|
|
'productType' => $productType, |
|
82
|
|
|
'isInternal' => $isInternal, |
|
83
|
|
|
'ruleType' => $ruleType, |
|
84
|
|
|
], |
|
85
|
|
|
[ |
|
86
|
|
|
'isInternal' => 'boolean', |
|
87
|
|
|
] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
} catch (UniqueConstraintViolationException $e) { |
|
|
|
|
|
|
91
|
|
|
throw new DuplicateGlobalRuleException(sprintf('Same rule already exists for company %d', $companyId)); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return (int) $this->connection->lastInsertId(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param int $companyId |
|
99
|
|
|
* @param string $campaignType |
|
100
|
|
|
* @param string $productType |
|
101
|
|
|
* @param string|null $ruleType |
|
102
|
|
|
* |
|
103
|
|
|
* @return int |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function getRuleId(int $companyId, string $campaignType, string $productType, ?string $ruleType): int |
|
106
|
|
|
{ |
|
107
|
|
|
$sql = 'SELECT |
|
108
|
|
|
id |
|
109
|
|
|
FROM rule_company |
|
110
|
|
|
WHERE |
|
111
|
|
|
company_id = :companyId |
|
112
|
|
|
AND campaign_type = :campaignType |
|
113
|
|
|
AND product_type = :productType |
|
114
|
|
|
'; |
|
115
|
|
|
|
|
116
|
|
|
$params = [ |
|
117
|
|
|
'companyId' => $companyId, |
|
118
|
|
|
'campaignType' => $campaignType, |
|
119
|
|
|
'productType' => $productType, |
|
120
|
|
|
]; |
|
121
|
|
|
|
|
122
|
|
|
if ($ruleType !== null) { |
|
123
|
|
|
$sql .= ' AND rule_type = :ruleType'; |
|
124
|
|
|
$params['ruleType'] = $ruleType; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return (int) $this->connection->executeQuery($sql, $params)->fetchOne(); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param int $companyId |
|
132
|
|
|
* |
|
133
|
|
|
* @return bool |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function companyHasGlobalRule(int $companyId, string $ruleType = null): bool |
|
136
|
|
|
{ |
|
137
|
|
|
$ruleId = $this->getRuleId($companyId, self::TYPE_ALL, self::TYPE_ALL, $ruleType); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
return $ruleId > 0; |
|
140
|
|
|
} |
|
141
|
|
|
} |
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