Parameter::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 2
nop 2
1
<?php
2
namespace Workana\AsyncJobs;
3
use Workana\AsyncJobs\Util\ClassUtils;
4
5
/**
6
 * DTO Parameter
7
 *
8
 * @author Carlos Frutos <[email protected]>
9
 */
10
class Parameter
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $type;
16
17
    /**
18
     * @var bool
19
     */
20
    protected $scalar = false;
21
22
    /**
23
     * @var string?
24
     */
25
    protected $name;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $value;
31
32
    /**
33
     * Creates a new Parameter
34
     *
35
     * @param mixed $value
36
     * @param string? $name
0 ignored issues
show
Documentation introduced by
The doc-type string? could not be parsed: Unknown type name "string?" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
37
     */
38
    public function __construct($value, $name = null)
39
    {
40
        if (is_scalar($value) || is_array($value) || is_null($value)) {
41
            $this->type = gettype($value);
42
            $this->scalar = true;
43
        } else {
44
            $this->type = ClassUtils::getRealClass($value);
45
        }
46
47
        $this->name = $name;
48
        $this->value = $value;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getName()
55
    {
56
        return $this->name;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function isScalar()
63
    {
64
        return $this->scalar;
65
    }
66
67
    /**
68
     * @return mixed
69
     */
70
    public function getValue()
71
    {
72
        return $this->value;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getType()
79
    {
80
        return $this->type;
81
    }
82
}