Completed
Branch develop (69883f)
by Benjamin
04:05
created

AbstractSkill::setTranslationDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Obblm\Core\Helper\Rule\Skill;
4
5
use Obblm\Core\Contracts\SkillInterface;
6
use Obblm\Core\Helper\Optionable;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
abstract class AbstractSkill extends Optionable implements SkillInterface
10
{
11
    /** @var string */
12
    private $key;
13
    /** @var string */
14
    private $name;
15
    /** @var string */
16
    private $translationDomain;
17
    /** @var string */
18
    private $type;
19
    /** @var string */
20
    private $typeName;
21
    /** @var string */
22
    private $description;
23
24
    protected function hydrateWithOptions()
25
    {
26
        $this->key = $this->options['key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['key'] ?? false can also be of type false. However, the property $key is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
27
        $this->name = $this->options['name'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['name'] ?? false can also be of type false. However, the property $name is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
28
        $this->translationDomain = $this->options['translation_domain'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['translation_domain'] ?? false can also be of type false. However, the property $translationDomain is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
29
        $this->type = $this->options['type'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['type'] ?? false can also be of type false. However, the property $type is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
30
        $this->typeName = $this->options['type_name'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['type_name'] ?? false can also be of type false. However, the property $typeName is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
31
        $this->description = $this->options['description'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->options['description'] ?? false can also be of type false. However, the property $description is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32
    }
33
34
    public function getKey(): string
35
    {
36
        return $this->key;
37
    }
38
39
    public function getName(): string
40
    {
41
        return $this->name;
42
    }
43
44
    public function getTranslationDomain(): string
45
    {
46
        return $this->translationDomain;
47
    }
48
49
    public function getType(): string
50
    {
51
        return $this->type;
52
    }
53
54
    public function getTypeName(): string
55
    {
56
        return $this->typeName;
57
    }
58
59
    public function getDescription(): string
60
    {
61
        return $this->description;
62
    }
63
64
    public function setKey(string $key): self
65
    {
66
        $this->key = $key;
67
        return $this;
68
    }
69
70
    public function setName(string $name): self
71
    {
72
        $this->name = $name;
73
        return $this;
74
    }
75
76
    public function setTranslationDomain(string $translationDomain): self
77
    {
78
        $this->translationDomain = $translationDomain;
79
        return $this;
80
    }
81
82
    public function setType(string $type): self
83
    {
84
        $this->type = $type;
85
        return $this;
86
    }
87
88
    public function setTypeName(string $typeName): self
89
    {
90
        $this->typeName = $typeName;
91
        return $this;
92
    }
93
94
    public function __toString(): string
95
    {
96
        return $this->name;
97
    }
98
99
    public function configureOptions(OptionsResolver $resolver):void
100
    {
101
        $resolver->setDefaults([
102
            'key'                => null,
103
            'type'               => null,
104
            'name'               => null,
105
            'translation_domain' => null,
106
            'type_name'          => null,
107
            'description'        => null,
108
        ])
109
            ->setRequired(['key', 'type', 'name', 'translation_domain', 'type_name'])
110
            ->setAllowedTypes('key', ['string'])
111
            ->setAllowedTypes('name', ['string'])
112
            ->setAllowedTypes('translation_domain', ['string'])
113
            ->setAllowedTypes('type', ['string'])
114
            ->setAllowedTypes('type_name', ['string'])
115
            ->setAllowedTypes('description', ['string', 'null'])
116
        ;
117
    }
118
}
119