General::setValue()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 3
nc 2
nop 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Status Trait
6
 * @category    Ticaje
7
 * @package     Ticaje_Setting
8
 * @author      Hector Luis Barrientos <[email protected]>
9
 */
10
11
namespace Ticaje\Configuration\Traits;
12
13
use Magento\Framework\App\Config\ScopeConfigInterface;
14
use Magento\Store\Model\ScopeInterface;
15
use Magento\Store\Model\Store;
16
use Ticaje\Configuration\Setting\GeneralInterface;
0 ignored issues
show
Bug introduced by
The type Ticaje\Configuration\Setting\GeneralInterface 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...
17
18
/**
19
 * Trait General
20
 * @package Ticaje\Configuration\Traits
21
 * Classes using this trait must implement Ticaje\Configuration\Setting\GeneralInterface
22
 * @Disclaimer: This trait provides the general methods for operating with all configurations within General section of adminhtml/system.xml
23
 */
24
trait General
25
{
26
    protected $generalPath = 'general'; // Could be overridden by client classes
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function getGeneralConfig($field = null, $storeId = null): string
32
    {
33
        return $this->scopeConfig->getValue($this->getXmlGeneralPath($field), ScopeInterface::SCOPE_STORE, $storeId) ?: '';
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function setValue($field, $value, $storeId = null): GeneralInterface
40
    {
41
        $storeId = $storeId ?: Store::DEFAULT_STORE_ID;
42
        $scope = $storeId == Store::DEFAULT_STORE_ID ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : ScopeInterface::SCOPE_STORES;
43
        $this->resourceConfig->saveConfig($this->getXmlGeneralPath($field), $value, $scope, $storeId);
44
        return $this;
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function getXmlGeneralPath($field): string
51
    {
52
        $xmlPath = $this->getXmlBasePath() . '/' . $this->getGeneralPath();
0 ignored issues
show
Bug introduced by
It seems like getXmlBasePath() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $xmlPath = $this->/** @scrutinizer ignore-call */ getXmlBasePath() . '/' . $this->getGeneralPath();
Loading history...
53
        if ($field) {
54
            $xmlPath .= '/' . $field;
55
        }
56
        return $xmlPath;
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    public function getGeneralPath(): string
63
    {
64
        return $this->generalPath;
65
    }
66
}
67