Passed
Push — trunk ( f797a9...e92141 )
by Christian
22:24 queued 10:00
created

SeedingThemePathBuilder::saveSeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Theme;
4
5
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
6
use Shopware\Core\System\SystemConfig\SystemConfigService;
7
8
/**
9
 * @package storefront
10
 */
11
class SeedingThemePathBuilder extends AbstractThemePathBuilder
12
{
13
    private const SYSTEM_CONFIG_KEY = 'storefront.themeSeed';
14
15
    /**
16
     * @internal
17
     */
18
    public function __construct(
19
        private readonly SystemConfigService $systemConfigService,
20
    ) {
21
    }
22
23
    public function assemblePath(string $salesChannelId, string $themeId): string
24
    {
25
        return $this->generateNewPath($salesChannelId, $themeId, $this->getSeed($salesChannelId));
26
    }
27
28
    public function generateNewPath(string $salesChannelId, string $themeId, string $seed): string
29
    {
30
        return md5($themeId . $salesChannelId . $seed);
31
    }
32
33
    public function saveSeed(string $salesChannelId, string $themeId, string $seed): void
34
    {
35
        $this->systemConfigService->set(self::SYSTEM_CONFIG_KEY, $seed, $salesChannelId);
36
    }
37
38
    public function getDecorated(): AbstractThemePathBuilder
39
    {
40
        throw new DecorationPatternException(self::class);
41
    }
42
43
    private function getSeed(string $salesChannelId): string
44
    {
45
        /** @var string|null $seed */
46
        $seed = $this->systemConfigService->get(self::SYSTEM_CONFIG_KEY, $salesChannelId);
47
48
        if (!$seed) {
49
            return '';
50
        }
51
52
        return $seed;
53
    }
54
}
55