WidgetPositionDataProvider::setStatus()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
4
namespace eXpansion\Framework\Core\DataProviders;
5
6
use eXpansion\Framework\Core\Helpers\CompatibleFetcher;
7
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
8
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface;
9
use eXpansion\Framework\Core\Storage\GameDataStorage;
10
use oliverde8\AssociativeArraySimplified\AssociativeArray;
11
12
13
/**
14
 * Class WidgetPositionProvider
15
 *
16
 * @package eXpansion\Framework\Core\DataProviders;
17
 * @author  oliver de Cramer <[email protected]>
18
 */
19
class WidgetPositionDataProvider extends AbstractDataProvider implements StatusAwarePluginInterface
20
{
21
    /** @var CompatibleFetcher */
22
    protected $compatibleFetcher;
23
24
    /** @var GameDataStorage */
25
    protected $gameStorage;
26
27
    /** @var array  */
28
    protected $widgetPositions;
29
30
    /**
31
     * WidgetPositionDataProvider constructor.
32
     *
33
     * @param CompatibleFetcher $compatibleFetcher
34
     * @param GameDataStorage   $gameStorage
35
     * @param array             $widgetPositions
36
     */
37
    public function __construct(CompatibleFetcher $compatibleFetcher, GameDataStorage $gameStorage, array $widgetPositions)
38
    {
39
        $this->compatibleFetcher = $compatibleFetcher;
40
        $this->gameStorage = $gameStorage;
41
        $this->widgetPositions = $widgetPositions;
42
    }
43
44
45
    /**
46
     * Set the status of the plugin
47
     *
48
     * @param boolean $status
49
     *
50
     * @return null
51
     */
52
    public function setStatus($status)
53
    {
54
        $title = $this->gameStorage->getTitle();
55
        $mode = $this->gameStorage->getGameModeCode();
56
        $script = $this->gameStorage->getGameInfos()->scriptName;
57
58
        foreach ($this->plugins as $pluginId => $plugin) {
59
            if (isset($this->widgetPositions[$pluginId])) {
60
                $options = $this->compatibleFetcher->getCompatibleData($this->widgetPositions[$pluginId], $title, $mode, $script);
61
62
                if (!is_null($options)) {
63
                    /** @var WidgetFactory $plugin */
64
                    $plugin->updateOptions($options['posX'], $options['posY'], AssociativeArray::getFromKey($options, 'options', []));
65
                }
66
            }
67
        }
68
    }
69
}
70