Passed
Push — master ( d1e743...c9dff9 )
by Anton
18:40 queued 10:26
created

CodeBucketConfig::getPathInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerConfig;
9
10
use Spryker\Shared\Kernel\CodeBucket\Config\AbstractCodeBucketConfig;
11
use Spryker\Shared\Kernel\Store;
12
use Symfony\Component\HttpFoundation\Request;
13
14
class CodeBucketConfig extends AbstractCodeBucketConfig
15
{
16
    /**
17
     * @return array<string>
18
     */
19
    public function getCodeBuckets(): array
20
    {
21
        if ($this->isAcpDevOn()) {
22
            return Store::getInstance()->getAllowedStores();
23
        }
24
25
        return [
26
            'EU',
27
            'US',
28
            'DE',
29
            'AT',
30
        ];
31
    }
32
33
    /**
34
     * @deprecated This method implementation will be removed when environment configs are cleaned up.
35
     *
36
     * @return string
37
     */
38
    public function getDefaultCodeBucket(): string
39
    {
40
        if ($this->isAcpDevOn()) {
41
            return APPLICATION_STORE;
42
        }
43
44
        $codeBuckets = $this->getCodeBuckets();
45
46
        $parts = explode('/', $this->getPathInfo());
47
        if (isset($parts[1]) && in_array($parts[1], $codeBuckets, true)) {
48
            return $parts[1];
49
        }
50
51
        return defined('APPLICATION_REGION') ? APPLICATION_REGION : reset($codeBuckets);
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    protected function isAcpDevOn(): bool
58
    {
59
        return APPLICATION_ENV === 'docker.acp.dev';
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    protected function getPathInfo(): string
66
    {
67
        $requestFromGlobals = Request::createFromGlobals();
68
69
        return $requestFromGlobals->getPathInfo();
70
    }
71
}
72