Completed
Push — master ( dea6f9...493a70 )
by Tim
12s
created

ResultTrait::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * AppserverIo\Routlt\Results\ResultTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author     Tim Wagner <[email protected]>
15
 * @copyright  2015 TechDivision GmbH <[email protected]>
16
 * @license    http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link       http://github.com/appserver-io/routlt
18
 * @link       http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Routlt\Results;
22
23
use AppserverIo\Routlt\ActionInterface;
24
use AppserverIo\Routlt\Description\ResultDescriptorInterface;
25
26
/**
27
 * Trait providing basic result functionality.
28
 *
29
 * @author     Tim Wagner <[email protected]>
30
 * @copyright  2015 TechDivision GmbH <[email protected]>
31
 * @license    http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link       http://github.com/appserver-io/routlt
33
 * @link       http://www.appserver.io
34
 */
35
trait ResultTrait
36
{
37
38
    /**
39
     * The action result name.
40
     *
41
     * @var string
42
     */
43
    protected $name;
44
45
    /**
46
     * The action result type.
47
     *
48
     * @var string
49
     */
50
    protected $type;
51
52
    /**
53
     * The action result value.
54
     *
55
     * @var array
56
     */
57
    protected $result;
58
59
    /**
60
     * The HTTP response code that has to be send.
61
     *
62
     * @var string
63
     */
64
    protected $code = 200;
65
66
    /**
67
     * Initializes the instance with the configured result value.
68
     *
69
     * @param \AppserverIo\Routlt\Description\\ResultDescriptorInterface $resultDescriptor The result descriptor instance
70
     */
71
    public function __construct(ResultDescriptorInterface $resultDescriptor)
72
    {
73
        $this->name = $resultDescriptor->getName();
74
        $this->type = $resultDescriptor->getType();
75
        $this->code = $resultDescriptor->getCode();
0 ignored issues
show
Documentation Bug introduced by
The property $code was declared of type string, but $resultDescriptor->getCode() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
76
        $this->result = $resultDescriptor->getResult();
0 ignored issues
show
Documentation Bug introduced by
It seems like $resultDescriptor->getResult() of type string is incompatible with the declared type array of property $result.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
77
    }
78
79
    /**
80
     * Returns the action result name.
81
     *
82
     * @return string The action result name
83
     */
84
    public function getName()
85
    {
86
        return $this->name;
87
    }
88
89
    /**
90
     * Returns the action result type.
91
     *
92
     * @return string The action result type
93
     */
94
    public function getType()
95
    {
96
        return $this->type;
97
    }
98
99
    /**
100
     * Returns the action result value.
101
     *
102
     * @return string The action result value
103
     */
104
    public function getResult()
105
    {
106
        return $this->result;
107
    }
108
109
    /**
110
     * Returns the HTTP response code that has to be send.
111
     *
112
     * @return integer The HTTP response code
113
     */
114
    public function getCode()
115
    {
116
        return $this->code;
117
    }
118
119
    /**
120
     * Sets the actual action instance.
121
     *
122
     * @param \AppserverIo\Routlt\ActionInterface $action The action instance
123
     *
124
     * @return void
125
     */
126
    public function setAction(ActionInterface $action)
127
    {
128
        $this->action = $action;
0 ignored issues
show
Bug introduced by
The property action does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
129
    }
130
131
    /**
132
     * Returns the action instance.
133
     *
134
     * @return \AppserverIo\Routlt\ActionInterface The action instance
135
     */
136
    public function getAction()
137
    {
138
        return $this->action;
139
    }
140
}
141