Passed
Push — master ( 4a1742...ff2740 )
by Alec
03:07 queued 34s
created

src/Spinner/Core/Spinner.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core;
6
7
use AlecRabbit\Spinner\Contract\IFrame;
8
use AlecRabbit\Spinner\Contract\IInterval;
9
use AlecRabbit\Spinner\Contract\IObserver;
10
use AlecRabbit\Spinner\Contract\ISubject;
11
use AlecRabbit\Spinner\Core\A\ASubject;
12
use AlecRabbit\Spinner\Core\Contract\ISpinner;
13
use AlecRabbit\Spinner\Core\Widget\Contract\IWidget;
14
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetComposite;
15
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetContext;
16
use AlecRabbit\Spinner\Exception\WidgetIsNotAComposite;
17
18
final class Spinner extends ASubject implements ISpinner
19
{
20
    public function __construct(
21
        private readonly IWidget $widget,
22
        ?IObserver $observer = null,
23
    ) {
24
        parent::__construct($observer);
25
        $this->widget->attach($this);
26
    }
27
28
    public function getFrame(?float $dt = null): IFrame
29
    {
30
        return $this->widget->getFrame($dt);
31
    }
32
33
    public function getInterval(): IInterval
34
    {
35
        return $this->widget->getInterval();
36
    }
37
38
    public function add(IWidgetContext $element): IWidgetContext
39
    {
40
        if ($this->widget instanceof IWidgetComposite) {
41
            return $this->widget->add($element);
0 ignored issues
show
The method add() does not exist on AlecRabbit\Spinner\Core\Widget\Contract\IWidget. It seems like you code against a sub-type of AlecRabbit\Spinner\Core\Widget\Contract\IWidget such as AlecRabbit\Spinner\Core\...ntract\IWidgetComposite or AlecRabbit\Spinner\Core\Widget\WidgetComposite. ( Ignorable by Annotation )

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

41
            return $this->widget->/** @scrutinizer ignore-call */ add($element);
Loading history...
42
        }
43
        throw new WidgetIsNotAComposite('Root widget is not a composite.');
44
    }
45
46
    public function remove(IWidgetContext $element): void
47
    {
48
        if ($this->widget instanceof IWidgetComposite) {
49
            $this->widget->remove($element);
0 ignored issues
show
The method remove() does not exist on AlecRabbit\Spinner\Core\Widget\Contract\IWidget. It seems like you code against a sub-type of AlecRabbit\Spinner\Core\Widget\Contract\IWidget such as AlecRabbit\Spinner\Core\...ntract\IWidgetComposite or AlecRabbit\Spinner\Core\Widget\WidgetComposite. ( Ignorable by Annotation )

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

49
            $this->widget->/** @scrutinizer ignore-call */ 
50
                           remove($element);
Loading history...
50
        }
51
    }
52
53
    public function update(ISubject $subject): void
54
    {
55
        if ($subject === $this->widget) {
56
            $this->notify();
57
        }
58
    }
59
}
60