Completed
Push — di ( eef893...256938 )
by Tim
06:01
created

ResultTrait::setAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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 result from the result descriptor instance.
68
     *
69
     * @param \AppserverIo\Routlt\Description\ResultDescriptorInterface $resultDescriptor The result descriptor instance
70
     *
71
     * @return void
72
     */
73
    public function init(ResultDescriptorInterface $resultDescriptor)
74
    {
75
        $this->name = $resultDescriptor->getName();
76
        $this->type = $resultDescriptor->getType();
77
        $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...
78
        $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...
79
    }
80
81
    /**
82
     * Returns the action result name.
83
     *
84
     * @return string The action result name
85
     */
86
    public function getName()
87
    {
88
        return $this->name;
89
    }
90
91
    /**
92
     * Returns the action result type.
93
     *
94
     * @return string The action result type
95
     */
96
    public function getType()
97
    {
98
        return $this->type;
99
    }
100
101
    /**
102
     * Returns the action result value.
103
     *
104
     * @return string The action result value
105
     */
106
    public function getResult()
107
    {
108
        return $this->result;
109
    }
110
111
    /**
112
     * Returns the HTTP response code that has to be send.
113
     *
114
     * @return integer The HTTP response code
115
     */
116
    public function getCode()
117
    {
118
        return $this->code;
119
    }
120
121
    /**
122
     * Sets the actual action instance.
123
     *
124
     * @param \AppserverIo\Routlt\ActionInterface $action The action instance
125
     *
126
     * @return void
127
     */
128
    public function setAction(ActionInterface $action)
129
    {
130
        $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...
131
    }
132
133
    /**
134
     * Returns the action instance.
135
     *
136
     * @return \AppserverIo\Routlt\ActionInterface The action instance
137
     */
138
    public function getAction()
139
    {
140
        return $this->action;
141
    }
142
}
143