Completed
Pull Request — master (#1)
by Raymond
03:07
created

PersistentSubscriptionInfoFeed   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 19.57 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 6
lcom 1
cbo 1
dl 9
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A validateLink() 9 9 3
A getPersistentSubscriptionInfo() 0 4 1

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 RayRutjes\GetEventStore\Client\Http\Feed;
4
5
use RayRutjes\GetEventStore\PersistentSubscriptionInfo;
6
7
final class PersistentSubscriptionInfoFeed
8
{
9
    /**
10
     * @var array
11
     */
12
    private $links = [];
13
14
    /**
15
     * @var PersistentSubscriptionInfo
16
     */
17
    private $info;
18
19
    /**
20
     * @param array                      $links
21
     * @param PersistentSubscriptionInfo $info
22
     */
23
    public function __construct(array $links, PersistentSubscriptionInfo $info)
24
    {
25
        foreach ($links as $link) {
26
            $this->validateLink($link);
27
            $this->links[$link->getRelation()] = $link;
28
        }
29
        $this->info = $info;
30
    }
31
32
    /**
33
     * @param $link
34
     */
35 View Code Duplication
    private function validateLink($link)
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...
36
    {
37
        if (!$link instanceof PersistentSubscriptionInfoFeedLink) {
38
            throw new \InvalidArgumentException('Invalid link type %s.', get_class($link));
39
        }
40
        if (isset($this->links[$link->getRelation()])) {
41
            throw new \InvalidArgumentException(sprintf('Link relation %s already there.', $link->getRelation()));
42
        }
43
    }
44
45
    /**
46
     * @return PersistentSubscriptionInfo
47
     */
48
    public function getPersistentSubscriptionInfo(): PersistentSubscriptionInfo
49
    {
50
        return $this->info;
51
    }
52
}
53