Issues (38)

src/Service/SettingsService.php (1 issue)

1
<?php
2
3
namespace App\Service;
4
5
use Psr\Log\LoggerInterface;
6
use Symfony\Component\HttpFoundation\Session\Session;
7
use Symfony\Component\HttpFoundation\Session\SessionInterface;
8
9
/**
10
 * Class SettingsService
11
 * @package App\Service
12
 */
13
class SettingsService
14
{
15
    /**
16
     * @var string[] Default Settings
17
     */
18
    protected $defaultSettings = [
19
        'settings-customer-currency' => 'GBP',
20
        'settings-customer-locale' => 'en_GB',
21
        'settings-customer-id' => 'customer_id_1',
22
        'settings-customer-name' => 'John',
23
        'settings-customer-family-name' => 'Doe',
24
        'settings-customer-email' => '[email protected]',
25
        'settings-customer-street' => '1 Westminster',
26
        'settings-customer-city' => 'London',
27
        'settings-customer-province' => 'London',
28
        'settings-customer-zip-code' => 'SW1A0AA',
29
        'settings-customer-country' => 'GB',
30
        'settings-merchant-maid' => null,
31
        'settings-merchant-name' => 'PlayGround Shop',
32
        'settings-merchant-email' => '[email protected]',
33
        'settings-merchant-street' => '2 Great George St, Westminster, London SW1P 3AD, Reino Unido',
34
        'settings-merchant-city' => 'London',
35
        'settings-merchant-province' => 'London',
36
        'settings-merchant-zip-code' => 'SW1P3AD',
37
        'settings-merchant-country' => 'GB',
38
        'settings-merchant-negative-testing' => null,
39
        'settings-item-name' => 'Make me proud! TEE (XXL)',
40
        'settings-item-price' => '31',
41
        'settings-item-shipping' => '5',
42
        'settings-item-sku' => 'TEE-MMP-XXL',
43
        'settings-item-description' => 'A tee that will make you proud and good looking, in an XXL size',
44
        'settings-item-purchase-description' => 'Tee sale: Make me proud! (XXL) SPECIAL OFFER',
45
        'settings-item-tax-name' => 'VAT',
46
        'settings-item-tax-value' => '21',
47
    ];
48
49
    /**
50
     * @var Session
51
     */
52
    public $session;
53
54
    /**
55
     * @var LoggerInterface
56
     */
57
    private $logger;
58
59
    /**
60
     * SettingsService constructor.
61
     * @param SessionInterface $session
62
     * @param LoggerInterface $logger
63
     * @param string $maid
64
     */
65
    public function __construct(SessionInterface  $session, LoggerInterface $logger, string $maid)
66
    {
67
        $this->session = $session;
0 ignored issues
show
Documentation Bug introduced by
$session is of type Symfony\Component\HttpFo...ession\SessionInterface, but the property $session was declared to be of type Symfony\Component\HttpFoundation\Session\Session. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
68
        $this->logger = $logger;
69
        $this->defaultSettings['settings-merchant-maid'] = $maid;
70
    }
71
72
    /**
73
     * @param array $settings
74
     */
75
    public function storeSettings(array $settings): void
76
    {
77
        $this->session->set('settings', $settings);
78
    }
79
80
    /**
81
     * Clear settings to Defaults
82
     */
83
    public function clearSettings(): void
84
    {
85
        $this->session->set('settings', $this->defaultSettings);
86
    }
87
88
    /**
89
     * Check if settings are initialized
90
     * @return bool
91
     */
92
    public function isInitialized(): bool
93
    {
94
        $settings = $this->session->get('settings');
95
        if (is_array($settings)) {
96
            return true;
97
        }
98
99
        return false;
100
    }
101
102
    /**
103
     * @param string $settingKey
104
     *
105
     * @return string
106
     */
107
    public function getSetting(string $settingKey): ?string
108
    {
109
        $settings = $this->session->get('settings');
110
        if (array_key_exists($settingKey, $settings)) {
111
            return $settings[$settingKey];
112
        }
113
114
        return null;
115
    }
116
}
117