GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Model::freshTimestamp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace fuitad\LaravelCassandra\Eloquent;
4
5
use Carbon\Carbon;
6
use Cassandra\Timestamp;
7
use fuitad\LaravelCassandra\Query\Builder as QueryBuilder;
8
use Illuminate\Database\Eloquent\Model as BaseModel;
9
10
abstract class Model extends BaseModel
11
{
12
    /**
13
     * Indicates if the IDs are auto-incrementing.
14
     * This is not possible in cassandra so we override this
15
     *
16
     * @var bool
17
     */
18
    public $incrementing = false;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function newEloquentBuilder($query)
24
    {
25
        return new Builder($query);
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    protected function newBaseQueryBuilder()
32
    {
33
        $connection = $this->getConnection();
34
35
        return new QueryBuilder($connection, $connection->getPostProcessor());
0 ignored issues
show
Compatibility introduced by
$connection of type object<Illuminate\Database\Connection> is not a sub-type of object<fuitad\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...
Compatibility introduced by
$connection->getPostProcessor() of type object<Illuminate\Databa...y\Processors\Processor> is not a sub-type of object<fuitad\LaravelCassandra\Query\Processor>. It seems like you assume a child class of the class Illuminate\Database\Query\Processors\Processor 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...
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function freshTimestamp()
42
    {
43
        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...
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function fromDateTime($value)
50
    {
51
        // If the value is already a Timestamp instance, we don't need to parse it.
52
        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...
53
            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...
54
        }
55
56
        // Let Eloquent convert the value to a DateTime instance.
57
        if (!$value instanceof DateTime) {
0 ignored issues
show
Bug introduced by
The class fuitad\LaravelCassandra\Eloquent\DateTime 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...
58
            $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...
59
        }
60
61
        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...
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67
    protected function asDateTime($value)
68
    {
69
        // Convert UTCDateTime instances.
70
        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...
71
            return Carbon::instance($value->toDateTime());
72
        }
73
74
        return parent::asDateTime($value);
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    protected function originalIsNumericallyEquivalent($key)
81
    {
82
        $current = $this->attributes[$key];
83
        $original = $this->original[$key];
84
85
        // Date comparison.
86
        if (in_array($key, $this->getDates())) {
87
            $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...
88
            $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...
89
90
            return $current == $original;
91
        }
92
93
        return parent::originalIsNumericallyEquivalent($key);
94
    }
95
96
    /**
97
     * Get the table qualified key name.
98
     * Cassandra does not support the table.column annotation so
99
     * we override this
100
     *
101
     * @return string
102
     */
103
    public function getQualifiedKeyName()
104
    {
105
        return $this->getKeyName();
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111
    public function __call($method, $parameters)
112
    {
113
        // Unset method
114
        if ($method == 'unset') {
115
            return call_user_func_array([$this, 'drop'], $parameters);
116
        }
117
118
        return parent::__call($method, $parameters);
119
    }
120
}
121