Completed
Push — master ( d24e87...3d32fe )
by Fabian
13s queued 10s
created

ConfigFixture::setForStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Core;
5
6
use Magento\Framework\App\Config\MutableScopeConfigInterface;
7
use Magento\Framework\App\Config\ScopeConfigInterface;
8
use Magento\Store\Api\StoreRepositoryInterface;
9
use Magento\Store\Model\ScopeInterface;
10
use Magento\TestFramework\Helper\Bootstrap;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class ConfigFixture
13
{
14
15
    /**
16
     * Sets configuration in default scope AND all stores, no matter what was configured previously
17
     *
18
     * @param string $path
19
     * @param mixed $value
20
     */
21 2
    public static function setGlobal(string $path, $value): void
22
    {
23 2
        self::scopeConfig()->setValue($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
24 2
        foreach (self::storeRepository()->getList() as $store) {
25 2
            self::scopeConfig()->setValue($path, $value, ScopeInterface::SCOPE_STORE, $store->getCode());
26
        }
27 2
    }
28
29
    /**
30
     * Sets configuration in store scope
31
     *
32
     * @param string $path
33
     * @param mixed $value
34
     * @param null $storeCode store code or NULL for current store
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $storeCode is correct as it would always require null to be passed?
Loading history...
35
     */
36 2
    public static function setForStore(string $path, $value, $storeCode = null) : void
37
    {
38 2
        self::scopeConfig()->setValue($path, $value, ScopeInterface::SCOPE_STORE, $storeCode);
39 2
    }
40
41 4
    private static function scopeConfig(): MutableScopeConfigInterface
42
    {
43 4
        return Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class);
44
    }
45
46 2
    private static function storeRepository(): StoreRepositoryInterface
47
    {
48 2
        return Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class);
49
    }
50
}
51