Passed
Push — master ( 39e4c0...d4ca25 )
by Michael
03:36
created

RepositoryProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 41.03 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 16
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerRepository() 8 8 2
A getRepository() 8 8 2

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
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Mapper\Handler\LinkRepository;
5
6
/**
7
 * Provider of link repositories
8
 *
9
 * @package Mikemirten\Component\JsonApi\Mapper\Handler\LinkRepository
10
 */
11
class RepositoryProvider
12
{
13
    /**
14
     * Repositories
15
     *
16
     * @var RepositoryInterface[]
17
     */
18
    protected $repositories;
19
20
    /**
21
     * Register links' repository
22
     *
23
     * @param string              $name
24
     * @param RepositoryInterface $repository
25
     */
26 2 View Code Duplication
    public function registerRepository(string $name, RepositoryInterface $repository)
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...
27
    {
28 2
        if (isset($this->repositories[$name])) {
29 1
            throw new \LogicException(sprintf('Links\' Repository "%s" is already registered.', $name));
30
        }
31
32 2
        $this->repositories[$name] = $repository;
33 2
    }
34
35
    /**
36
     * Get links' repository by name
37
     *
38
     * @param  string $name
39
     * @return RepositoryInterface
40
     */
41 2 View Code Duplication
    public function getRepository(string $name): RepositoryInterface
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...
42
    {
43 2
        if (isset($this->repositories[$name])) {
44 1
            return $this->repositories[$name];
45
        }
46
47 1
        throw new \LogicException(sprintf('Unknown repository "%s"', $name));
48
    }
49
}