Completed
Pull Request — master (#254)
by
unknown
03:30
created

BestRecordsWidgetFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 7
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\WidgetBestRecords\Plugins\Gui;
4
5
use eXpansion\Bundle\LocalRecords\Model\Record;
6
use eXpansion\Framework\Core\Helpers\Time;
7
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
8
use eXpansion\Framework\Core\Model\Gui\Widget;
9
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
10
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
11
use eXpansion\Framework\Gui\Components\uiLabel;
12
13
class BestRecordsWidgetFactory extends WidgetFactory
14
{
15
    /** @var string */
16
    private $authorName;
17
    /** @var int */
18
    private $authorTime;
19
20
    /** @var UiLabel */
21
    private $lblDediNick;
22
    /** @var UiLabel */
23
    private $lblDediTime;
24
25
    /** @var UiLabel */
26
    private $lblAuthorNick;
27
    /** @var UiLabel */
28
    private $lblAuthorTime;
29
30
    /** @var UiLabel */
31
    private $lblLocalNick;
32
    /** @var UiLabel */
33
    private $lblLocalTime;
34
    /**
35
     * @var Time
36
     */
37
    private $time;
38
39
40
    /***
41
     * MenuFactory constructor.
42
     *
43
     * @param                      $name
44
     * @param                      $sizeX
45
     * @param                      $sizeY
46
     * @param null                 $posX
47
     * @param null                 $posY
48
     * @param WidgetFactoryContext $context
49
     * @param Time                 $time
50
     */
51
    public function __construct(
52
        $name,
53
        $sizeX,
54
        $sizeY,
55
        $posX,
56
        $posY,
57
        WidgetFactoryContext $context,
58
        Time $time
59
60
    ) {
61
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
62
        $this->time = $time;
63
    }
64
65
    /**
66
     * @param int $authorTime
67
     */
68
    public function setAuthorTime($author, int $authorTime)
69
    {
70
        $this->authorName = $author;
71
        $this->authorTime = $authorTime;
72
    }
73
74
    /**
75
     * @param Widget|ManialinkInterface $manialink
76
     */
77
    protected function createContent(ManialinkInterface $manialink)
78
    {
79
        parent::createContent($manialink);
80
81
        $line = $this->uiFactory->createLayoutLine(0, 0, [], 0.5);
82
        $lbl = $this->createLabel("Author", "0017")->setSize(15, 4);
83
        $line->addChild($lbl);
84
85
        $this->lblAuthorNick = $this->createLabel("n/a", "0023")->setSize(33, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('n/a', '0023')->setSize(33, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblAuthorNick.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
        $line->addChild($this->lblAuthorNick);
87
88
        $this->lblAuthorTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('-:--...'0015')->setSize(12, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblAuthorTime.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
89
90
        $line->addChild($this->lblAuthorTime);
91
        $manialink->addChild($line);
92
93
        $line2 = $this->uiFactory->createLayoutLine(0, -4.45, [], 0.5);
94
95
        $lbl = $this->createLabel("Record", "0017")->setSize(15, 4);
96
        $line2->addChild($lbl);
97
98
        $this->lblLocalNick = $this->createLabel("n/a", "0023")->setSize(33, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('n/a', '0023')->setSize(33, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblLocalNick.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
99
        $line2->addChild($this->lblLocalNick);
100
101
        $this->lblLocalTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('-:--...'0015')->setSize(12, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblLocalTime.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
102
        $line2->addChild($this->lblLocalTime);
103
        $manialink->addChild($line2);
104
105
        $line3 = $this->uiFactory->createLayoutLine(0, -9.0, [], 0.5);
106
107
        $lbl = $this->createLabel("Dedimania", "0017")->setSize(15, 4);
108
        $line3->addChild($lbl);
109
110
        $this->lblDediNick = $this->createLabel("n/a", "0023")->setSize(33, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('n/a', '0023')->setSize(33, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblDediNick.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
111
        $line3->addChild($this->lblDediNick);
112
113
        $this->lblDediTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createLabel('-:--...'0015')->setSize(12, 4) of type object<FML\Controls\Label> is incompatible with the declared type object<eXpansion\Bundle\...ds\Plugins\Gui\UiLabel> of property $lblDediTime.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
114
        $line3->addChild($this->lblDediTime);
115
        $manialink->addChild($line3);
116
    }
117
118
    private function createLabel($text, $color)
119
    {
120
        return $this->uiFactory->createLabel($text, UiLabel::TYPE_NORMAL)->setTranslate(false)
121
            ->setAlign("left", "center2")->setTextSize(1)->setScriptEvents(true)
122
            ->setAreaColor($color)->setAreaFocusColor($color)->setTextColor("eff")->setTextPrefix(" ");
123
    }
124
125
126
    public function setLocalRecord($record)
127
    {
128
        if ($record instanceof Record) {
0 ignored issues
show
Bug introduced by
The class eXpansion\Bundle\LocalRecords\Model\Record does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
129
            try {
130
                $this->lblLocalNick->setText($record->getPlayer()->getNicknameStripped());
131
                $this->lblLocalTime->setText($this->time->timeToText($record->getScore(), true));
132
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
133
134
            }
135
        } else {
136
            $this->lblLocalNick->setText("");
137
            $this->lblLocalTime->setText("-:--.---");
138
        }
139
    }
140
141
    protected function updateContent(ManialinkInterface $manialink)
142
    {
143
        $this->lblAuthorTime->setText($this->time->timeToText($this->authorTime, true));
144
        $this->lblAuthorNick->setText($this->authorName);
145
    }
146
147
148
}
149