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 | namespace lroman242\LaravelCassandra\Eloquent; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use Cassandra\Rows; |
||
7 | use Cassandra\Timestamp; |
||
8 | use lroman242\LaravelCassandra\CassandraTypesTrait; |
||
9 | use lroman242\LaravelCassandra\Collection; |
||
10 | use lroman242\LaravelCassandra\Query\Builder as QueryBuilder; |
||
11 | use Illuminate\Database\Eloquent\Model as BaseModel; |
||
12 | |||
13 | abstract class Model extends BaseModel |
||
14 | { |
||
15 | use CassandraTypesTrait; |
||
16 | |||
17 | /** |
||
18 | * The connection name for the model. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $connection = 'cassandra'; |
||
23 | |||
24 | /** |
||
25 | * Indicates if the IDs are auto-incrementing. |
||
26 | * This is not possible in cassandra so we override this |
||
27 | * |
||
28 | * @var bool |
||
29 | */ |
||
30 | public $incrementing = false; |
||
31 | |||
32 | /** |
||
33 | * @inheritdoc |
||
34 | */ |
||
35 | 55 | public function newEloquentBuilder($query) |
|
36 | { |
||
37 | 55 | return new Builder($query); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @inheritdoc |
||
42 | */ |
||
43 | 55 | protected function newBaseQueryBuilder() |
|
44 | { |
||
45 | 55 | $connection = $this->getConnection(); |
|
46 | |||
47 | 55 | return new QueryBuilder($connection, null, $connection->getPostProcessor()); |
|
0 ignored issues
–
show
$connection->getPostProcessor() is of type object<Illuminate\Databa...y\Processors\Processor> , but the function expects a null|object<lroman242\La...sandra\Query\Processor> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 13 | public function freshTimestamp() |
|
54 | { |
||
55 | 13 | return new Timestamp(); |
|
0 ignored issues
–
show
The return type of
return new \Cassandra\Timestamp(); (Cassandra\Timestamp ) is incompatible with the return type of the parent method Illuminate\Database\Eloquent\Model::freshTimestamp of type Illuminate\Support\Carbon .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | 13 | public function fromDateTime($value) |
|
62 | { |
||
63 | // If the value is already a Timestamp instance, we don't need to parse it. |
||
64 | 13 | if ($value instanceof Timestamp) { |
|
0 ignored issues
–
show
The class
Cassandra\Timestamp does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
65 | 13 | return $value; |
|
0 ignored issues
–
show
The return type of
return $value; (Cassandra\Timestamp ) is incompatible with the return type of the parent method Illuminate\Database\Eloquent\Model::fromDateTime of type integer|string .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
66 | } |
||
67 | |||
68 | // Let Eloquent convert the value to a DateTime instance. |
||
69 | 1 | if (!$value instanceof \DateTime) { |
|
70 | 1 | $value = parent::asDateTime($value); |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
asDateTime() instead of fromDateTime() ). Are you sure this is correct? If so, you might want to change this to $this->asDateTime() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
71 | } |
||
72 | |||
73 | 1 | return new Timestamp($value->getTimestamp() * 1000); |
|
0 ignored issues
–
show
The return type of
return new \Cassandra\Ti...getTimestamp() * 1000); (Cassandra\Timestamp ) is incompatible with the return type of the parent method Illuminate\Database\Eloquent\Model::fromDateTime of type integer|string .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | 6 | protected function asDateTime($value) |
|
80 | { |
||
81 | // Convert UTCDateTime instances. |
||
82 | 6 | if ($value instanceof Timestamp) { |
|
0 ignored issues
–
show
The class
Cassandra\Timestamp does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
83 | 6 | return Carbon::instance($value->toDateTime()); |
|
84 | } |
||
85 | |||
86 | return parent::asDateTime($value); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the table qualified key name. |
||
91 | * Cassandra does not support the table.column annotation so |
||
92 | * we override this |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 8 | public function getQualifiedKeyName() |
|
97 | { |
||
98 | 8 | return $this->getKeyName(); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * Qualify the given column name by the model's table. |
||
103 | * |
||
104 | * @param string $column |
||
105 | * @return string |
||
106 | */ |
||
107 | 2 | public function qualifyColumn($column) |
|
108 | { |
||
109 | 2 | return $column; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * @inheritdoc |
||
114 | */ |
||
115 | 55 | public function __call($method, $parameters) |
|
116 | { |
||
117 | // Unset method |
||
118 | 55 | if ($method == 'unset') { |
|
119 | return call_user_func_array([$this, 'drop'], $parameters); |
||
120 | } |
||
121 | |||
122 | 55 | return parent::__call($method, $parameters); |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * Create a new Eloquent Collection instance. |
||
127 | * |
||
128 | * @param Rows|array $rows |
||
129 | * |
||
130 | * @return Collection |
||
131 | * |
||
132 | * @throws \Exception |
||
133 | */ |
||
134 | 50 | public function newCassandraCollection($rows) |
|
135 | { |
||
136 | 50 | if (!is_array($rows) && !$rows instanceof Rows) { |
|
0 ignored issues
–
show
The class
Cassandra\Rows does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
137 | throw new \Exception('Wrong type to create collection');//TODO: customize error |
||
138 | } |
||
139 | |||
140 | 50 | $items = []; |
|
141 | 50 | foreach ($rows as $row) { |
|
142 | 47 | $items[] = $this->newFromBuilder($row); |
|
143 | } |
||
144 | |||
145 | 50 | $collection = new Collection($items); |
|
146 | |||
147 | 50 | if ($rows instanceof Rows) { |
|
0 ignored issues
–
show
The class
Cassandra\Rows does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
148 | 19 | $collection->setRowsInstance($rows); |
|
149 | } |
||
150 | |||
151 | 50 | return $collection; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * Determine if the new and old values for a given key are equivalent. |
||
156 | * |
||
157 | * @param string $key |
||
158 | * @param mixed $current |
||
159 | * @return bool |
||
160 | */ |
||
161 | 13 | public function originalIsEquivalent($key, $current) |
|
162 | { |
||
163 | 13 | if (!array_key_exists($key, $this->original)) { |
|
164 | 13 | return false; |
|
165 | } |
||
166 | |||
167 | 2 | $original = $this->getOriginal($key); |
|
168 | |||
169 | 2 | if ($current === $original) { |
|
170 | 2 | return true; |
|
171 | 2 | } elseif (is_null($current)) { |
|
172 | return false; |
||
173 | 2 | } elseif ($this->isDateAttribute($key)) { |
|
174 | 2 | return $this->fromDateTime($current) === |
|
175 | 2 | $this->fromDateTime($original); |
|
176 | 1 | } elseif ($this->hasCast($key)) { |
|
177 | return $this->castAttribute($key, $current) === |
||
178 | $this->castAttribute($key, $original); |
||
179 | 1 | } elseif ($this->isCassandraValueObject($current)) { |
|
180 | return $this->valueFromCassandraObject($current) === |
||
181 | $this->valueFromCassandraObject($original); |
||
182 | } |
||
183 | |||
184 | 1 | return is_numeric($current) && is_numeric($original) |
|
185 | 1 | && strcmp((string) $current, (string) $original) === 0; |
|
186 | } |
||
187 | |||
188 | /** |
||
189 | * Get the value of the model's primary key. |
||
190 | * |
||
191 | * @return mixed |
||
192 | */ |
||
193 | 16 | public function getKey() |
|
194 | { |
||
195 | 16 | $value = $this->getAttribute($this->getKeyName()); |
|
196 | |||
197 | 16 | if ($this->isCassandraValueObject($value)) { |
|
198 | return $this->valueFromCassandraObject($this->getAttribute($this->getKeyName())); |
||
199 | } |
||
200 | |||
201 | 16 | return $value; |
|
202 | } |
||
203 | |||
204 | } |
||
205 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.