MiscManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 75 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 0
cbo 1
dl 24
loc 32
ccs 13
cts 15
cp 0.8667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getEvents() 24 24 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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