GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractRule   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 128
rs 10
c 4
b 1
f 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A translateMessage() 0 9 2
A setTranslator() 0 10 2
A getTranslator() 0 7 2
A hasTranslator() 0 4 1
A setTranslatorEnabled() 0 6 1
A isTranslatorEnabled() 0 5 1
A setTranslatorTextDomain() 0 6 1
A getTranslatorTextDomain() 0 7 2
1
<?php
2
/**
3
 * AbstractRule
4
 *
5
 * @category  StrokerForm
6
 * @package   StrokerForm\Renderer
7
 * @copyright 2012 Bram Gerritsen
8
 * @version   SVN: $Id$
9
 */
10
11
namespace StrokerForm\Renderer\JqueryValidate\Rule;
12
13
use Zend\I18n\Translator\TranslatorInterface;
14
use Zend\Validator\AbstractValidator;
15
16
abstract class AbstractRule implements RuleInterface
17
{
18
    /**
19
     * @var TranslatorInterface
20
     */
21
    protected $translator = null;
22
23
    /**
24
     * @var bool
25
     */
26
    protected $translatorEnabled = true;
27
28
    /**
29
     * @var string
30
     */
31
    protected $translatorTextDomain;
32
33
    /**
34
     * Translate a validation message
35
     *
36
     * @param  string $message
37
     *
38
     * @return string
39
     */
40
    protected function translateMessage($message)
41
    {
42
        $translator = $this->getTranslator();
43
        if (!$translator) {
44
            return $message;
45
        }
46
47
        return $translator->translate($message, $this->getTranslatorTextDomain());
48
    }
49
50
    /**
51
     * Sets translator to use in helper
52
     *
53
     * @param  TranslatorInterface $translator
54
     * @param  string              $textDomain
55
     *
56
     * @return AbstractRule
57
     */
58
    public function setTranslator(TranslatorInterface $translator = null, $textDomain = null)
59
    {
60
        $this->translator = $translator;
61
62
        if (!is_null($textDomain)) {
63
            $this->setTranslatorTextDomain($textDomain);
64
        }
65
66
        return $this;
67
    }
68
69
    /**
70
     * Returns translator used in object
71
     *
72
     * @return TranslatorInterface|\Zend\Validator\Translator\TranslatorInterface
73
     */
74
    public function getTranslator()
75
    {
76
        if ($this->translator === null) {
77
            $this->translator = AbstractValidator::getDefaultTranslator();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Zend\Validator\Abstract...:getDefaultTranslator() can also be of type object<Zend\Validator\Tr...or\TranslatorInterface>. However, the property $translator is declared as type object<Zend\I18n\Translator\TranslatorInterface>. 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...
78
        }
79
        return $this->translator;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->translator; of type Zend\Validator\Translato...tor\TranslatorInterface adds the type Zend\Validator\Translator\TranslatorInterface to the return on line 79 which is incompatible with the return type declared by the interface Zend\I18n\Translator\Tra...nterface::getTranslator of type Zend\I18n\Translator\TranslatorInterface|null.
Loading history...
80
    }
81
82
    /**
83
     * Checks if the object has a translator
84
     *
85
     * @return bool
86
     */
87
    public function hasTranslator()
88
    {
89
        return !is_null($this->translator);
90
    }
91
92
    /**
93
     * Sets whether translator is enabled and should be used
94
     *
95
     * @param  bool $enabled
96
     *
97
     * @return AbstractRule
98
     */
99
    public function setTranslatorEnabled($enabled = true)
100
    {
101
        $this->translatorEnabled = $enabled;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Returns whether translator is enabled and should be used
108
     *
109
     * @return bool
110
     */
111
    public function isTranslatorEnabled()
112
    {
113
        $this->translator = AbstractValidator::getDefaultTranslator();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Zend\Validator\Abstract...:getDefaultTranslator() can also be of type object<Zend\Validator\Tr...or\TranslatorInterface>. However, the property $translator is declared as type object<Zend\I18n\Translator\TranslatorInterface>. 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...
114
        return $this->translatorEnabled;
115
    }
116
117
    /**
118
     * Set translation text domain
119
     *
120
     * @param  string $textDomain
121
     *
122
     * @return AbstractRule
123
     */
124
    public function setTranslatorTextDomain($textDomain = 'default')
125
    {
126
        $this->translatorTextDomain = $textDomain;
127
128
        return $this;
129
    }
130
131
    /**
132
     * Return the translation text domain
133
     *
134
     * @return string
135
     */
136
    public function getTranslatorTextDomain()
137
    {
138
        if ($this->translatorTextDomain === null) {
139
            $this->translatorTextDomain = AbstractValidator::getDefaultTranslatorTextDomain();
140
        }
141
        return $this->translatorTextDomain;
142
    }
143
}
144