This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the xAPI package. |
||
5 | * |
||
6 | * (c) Christian Flothmann <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace XApi\Repository\Doctrine\Mapping; |
||
13 | |||
14 | use Xabbuh\XApi\Model\Statement as StatementModel; |
||
15 | use Xabbuh\XApi\Model\StatementId; |
||
16 | |||
17 | /** |
||
18 | * A {@link Statement} mapped to a storage backend. |
||
19 | * |
||
20 | * @author Christian Flothmann <[email protected]> |
||
21 | */ |
||
22 | class Statement |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | public $id; |
||
28 | |||
29 | /** |
||
30 | * @var StatementObject |
||
31 | */ |
||
32 | public $actor; |
||
33 | |||
34 | /** |
||
35 | * @var Verb |
||
36 | */ |
||
37 | public $verb; |
||
38 | |||
39 | /** |
||
40 | * @var StatementObject |
||
41 | */ |
||
42 | public $object; |
||
43 | |||
44 | /** |
||
45 | * @var Result |
||
46 | */ |
||
47 | public $result; |
||
48 | |||
49 | /** |
||
50 | * @var StatementObject |
||
51 | */ |
||
52 | public $authority; |
||
53 | |||
54 | /** |
||
55 | * @var int |
||
56 | */ |
||
57 | public $created; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | */ |
||
62 | public $stored; |
||
63 | |||
64 | /** |
||
65 | * @var Context |
||
66 | */ |
||
67 | public $context; |
||
68 | |||
69 | /** |
||
70 | * @var bool |
||
71 | */ |
||
72 | public $hasAttachments; |
||
73 | |||
74 | /** |
||
75 | * @var Attachment[]|null |
||
76 | */ |
||
77 | public $attachments; |
||
78 | |||
79 | public static function fromModel(StatementModel $model) |
||
80 | { |
||
81 | $statement = new self(); |
||
82 | $statement->id = $model->getId()->getValue(); |
||
83 | $statement->actor = StatementObject::fromModel($model->getActor()); |
||
84 | $statement->verb = Verb::fromModel($model->getVerb()); |
||
85 | $statement->object = StatementObject::fromModel($model->getObject()); |
||
86 | |||
87 | if (null !== $model->getCreated()) { |
||
88 | $statement->created = $model->getCreated()->getTimestamp(); |
||
89 | } |
||
90 | |||
91 | if (null !== $result = $model->getResult()) { |
||
92 | $statement->result = Result::fromModel($result); |
||
93 | } |
||
94 | |||
95 | if (null !== $authority = $model->getAuthority()) { |
||
96 | $statement->authority = StatementObject::fromModel($authority); |
||
97 | } |
||
98 | |||
99 | if (null !== $context = $model->getContext()) { |
||
100 | $statement->context = Context::fromModel($context); |
||
101 | } |
||
102 | |||
103 | if (null !== $attachments = $model->getAttachments()) { |
||
104 | $statement->hasAttachments = true; |
||
105 | $statement->attachments = array(); |
||
106 | |||
107 | foreach ($attachments as $attachment) { |
||
108 | $mappedAttachment = Attachment::fromModel($attachment); |
||
109 | $mappedAttachment->statement = $statement; |
||
110 | $statement->attachments[] = $mappedAttachment; |
||
111 | } |
||
112 | } else { |
||
113 | $statement->hasAttachments = false; |
||
114 | } |
||
115 | |||
116 | return $statement; |
||
117 | } |
||
118 | |||
119 | public function getModel() |
||
120 | { |
||
121 | $result = null; |
||
122 | $authority = null; |
||
123 | $created = null; |
||
124 | $stored = null; |
||
125 | $context = null; |
||
126 | $attachments = null; |
||
127 | |||
128 | if (null !== $this->result) { |
||
129 | $result = $this->result->getModel(); |
||
130 | } |
||
131 | |||
132 | if (null !== $this->authority) { |
||
133 | $authority = $this->authority->getModel(); |
||
134 | } |
||
135 | |||
136 | if (null !== $this->created) { |
||
137 | $created = new \DateTime('@'.$this->created); |
||
138 | } |
||
139 | |||
140 | if (null !== $this->stored) { |
||
141 | $stored = new \DateTime('@'.$this->stored); |
||
142 | } |
||
143 | |||
144 | if (null !== $this->context) { |
||
145 | $context = $this->context->getModel(); |
||
146 | } |
||
147 | |||
148 | if ($this->hasAttachments) { |
||
149 | $attachments = array(); |
||
150 | |||
151 | foreach ($this->attachments as $attachment) { |
||
0 ignored issues
–
show
|
|||
152 | $attachments[] = $attachment->getModel(); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | return new StatementModel( |
||
157 | StatementId::fromString($this->id), |
||
158 | $this->actor->getModel(), |
||
0 ignored issues
–
show
It seems like
$this->actor->getModel() targeting XApi\Repository\Doctrine...ementObject::getModel() can also be of type object<Xabbuh\XApi\Model\Activity> or object<Xabbuh\XApi\Model\StatementReference> or object<Xabbuh\XApi\Model\SubStatement> ; however, Xabbuh\XApi\Model\Statement::__construct() does only seem to accept object<Xabbuh\XApi\Model\Actor> , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
159 | $this->verb->getModel(), |
||
160 | $this->object->getModel(), |
||
161 | $result, |
||
162 | $authority, |
||
0 ignored issues
–
show
It seems like
$authority defined by $this->authority->getModel() on line 133 can also be of type object<Xabbuh\XApi\Model\Activity> or object<Xabbuh\XApi\Model\StatementReference> or object<Xabbuh\XApi\Model\SubStatement> ; however, Xabbuh\XApi\Model\Statement::__construct() does only seem to accept null|object<Xabbuh\XApi\Model\Actor> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
163 | $created, |
||
164 | $stored, |
||
165 | $context, |
||
166 | $attachments |
||
0 ignored issues
–
show
It seems like
$attachments defined by array() on line 149 can also be of type array ; however, Xabbuh\XApi\Model\Statement::__construct() does only seem to accept null|array<integer,objec...XApi\Model\Attachment>> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
167 | ); |
||
168 | } |
||
169 | } |
||
170 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.