Passed
Pull Request — master (#48)
by
unknown
02:41
created

ParameterConfig::allowsNull()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Proxy\Config;
6
7
/**
8
 * A parameter metadata. {@see ClassConfigFactory} is used for creation. Note that it relies only on PHP type hints and
9
 * ignores PHPDoc completely.
10
 */
11
final class ParameterConfig
12
{
13 5
    public function __construct(
14
        /**
15
         * @var TypeConfig|null Type config. `null` means no type specified.
16
         */
17
        public ?TypeConfig $type,
18
        /**
19
         * @var string A name without dollar sign (`$`). For example: `previousNodesCount`.
20
         */
21
        public string $name,
22
        /**
23
         * @var bool Whether the default value available.
24
         *
25
         * @link https://www.php.net/manual/en/functions.arguments.php#functions.arguments.default
26
         */
27
        public bool $isDefaultValueAvailable,
28
        /**
29
         * @var bool|null Whether the default value refers to a constant (when {@see $isDefaultValueAvailable} is
30
         * `true`}). `null` means no default value specified ({@see $isDefaultValueAvailable} is `false`).
31
         *
32
         * @link https://www.php.net/manual/en/language.constants.syntax.php
33
         */
34
        public ?bool $isDefaultValueConstant,
35
        /**
36
         * @var string|null A constant name for default value (when it's specified, {@see $isDefaultValueAvailable} and
37
         * {@see $isDefaultValueConstant} must be `true` at the same time). `null` means no default value specified or
38
         * it's not a constant (either {@see $isDefaultValueAvailable} or {@see $isDefaultValueConstant} is `false`).
39
         *
40
         * @link https://www.php.net/manual/en/language.constants.syntax.php
41
         */
42
        public ?string $defaultValueConstantName,
43
        /**
44
         * @var mixed The actual value specified as default with corresponding type. `null` means no default value (only
45
         * when {@see $isDefaultValueAvailable} is `false`).
46
         */
47
        public mixed $defaultValue,
48
    ) {
49
    }
50
51
    /**
52
     * Whether a parameter has type.
53
     *
54
     * @return bool `true` if type specified and `false` otherwise.
55
     */
56 3
    public function hasType(): bool
57
    {
58 3
        return $this->type !== null;
59
    }
60
61
    /**
62
     * Whether the null values are allowed.
63
     *
64
     * @return bool `true` when null values are allowed and `false` otherwise.
65
     *
66
     * @link https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.nullable-types
67
     */
68
    public function allowsNull(): bool
69
    {
70
        return $this->type ? $this->type->allowsNull : true;
71
    }
72
}
73