Passed
Push — master ( f5f62a...783e97 )
by Christian
12:34 queued 10s
created

PromotionCodesLoader::generateCodeFixed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Promotion\Util;
4
5
use Doctrine\DBAL\Connection;
6
use Shopware\Core\Framework\Uuid\Uuid;
7
8
/**
9
 * @deprecated tag:v6.4.0.0 - Use PromotionCodeService instead
10
 */
11
class PromotionCodesLoader
12
{
13
    /**
14
     * @var Connection
15
     */
16
    private $connection;
17
18
    public function __construct(Connection $connection)
19
    {
20
        $this->connection = $connection;
21
    }
22
23
    /**
24
     * @throws \Shopware\Core\Framework\Uuid\Exception\InvalidUuidException
25
     */
26
    public function loadIndividualCodes(string $promotionId): array
27
    {
28
        $qb = $this->connection->createQueryBuilder();
29
30
        $qb->select('code');
31
        $qb->from('promotion_individual_code');
32
        $qb->where($qb->expr()->eq('promotion_id', ':id'));
33
        $qb->setParameter(':id', Uuid::fromHexToBytes($promotionId));
34
35
        /** @var array|bool $result */
36
        $result = $qb->execute()->fetchAll(\PDO::FETCH_COLUMN);
37
38
        if ($result !== (array) $result) {
39
            return [];
40
        }
41
42
        return $result;
43
    }
44
}
45