Completed
Branch testing (8fdb90)
by Roman
10:31
created

Model   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 325
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 56.29%

Importance

Changes 0
Metric Value
wmc 58
lcom 1
cbo 7
dl 0
loc 325
ccs 67
cts 119
cp 0.5629
rs 4.5599
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A newEloquentBuilder() 0 4 1
A newBaseQueryBuilder() 0 6 1
A freshTimestamp() 0 4 1
A fromDateTime() 0 14 3
A asDateTime() 0 9 2
A originalIsNumericallyEquivalent() 0 15 4
A getQualifiedKeyName() 0 4 1
A qualifyColumn() 0 4 1
B setAttribute() 0 33 7
A __call() 0 9 2
A newCassandraCollection() 0 19 5
B originalIsEquivalent() 0 26 9
B isCassandraObject() 0 15 8
A isCompareableCassandraObject() 0 10 3
B valueFromCassandraObject() 0 30 8
A getKey() 0 9 2

How to fix   Complexity   

Complex Class

Complex classes like Model often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Model, and based on these observations, apply Extract Interface, too.

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\Collection;
9
use lroman242\LaravelCassandra\Query\Builder as QueryBuilder;
10
use Illuminate\Database\Eloquent\Model as BaseModel;
11
use Illuminate\Support\Str;
12
13
abstract class Model extends BaseModel
14
{
15
    /**
16
     * The connection name for the model.
17
     *
18
     * @var string
19
     */
20
    protected $connection = 'cassandra';
21
22
    /**
23
     * Indicates if the IDs are auto-incrementing.
24
     * This is not possible in cassandra so we override this
25
     *
26
     * @var bool
27
     */
28
    public $incrementing = false;
29
30
    /**
31
     * @inheritdoc
32
     */
33 55
    public function newEloquentBuilder($query)
34
    {
35 55
        return new Builder($query);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 55
    protected function newBaseQueryBuilder()
42
    {
43 55
        $connection = $this->getConnection();
44
45 55
        return new QueryBuilder($connection, null, $connection->getPostProcessor());
0 ignored issues
show
Compatibility introduced by
$connection of type object<Illuminate\Database\Connection> is not a sub-type of object<lroman242\LaravelCassandra\Connection>. It seems like you assume a child class of the class Illuminate\Database\Connection to be always present.

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.

Loading history...
Documentation introduced by
$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);
Loading history...
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 13
    public function freshTimestamp()
52
    {
53 13
        return new Timestamp();
0 ignored issues
show
Bug Best Practice introduced by
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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59 13
    public function fromDateTime($value)
60
    {
61
        // If the value is already a Timestamp instance, we don't need to parse it.
62 13
        if ($value instanceof Timestamp) {
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
63 13
            return $value;
0 ignored issues
show
Bug Best Practice introduced by
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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
64
        }
65
66
        // Let Eloquent convert the value to a DateTime instance.
67 1
        if (!$value instanceof \DateTime) {
68 1
            $value = parent::asDateTime($value);
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
69
        }
70
71 1
        return new Timestamp($value->getTimestamp() * 1000);
0 ignored issues
show
Bug Best Practice introduced by
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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 6
    protected function asDateTime($value)
78
    {
79
        // Convert UTCDateTime instances.
80 6
        if ($value instanceof Timestamp) {
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
81 6
            return Carbon::instance($value->toDateTime());
82
        }
83
84
        return parent::asDateTime($value);
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    protected function originalIsNumericallyEquivalent($key)
91
    {
92
        $current = $this->attributes[$key];
93
        $original = $this->original[$key];
94
95
        // Date comparison.
96
        if (in_array($key, $this->getDates())) {
97
            $current = $current instanceof Timestamp ? $this->asDateTime($current) : $current;
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
98
            $original = $original instanceof Timestamp ? $this->asDateTime($original) : $original;
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
99
100
            return $current == $original;
101
        }
102
103
        return parent::originalIsNumericallyEquivalent($key);
104
    }
105
106
    /**
107
     * Get the table qualified key name.
108
     * Cassandra does not support the table.column annotation so
109
     * we override this
110
     *
111
     * @return string
112
     */
113 8
    public function getQualifiedKeyName()
114
    {
115 8
        return $this->getKeyName();
116
    }
117
118
    /**
119
     * Qualify the given column name by the model's table.
120
     *
121
     * @param  string  $column
122
     * @return string
123
     */
124 2
    public function qualifyColumn($column)
125
    {
126 2
        return $column;
127
    }
128
129
     /**
130
     * Set a given attribute on the model.
131
     *
132
     * @param  string  $key
133
     * @param  mixed  $value
134
     * @return $this
135
     */
136 14
    public function setAttribute($key, $value)
137
    {
138
        // First we will check for the presence of a mutator for the set operation
139
        // which simply lets the developers tweak the attribute as it is set on
140
        // the model, such as "json_encoding" an listing of data for storage.
141 14
        if ($this->hasSetMutator($key)) {
142
            $method = 'set' . Str::studly($key) . 'Attribute';
143
144
            return $this->{$method}($value);
145
        }
146
147
        // If an attribute is listed as a "date", we'll convert it from a DateTime
148
        // instance into a form proper for storage on the database tables using
149
        // the connection grammar's date format. We will auto set the values.
150 14
        elseif ($value !== null && $this->isDateAttribute($key)) {
151 13
            $value = $this->fromDateTime($value);
152
        }
153
154 14
        if ($this->isJsonCastable($key) && !is_null($value)) {
155
            $value = $this->castAttributeAsJson($key, $value);
156
        }
157
158
        // If this attribute contains a JSON ->, we'll set the proper value in the
159
        // attribute's underlying array. This takes care of properly nesting an
160
        // attribute in the array's value in the case of deeply nested items.
161 14
        if (Str::contains($key, '->')) {
162
            return $this->fillJsonAttribute($key, $value);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->fillJsonAttribute($key, $value); (lroman242\LaravelCassandra\Eloquent\Model) is incompatible with the return type of the parent method Illuminate\Database\Eloquent\Model::setAttribute of type Illuminate\Database\Eloq...\Concerns\HasAttributes.

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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
163
        }
164
165 14
        $this->attributes[$key] = $value;
166
167 14
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (lroman242\LaravelCassandra\Eloquent\Model) is incompatible with the return type of the parent method Illuminate\Database\Eloquent\Model::setAttribute of type Illuminate\Database\Eloq...\Concerns\HasAttributes.

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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
168
    }
169
    
170
    /**
171
     * @inheritdoc
172
     */
173 55
    public function __call($method, $parameters)
174
    {
175
        // Unset method
176 55
        if ($method == 'unset') {
177
            return call_user_func_array([$this, 'drop'], $parameters);
178
        }
179
180 55
        return parent::__call($method, $parameters);
181
    }
182
183
    /**
184
     * Create a new Eloquent Collection instance.
185
     *
186
     * @param  Rows|array  $rows
187
     *
188
     * @return Collection
189
     *
190
     * @throws \Exception
191
     */
192 50
    public function newCassandraCollection($rows)
193
    {
194 50
        if (!is_array($rows) && !$rows instanceof Rows) {
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
195
            throw new \Exception('Wrong type to create collection');//TODO: customize error
196
        }
197
198 50
        $items = [];
199 50
        foreach ($rows as $row) {
200 47
            $items[] = $this->newFromBuilder($row);
201
        }
202
203 50
        $collection = new Collection($items);
204
205 50
        if ($rows instanceof Rows) {
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
206 19
            $collection->setRowsInstance($rows);
207
        }
208
209 50
        return $collection;
210
    }
211
212
    /**
213
     * Determine if the new and old values for a given key are equivalent.
214
     *
215
     * @param  string $key
216
     * @param  mixed $current
217
     * @return bool
218
     */
219 13
    public function originalIsEquivalent($key, $current)
220
    {
221 13
        if (!array_key_exists($key, $this->original)) {
222 13
            return false;
223
        }
224
225 2
        $original = $this->getOriginal($key);
226
227 2
        if ($current === $original) {
228 2
            return true;
229 2
        } elseif (is_null($current)) {
230
            return false;
231 2
        } elseif ($this->isDateAttribute($key)) {
232 2
            return $this->fromDateTime($current) ===
233 2
                $this->fromDateTime($original);
234 1
        } elseif ($this->hasCast($key)) {
235
            return $this->castAttribute($key, $current) ===
236
                $this->castAttribute($key, $original);
237 1
        } elseif ($this->isCassandraObject($current)) {
238
            return $this->valueFromCassandraObject($current) ===
239
                $this->valueFromCassandraObject($original);
240
        }
241
242 1
        return is_numeric($current) && is_numeric($original)
243 1
            && strcmp((string) $current, (string) $original) === 0;
244
    }
245
246
    /**
247
     * Check if object is instance of any cassandra object types
248
     *
249
     * @param $obj
250
     * @return bool
251
     */
252 17
    protected function isCassandraObject($obj)
253
    {
254 17
        if ($obj instanceof \Cassandra\Uuid ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Uuid 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
255 17
            $obj instanceof \Cassandra\Date ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Date 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
256 17
            $obj instanceof \Cassandra\Float ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Float 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
257 17
            $obj instanceof \Cassandra\Decimal ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Decimal 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
258 17
            $obj instanceof \Cassandra\Timestamp ||
0 ignored issues
show
Bug introduced by
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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
259 17
            $obj instanceof \Cassandra\Inet ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Inet 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
260 17
            $obj instanceof \Cassandra\Time
0 ignored issues
show
Bug introduced by
The class Cassandra\Time 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
261
        ) {
262
            return true;
263
        } else {
264 17
            return false;
265
        }
266
    }
267
268
    /**
269
     * Check if object is instance of any cassandra object types
270
     *
271
     * @param $obj
272
     * @return bool
273
     */
274
    protected function isCompareableCassandraObject($obj)
275
    {
276
        if ($obj instanceof \Cassandra\Uuid ||
0 ignored issues
show
Bug introduced by
The class Cassandra\Uuid 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
277
            $obj instanceof \Cassandra\Inet
0 ignored issues
show
Bug introduced by
The class Cassandra\Inet 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 dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
278
        ) {
279
            return true;
280
        } else {
281
            return false;
282
        }
283
    }
284
285
    /**
286
     * Returns comparable value from cassandra object type
287
     *
288
     * @param $obj
289
     * @return mixed
290
     */
291
    protected function valueFromCassandraObject($obj)
292
    {
293
        $class = get_class($obj);
294
        $value = '';
295
        switch ($class) {
296
            case 'Cassandra\Date':
297
                $value = $obj->seconds();
298
                break;
299
            case 'Cassandra\Time':
300
                $value = $obj->__toString();
301
                break;
302
            case 'Cassandra\Timestamp':
303
                $value = $obj->time();
304
                break;
305
            case 'Cassandra\Float':
306
                $value = $obj->value();
307
                break;
308
            case 'Cassandra\Decimal':
309
                $value = $obj->value();
310
                break;
311
            case 'Cassandra\Inet':
312
                $value = $obj->address();
313
                break;
314
            case 'Cassandra\Uuid':
315
                $value = $obj->uuid();
316
                break;
317
        }
318
319
        return $value;
320
    }
321
322
    /**
323
     * Get the value of the model's primary key.
324
     *
325
     * @return mixed
326
     */
327 16
    public function getKey()
328
    {
329 16
        $value = $this->getAttribute($this->getKeyName());
330 16
        if ($this->isCassandraObject($value)) {
331
            return $this->valueFromCassandraObject($this->getAttribute($this->getKeyName()));
332
        }
333
334 16
        return $value;
335
    }
336
337
}
338