LoaderFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 48.28 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 4
dl 28
loc 58
ccs 27
cts 27
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B make() 28 28 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
3
namespace Innmind\RestBundle\Client;
4
5
use Innmind\Rest\Client\Definition\Loader;
6
use Innmind\Rest\Client\Definition\Builder;
7
use Innmind\Rest\Client\Cache\FileCache;
8
use Innmind\UrlResolver\ResolverInterface;
9
use Symfony\Component\Validator\Validator\ValidatorInterface;
10
use GuzzleHttp\Client as Http;
11
12
class LoaderFactory
13
{
14
    protected $instances = [];
15
    protected $cacheDir;
16
    protected $resolver;
17
    protected $builder;
18
    protected $http;
19
    protected $validator;
20
21 8
    public function __construct(
22
        $cacheDir,
23
        ResolverInterface $resolver,
24
        Http $http,
25
        ValidatorInterface $validator
26
    ) {
27 8
        $this->cacheDir = (string) $cacheDir;
28 8
        $this->resolver = $resolver;
29 8
        $this->http = $http;
30 8
        $this->validator = $validator;
31 8
        $this->builder = new Builder;
32 8
    }
33
34
    /**
35
     * Create a loader for a given host
36
     *
37
     * @param string $host
38
     *
39
     * @return Loader
40
     */
41 8 View Code Duplication
    public function make($host)
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 8
        $host = $this->resolver->resolve($host, '/');
44 8
        $hash = md5($host);
45
46 8
        if (isset($this->instances[$hash])) {
47 4
            return $this->instances[$hash];
48
        }
49
50 8
        $dir = sprintf(
51 8
            '%s/%s',
52 8
            rtrim($this->cacheDir, '/'),
53
            $hash
54 8
        );
55 8
        $instance = new Loader(
56 8
            new FileCache(sprintf(
57 8
                '%s/definitions.php',
58
                $dir
59 8
            )),
60 8
            $this->resolver,
61 8
            $this->builder,
62 8
            $this->http,
63 8
            $this->validator
64 8
        );
65 8
        $this->instances[$hash] = $instance;
66
67 8
        return $instance;
68
    }
69
}
70