Completed
Branch develop (598d0f)
by Benjamin
03:23
created

Skill   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 141
rs 10
wmc 14

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 3 1
A setTypeTranslationKey() 0 3 1
A __toString() 0 3 1
A setTranslationKey() 0 3 1
A setType() 0 3 1
A getTypeTranslationKey() 0 3 1
A getTranslationKey() 0 3 1
A getTranslationDomain() 0 3 1
A setKey() 0 3 1
A hydrateWithOptions() 0 7 1
A configureOptions() 0 19 1
A getType() 0 3 1
A resolveOptions() 0 4 1
A setTranslationDomain() 0 3 1
1
<?php
2
3
namespace Obblm\Core\Helper\Rule\Skill;
4
5
use Obblm\Core\Helper\Optionable;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
class Skill extends Optionable
9
{
10
    /** @var string */
11
    private $key;
12
13
    /** @var string */
14
    private $type;
15
16
    /** @var string */
17
    private $translation_key;
18
19
    /** @var string */
20
    private $type_translation_key;
21
22
    /** @var string */
23
    private $translation_domain;
24
25
    /**
26
     * Inducement constructor.
27
     * @param array $options
28
     */
29
30
    private function hydrateWithOptions($options)
31
    {
32
        $this->key = $options['key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $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...
33
        $this->type = $options['type'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $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...
34
        $this->translation_key = $options['translation_key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['translation_key'] ?? false can also be of type false. However, the property $translation_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...
35
        $this->type_translation_key = $options['type_translation_key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['type_translation_key'] ?? false can also be of type false. However, the property $type_translation_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...
36
        $this->translation_domain = $options['translation_domain'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['translation_domain'] ?? false can also be of type false. However, the property $translation_domain 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...
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getKey(): string
43
    {
44
        return $this->key;
45
    }
46
47
    /**
48
     * @param string $key
49
     */
50
    public function setKey(string $key): void
51
    {
52
        $this->key = $key;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getType(): string
59
    {
60
        return $this->type;
61
    }
62
63
    /**
64
     * @param string $type
65
     */
66
    public function setType(string $type): void
67
    {
68
        $this->type = $type;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getTranslationKey(): string
75
    {
76
        return $this->translation_key;
77
    }
78
79
    /**
80
     * @param string $translation_key
81
     */
82
    public function setTranslationKey(string $translation_key): void
83
    {
84
        $this->translation_key = $translation_key;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getTypeTranslationKey(): string
91
    {
92
        return $this->type_translation_key;
93
    }
94
95
    /**
96
     * @param string $type_translation_key
97
     */
98
    public function setTypeTranslationKey(string $type_translation_key): void
99
    {
100
        $this->type_translation_key = $type_translation_key;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getTranslationDomain(): string
107
    {
108
        return $this->translation_domain;
109
    }
110
111
    /**
112
     * @param string $translation_domain
113
     */
114
    public function setTranslationDomain(string $translation_domain): void
115
    {
116
        $this->translation_domain = $translation_domain;
117
    }
118
119
    public function __toString(): string
120
    {
121
        return $this->translation_key;
122
    }
123
124
    public function resolveOptions($options)
125
    {
126
        parent::resolveOptions($options);
127
        $this->hydrateWithOptions($options);
128
    }
129
130
    public function configureOptions(OptionsResolver $resolver)
131
    {
132
        $resolver->setDefaults([
133
            'key'                  => null,
134
            'type'                 => null,
135
            'translation_key'      => null,
136
            'translation_domain'   => null,
137
            'type_translation_key' => null,
138
        ])
139
            ->setRequired('key')
140
            ->setRequired('translation_key')
141
            ->setRequired('translation_domain')
142
            ->setRequired('type')
143
            ->setRequired('type_translation_key')
144
            ->setAllowedTypes('key', ['string'])
145
            ->setAllowedTypes('translation_key', ['string'])
146
            ->setAllowedTypes('translation_domain', ['string'])
147
            ->setAllowedTypes('type', ['string'])
148
            ->setAllowedTypes('type_translation_key', ['string'])
149
        ;
150
    }
151
}
152