Completed
Pull Request — 1.x (#227)
by Akihito
17:00 queued 06:54
created

NullRequest::hash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
final class NullRequest implements RequestInterface
8
{
9
    /**
10
     * @param array<string, mixed> $query
11
     */
12
    public function __invoke(?array $query = null): ResourceObject
13
    {
14
        return new NullResourceObject();
15 7
    }
16
17 7
    public function hash(): string
18 7
    {
19
        return '';
20 1
    }
21
22 1
    /**
23
     * @return ResourceObject
24
     */
25 1
    public function request()
26
    {
27 1
        return new NullResourceObject();
28
    }
29
30 1
    /**
31
     * {@inheritDoc}
32 1
     */
33
    public function withQuery(array $query): RequestInterface
34
    {
35 1
        unset($query);
36
37 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (BEAR\Resource\NullRequest) is incompatible with the return type declared by the interface BEAR\Resource\RequestInterface::withQuery of type self.

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...
38
    }
39
40 1
    /**
41
     * {@inheritDoc}
42 1
     */
43
    public function addQuery(array $query): RequestInterface
44
    {
45 1
        unset($query);
46
47 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (BEAR\Resource\NullRequest) is incompatible with the return type declared by the interface BEAR\Resource\RequestInterface::addQuery of type self.

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...
48
    }
49
50 1
    public function toUri(): string
51
    {
52 1
        return (string) new NullUri();
53
    }
54
55
    public function toUriWithMethod(): string
56
    {
57
        return 'get ' . (string) new NullUri();
58
    }
59
60
    /**
61
     * @return self
62
     */
63
    public function linkSelf(string $linkKey): RequestInterface
64
    {
65
        unset($linkKey);
66
67
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (BEAR\Resource\NullRequest) is incompatible with the return type declared by the interface BEAR\Resource\RequestInterface::linkSelf of type self.

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...
68
    }
69
70
    /**
71
     * @return self
72
     */
73
    public function linkNew(string $linkKey): RequestInterface
74
    {
75
        unset($linkKey);
76
77
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (BEAR\Resource\NullRequest) is incompatible with the return type declared by the interface BEAR\Resource\RequestInterface::linkNew of type self.

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...
78
    }
79
80
    /**
81
     * @return self
82
     */
83
    public function linkCrawl(string $linkKey): RequestInterface
84
    {
85
        unset($linkKey);
86
87
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (BEAR\Resource\NullRequest) is incompatible with the return type declared by the interface BEAR\Resource\RequestInterface::linkCrawl of type self.

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...
88
    }
89
}
90