Passed
Pull Request — master (#43)
by
unknown
02:37
created

AbstractApiClient::getVideoManagers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace MovingImage\Client\VMPro\ApiClient;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use MovingImage\Client\VMPro\Collection\ChannelCollection;
7
use MovingImage\Client\VMPro\Collection\VideoCollection;
8
use MovingImage\Client\VMPro\Entity\Channel;
9
use MovingImage\Client\VMPro\Entity\ChannelsRequestParameters;
10
use MovingImage\Client\VMPro\Entity\EmbedCode;
11
use MovingImage\Client\VMPro\Entity\Keyword;
12
use MovingImage\Client\VMPro\Entity\Video;
13
use MovingImage\Client\VMPro\Entity\Attachment;
14
use MovingImage\Client\VMPro\Entity\VideoManager;
15
use MovingImage\Client\VMPro\Entity\VideoRequestParameters;
16
use MovingImage\Client\VMPro\Entity\VideosRequestParameters;
17
use MovingImage\Client\VMPro\Interfaces\ApiClientInterface;
18
use MovingImage\Client\VMPro\Util\ChannelTrait;
19
use MovingImage\Client\VMPro\Util\Logging\Traits\LoggerAwareTrait;
20
use MovingImage\Client\VMPro\Util\SearchEndpointTrait;
21
22
/**
23
 * Class AbstractApiClient.
24
 *
25
 * @author Ruben Knol <[email protected]>
26
 * @author Omid Rad <[email protected]>
27
 */
28
abstract class AbstractApiClient extends AbstractCoreApiClient implements ApiClientInterface
29
{
30
    use LoggerAwareTrait;
31
    use SearchEndpointTrait;
32
    use ChannelTrait;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getChannels($videoManagerId)
38
    {
39
        $response = $this->makeRequest('GET', 'channels', [
40
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
41
        ]);
42
43
        $rootChannel = $this->deserialize($response->getBody(), Channel::class);
44
        $rootChannel->setChildren($this->sortChannels($rootChannel->getChildren()));
45
46
        return $rootChannel;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $rootChannel; (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...tInterface::getChannels of type MovingImage\Client\VMPro\Entity\Channel.

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...
47
    }
48
49
    /**
50
     * Since the VMPro API doesn't sort any more the returned channels, we have to do it on our side.
51
     *
52
     * @param ArrayCollection $channels
53
     *
54
     * @return ArrayCollection
55
     */
56
    protected function sortChannels(ArrayCollection $channels)
57
    {
58
        $channels->map(function ($channel) {
59
            $channel->setChildren($this->sortChannels($channel->getChildren()));
60
        });
61
62
        $iterator = $channels->getIterator();
63
        $iterator->uasort(function ($a, $b) {
64
            return $a->getName() > $b->getName();
65
        });
66
67
        return new ArrayCollection(iterator_to_array($iterator));
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function createVideo(
74
        $videoManagerId,
75
        $fileName,
76
        $title = '',
77
        $description = '',
78
        $channel = null,
79
        $group = null,
80
        array $keywords = [],
81
        $autoPublish = null
82
    ) {
83
        $response = $this->makeRequest('POST', 'videos', [
84
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
85
            'json' => $this->buildJsonParameters(
86
                compact('fileName'), // Required parameters
87
                compact('title', 'description', 'channel', 'group', 'keywords', 'autoPublish') // Optional parameters
88
            ),
89
        ]);
90
91
        // Guzzle 5+6 co-compatibility - Guzzle 6 for some reason
92
        // wraps headers in arrays.
93
        $videoLocation = is_array($response->getHeader('location'))
94
            ? $response->getHeader('location')[0]
95
            : $response->getHeader('location');
96
97
        $pieces = explode('/', $videoLocation);
98
99
        return end($pieces);
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getVideos($videoManagerId, VideosRequestParameters $parameters = null)
106
    {
107
        $options = [
108
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
109
        ];
110
111
        if ($parameters) {
112
            $options['query'] = $parameters->getContainer();
113
        }
114
115
        $response = $this->makeRequest('GET', 'videos', $options);
116
        $response = json_encode(json_decode($response->getBody()->getContents(), true)['videos']);
117
118
        return $this->deserialize($response, 'ArrayCollection<'.Video::class.'>');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deserializ...ty\Video::class . '>'); (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...entInterface::getVideos of type MovingImage\Meta\Interfaces\VideoInterface[].

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...
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 View Code Duplication
    public function getCount($videoManagerId, VideosRequestParameters $parameters = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        $options = [
127
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
128
        ];
129
130
        if ($parameters) {
131
            $options['query'] = $parameters->getContainer();
132
        }
133
134
        $response = $this->makeRequest('GET', 'videos', $options);
135
136
        return json_decode($response->getBody()->getContents(), true)['total'];
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    public function getVideoUploadUrl($videoManagerId, $videoId)
143
    {
144
        $response = $this->makeRequest('GET', sprintf('videos/%s/url', $videoId), [
145
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
146
        ]);
147
148
        // Guzzle 5+6 co-compatibility - Guzzle 6 for some reason
149
        // wraps headers in arrays.
150
        return is_array($response->getHeader('location'))
151
            ? $response->getHeader('location')[0]
152
            : $response->getHeader('location');
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function updateVideo($videoManagerId, $videoId, $title, $description)
159
    {
160
        $this->makeRequest('PATCH', sprintf('videos/%s', $videoId), [
161
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
162
            'json' => $this->buildJsonParameters([], compact('title', 'description')),
163
        ]);
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function addVideoToChannel($videoManagerId, $videoId, $channelId)
170
    {
171
        $this->makeRequest('POST', sprintf('channels/%s/videos/%s', $channelId, $videoId), [
172
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
173
        ]);
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179
    public function setCustomMetaData($videoManagerId, $videoId, $metadata)
180
    {
181
        $this->makeRequest('PATCH', sprintf('videos/%s/metadata', $videoId), [
182
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
183
            'json' => $metadata,
184
        ]);
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190
    public function getEmbedCode($videoManagerId, $videoId, $playerDefinitionId, $embedType = 'html')
191
    {
192
        $url = sprintf(
193
            'videos/%s/embed-codes?player_definition_id=%s&embed_type=%s',
194
            $videoId,
195
            $playerDefinitionId,
196
            $embedType
197
        );
198
199
        if ($this->cacheTtl) {
200
            $url = sprintf('%s&token_lifetime_in_seconds=%s', $url, $this->cacheTtl);
201
        }
202
203
        $response = $this->makeRequest('GET', $url, [self::OPT_VIDEO_MANAGER_ID => $videoManagerId]);
204
205
        $data = \json_decode($response->getBody(), true);
206
        $embedCode = new EmbedCode();
207
        $embedCode->setCode($data['embedCode']);
208
209
        return $embedCode;
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215
    public function deleteVideo($videoManagerId, $videoId)
216
    {
217
        $this->makeRequest('DELETE', sprintf('videos/%s', $videoId), [
218
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
219
        ]);
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225 View Code Duplication
    public function getVideo($videoManagerId, $videoId, VideoRequestParameters $parameters = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
    {
227
        $options = [
228
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
229
        ];
230
231
        if ($parameters) {
232
            $options['query'] = $parameters->getContainer();
233
        }
234
235
        $response = $this->makeRequest(
236
            'GET',
237
            sprintf('videos/%s', $videoId),
238
            $options
239
        );
240
241
        return $this->deserialize($response->getBody()->getContents(), Video::class);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deserializ...o\Entity\Video::class); (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...ientInterface::getVideo of type MovingImage\Client\VMPro\Entity\Video.

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...
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247 View Code Duplication
    public function getAttachments($videoManagerId, $videoId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
248
    {
249
        $response = $this->makeRequest(
250
            'GET',
251
            sprintf('videos/%s/attachments', $videoId),
252
            [self::OPT_VIDEO_MANAGER_ID => $videoManagerId]
253
        );
254
255
        return $this->deserialize($response->getBody()->getContents(), 'ArrayCollection<'.Attachment::class.'>');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deserializ...tachment::class . '>'); (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...terface::getAttachments of type MovingImage\Client\VMPro\Entity\Attachment[].

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...
256
    }
257
258
    /**
259
     * {@inheritdoc}
260
     */
261 View Code Duplication
    public function getKeywords($videoManagerId, $videoId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
    {
263
        $response = $this->makeRequest(
264
            'GET',
265
            sprintf('videos/%s/keywords', $videoId),
266
            [self::OPT_VIDEO_MANAGER_ID => $videoManagerId]
267
        );
268
269
        return $this->deserialize($response->getBody()->getContents(), 'ArrayCollection<'.Keyword::class.'>');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deserializ...\Keyword::class . '>'); (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...tInterface::getKeywords of type MovingImage\Client\VMPro\Entity\Keyword[].

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...
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function updateKeywords($videoManagerId, $videoId, $keywords)
276
    {
277
        //remove all keywords
278
        foreach ($this->getKeywords($videoManagerId, $videoId) as $keyword) {
0 ignored issues
show
Bug introduced by
The expression $this->getKeywords($videoManagerId, $videoId) of type object|array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
279
            $this->deleteKeyword($videoManagerId, $videoId, $keyword->getId());
280
        }
281
282
        //add new
283
        foreach ($keywords as $keyword) {
284
            $this->makeRequest('POST', sprintf('videos/%s/keywords', $videoId), [
285
                self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
286
                'json' => ['text' => $keyword],
287
            ]);
288
        }
289
    }
290
291
    /**
292
     * {@inheritdoc}
293
     */
294
    public function deleteKeyword($videoManagerId, $videoId, $keywordId)
295
    {
296
        $this->makeRequest('DELETE', sprintf('videos/%s/keywords/%s', $videoId, $keywordId), [
297
            self::OPT_VIDEO_MANAGER_ID => $videoManagerId,
298
        ]);
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304
    public function searchVideos($videoManagerId, VideosRequestParameters $parameters = null)
305
    {
306
        $options = $this->getRequestOptionsForSearchVideosEndpoint($videoManagerId, $parameters);
307
        $response = $this->makeRequest('POST', 'search', ['json' => $options]);
308
        $response = $this->normalizeSearchVideosResponse($response->getBody()->getContents());
309
310
        $collection = $this->deserialize($response, VideoCollection::class);
311
312
        return $collection;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $collection; (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...Interface::searchVideos of type MovingImage\Client\VMPro...lection\VideoCollection.

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...
313
    }
314
315
    /**
316
     * {@inheritdoc}
317
     */
318
    public function searchChannels($videoManagerId, ChannelsRequestParameters $parameters = null)
319
    {
320
        $options = $this->getRequestOptionsForSearchChannelsEndpoint($videoManagerId, $parameters);
321
        $response = $this->makeRequest('POST', 'search', ['json' => $options]);
322
        $response = $this->normalizeSearchChannelsResponse($response->getBody()->getContents());
323
        /** @var ChannelCollection $collection */
324
        $collection = $this->deserialize($response, ChannelCollection::class);
325
326
        //builds parent/children relations on all channels
327
        $channels = $this->setChannelRelations($collection->getChannels());
0 ignored issues
show
Documentation introduced by
$collection->getChannels() is of type array<integer,object<Mov...aces\ChannelInterface>>, but the function expects a array<integer,object<Mov...\VMPro\Entity\Channel>>.

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...
328
        $collection->setChannels($channels);
329
330
        return $collection;
331
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336
    public function getVideoManagers()
337
    {
338
        $response = $this->makeRequest('GET', '', []);
339
340
        return $this->deserialize($response->getBody()->getContents(), 'ArrayCollection<'.VideoManager::class.'>');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deserializ...oManager::class . '>'); (object|array|integer|double|string|boolean) is incompatible with the return type declared by the interface MovingImage\Client\VMPro...rface::getVideoManagers of type MovingImage\Client\VMPro\Entity\VideoManager[].

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...
341
    }
342
}
343