MiscManager::getEvents()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 24
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 4.0378

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 24
loc 24
ccs 13
cts 15
cp 0.8667
rs 8.6845
cc 4
eloc 13
nc 4
nop 2
crap 4.0378
1
<?php
2
3
namespace Docker\Manager;
4
5
use Docker\API\Model\Event;
6
use Docker\API\Resource\MiscResource;
7
use Docker\Stream\EventStream;
8
9
class MiscManager extends MiscResource
10
{
11
    const FETCH_STREAM = 'stream';
12
13
    /**
14
     * {@inheritdoc}
15
     */
16 2 View Code Duplication
    public function getEvents($parameters = [], $fetch = self::FETCH_OBJECT)
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...
17
    {
18 2
        $response = parent::getEvents($parameters, self::FETCH_RESPONSE);
19
20 2
        if (200 === $response->getStatusCode()) {
21 2
            if (self::FETCH_STREAM === $fetch) {
22 1
                return new EventStream($response->getBody(), $this->serializer);
23
            }
24
25 1
            if (self::FETCH_OBJECT === $fetch) {
26 1
                $eventList = [];
27
28 1
                $stream = new EventStream($response->getBody(), $this->serializer);
29 1
                $stream->onFrame(function (Event $event) use (&$eventList) {
30 1
                    $eventList[] = $event;
31 1
                });
32 1
                $stream->wait();
33
34 1
                return $eventList;
35
            }
36
        }
37
38
        return $response;
39
    }
40
}
41