Failed Conditions
Pull Request — feature/init (#3)
by Yo
01:46
created

StringDoc::getMinLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Model\Type;
3
4
/**
5
 * Class StringDoc
6
 */
7
class StringDoc extends ScalarDoc
8
{
9
    /*** Validation ***/
10
    /** @var null|bool */
11
    private $blankAllowed = null;
12
    /** @var null|string */
13
    private $format = null;
14
    /** @var null|int|float */
15
    private $minLength = null;
16
    /** @var null|int|float */
17
    private $maxLength = null;
18
19
    /**
20
     * @param bool|null $blankAllowed
21
     */
22
    public function setBlankAllowed($blankAllowed)
23
    {
24
        $this->blankAllowed = $blankAllowed;
25
    }
26
27
    /**
28
     * @param null|string $format
29
     */
30
    public function setFormat($format)
31
    {
32
        $this->format = $format;
33
    }
34
35
    /**
36
     * @param null $minLength
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $minLength is correct as it would always require null to be passed?
Loading history...
37
     */
38
    public function setMinLength($minLength)
39
    {
40
        $this->minLength = $minLength;
41
    }
42
43
    /**
44
     * @param null|bool $maxLength
45
     */
46
    public function setMaxLength($maxLength)
47
    {
48
        $this->maxLength = $maxLength;
0 ignored issues
show
Documentation Bug introduced by
It seems like $maxLength can also be of type boolean. However, the property $maxLength is declared as type null|integer|double. 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...
49
    }
50
51
    /**
52
     * @return bool|null
53
     */
54
    public function isBlankAllowed()
55
    {
56
        return $this->blankAllowed;
57
    }
58
59
    /**
60
     * @return null|string
61
     */
62
    public function getFormat()
63
    {
64
        return $this->format;
65
    }
66
67
    /**
68
     * @return null|bool
69
     */
70
    public function getMinLength()
71
    {
72
        return $this->minLength;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->minLength also could return the type integer|double which is incompatible with the documented return type null|boolean.
Loading history...
73
    }
74
75
    /**
76
     * @return null|bool
77
     */
78
    public function getMaxLength()
79
    {
80
        return $this->maxLength;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->maxLength also could return the type integer|double which is incompatible with the documented return type null|boolean.
Loading history...
81
    }
82
}
83