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.
Completed
Push — develop ( d40077...e71353 )
by Baptiste
03:40
created

Generic::replyTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Model\Basic\Message;
5
6
use Innmind\AMQP\Model\Basic\Message;
7
use Innmind\TimeContinuum\{
8
    PointInTimeInterface,
9
    ElapsedPeriod
10
};
11
use Innmind\Immutable\{
12
    MapInterface,
13
    Str
14
};
15
16
final class Generic implements Message
17
{
18
    private $contentType;
19
    private $contentEncoding;
20
    private $headers;
21
    private $deliveryMode;
22
    private $priority;
23
    private $correlationId;
24
    private $replyTo;
25
    private $expiration;
26
    private $id;
27
    private $timestamp;
28
    private $type;
29
    private $userId;
30
    private $appId;
31
    private $body;
32
33 22
    public function __construct(Str $body)
34
    {
35 22
        $this->body = $body->toEncoding('ASCII');
36 22
    }
37
38 9
    public function hasContentType(): bool
39
    {
40 9
        return $this->contentType instanceof ContentType;
41
    }
42
43 2
    public function contentType(): ContentType
44
    {
45 2
        return $this->contentType;
46
    }
47
48 2
    public function withContentType(ContentType $contentType): Message
49
    {
50 2
        $self = clone $this;
51 2
        $self->contentType = $contentType;
52
53 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withContentType 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...
54
    }
55
56 9
    public function hasContentEncoding(): bool
57
    {
58 9
        return $this->contentEncoding instanceof ContentEncoding;
59
    }
60
61 2
    public function contentEncoding(): ContentEncoding
62
    {
63 2
        return $this->contentEncoding;
64
    }
65
66 2
    public function withContentEncoding(ContentEncoding $contentEncoding): Message
67
    {
68 2
        $self = clone $this;
69 2
        $self->contentEncoding = $contentEncoding;
70
71 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic...ge::withContentEncoding 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...
72
    }
73
74 9
    public function hasHeaders(): bool
75
    {
76 9
        return $this->headers instanceof MapInterface;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 2
    public function headers(): MapInterface
83
    {
84 2
        return $this->headers;
85
    }
86
87 3
    public function withHeaders(MapInterface $headers): Message
88
    {
89
        if (
90 3
            (string) $headers->keyType() !== 'string' ||
91 3
            (string) $headers->valueType() !== 'mixed'
92
        ) {
93 1
            throw new \TypeError('Argument 1 must be of type MapInterface<string, mixed>');
1 ignored issue
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with 'Argument 1 must be of t...terface<string, mixed>'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
94
        }
95
96 2
        $self = clone $this;
97 2
        $self->headers = $headers;
98
99 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withHeaders 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...
100
    }
101
102 9
    public function hasDeliveryMode(): bool
103
    {
104 9
        return $this->deliveryMode instanceof DeliveryMode;
105
    }
106
107 2
    public function deliveryMode(): DeliveryMode
108
    {
109 2
        return $this->deliveryMode;
110
    }
111
112 2
    public function withDeliveryMode(DeliveryMode $deliveryMode): Message
113
    {
114 2
        $self = clone $this;
115 2
        $self->deliveryMode = $deliveryMode;
116
117 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withDeliveryMode 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...
118
    }
119
120 9
    public function hasPriority(): bool
121
    {
122 9
        return $this->priority instanceof Priority;
123
    }
124
125 2
    public function priority(): Priority
126
    {
127 2
        return $this->priority;
128
    }
129
130 2
    public function withPriority(Priority $priority): Message
131
    {
132 2
        $self = clone $this;
133 2
        $self->priority = $priority;
134
135 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withPriority 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...
136
    }
137
138 9
    public function hasCorrelationId(): bool
139
    {
140 9
        return $this->correlationId instanceof CorrelationId;
141
    }
142
143 2
    public function correlationId(): CorrelationId
144
    {
145 2
        return $this->correlationId;
146
    }
147
148 2
    public function withCorrelationId(CorrelationId $correlationId): Message
149
    {
150 2
        $self = clone $this;
151 2
        $self->correlationId = $correlationId;
152
153 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic...sage::withCorrelationId 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...
154
    }
155
156 9
    public function hasReplyTo(): bool
157
    {
158 9
        return $this->replyTo instanceof ReplyTo;
159
    }
160
161 2
    public function replyTo(): ReplyTo
162
    {
163 2
        return $this->replyTo;
164
    }
165
166 2
    public function withReplyTo(ReplyTo $replyTo): Message
167
    {
168 2
        $self = clone $this;
169 2
        $self->replyTo = $replyTo;
170
171 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withReplyTo 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...
172
    }
173
174 9
    public function hasExpiration(): bool
175
    {
176 9
        return $this->expiration instanceof ElapsedPeriod;
177
    }
178
179 2
    public function expiration(): ElapsedPeriod
180
    {
181 2
        return $this->expiration;
182
    }
183
184 2
    public function withExpiration(ElapsedPeriod $expiration): Message
185
    {
186 2
        $self = clone $this;
187 2
        $self->expiration = $expiration;
188
189 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withExpiration 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...
190
    }
191
192 9
    public function hasId(): bool
193
    {
194 9
        return $this->id instanceof Id;
195
    }
196
197 2
    public function id(): Id
198
    {
199 2
        return $this->id;
200
    }
201
202 2
    public function withId(Id $id): Message
203
    {
204 2
        $self = clone $this;
205 2
        $self->id = $id;
206
207 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withId 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...
208
    }
209
210 9
    public function hasTimestamp(): bool
211
    {
212 9
        return $this->timestamp instanceof PointInTimeInterface;
213
    }
214
215 2
    public function timestamp(): PointInTimeInterface
216
    {
217 2
        return $this->timestamp;
218
    }
219
220 2
    public function withTimestamp(PointInTimeInterface $timestamp): Message
221
    {
222 2
        $self = clone $this;
223 2
        $self->timestamp = $timestamp;
224
225 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withTimestamp 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...
226
    }
227
228 9
    public function hasType(): bool
229
    {
230 9
        return $this->type instanceof Type;
231
    }
232
233 2
    public function type(): Type
234
    {
235 2
        return $this->type;
236
    }
237
238 2
    public function withType(Type $type): Message
239
    {
240 2
        $self = clone $this;
241 2
        $self->type = $type;
242
243 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withType 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...
244
    }
245
246 9
    public function hasUserId(): bool
247
    {
248 9
        return $this->userId instanceof UserId;
249
    }
250
251 2
    public function userId(): UserId
252
    {
253 2
        return $this->userId;
254
    }
255
256 2
    public function withUserId(UserId $userId): Message
257
    {
258 2
        $self = clone $this;
259 2
        $self->userId = $userId;
260
261 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withUserId 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...
262
    }
263
264 9
    public function hasAppId(): bool
265
    {
266 9
        return $this->appId instanceof AppId;
267
    }
268
269 2
    public function appId(): AppId
270
    {
271 2
        return $this->appId;
272
    }
273
274 2
    public function withAppId(AppId $appId): Message
275
    {
276 2
        $self = clone $this;
277 2
        $self->appId = $appId;
278
279 2
        return $self;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $self; (Innmind\AMQP\Model\Basic\Message\Generic) is incompatible with the return type declared by the interface Innmind\AMQP\Model\Basic\Message::withAppId 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...
280
    }
281
282 8
    public function body(): Str
283
    {
284 8
        return $this->body;
285
    }
286
}
287