Completed
Push — master ( a814e0...392de1 )
by Tobias
24:09
created

ProfilingProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 51.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 36
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A geocodeQuery() 18 18 1
A reverseQuery() 18 18 1
A __call() 0 4 1
A getName() 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 Bazinga\Bundle\GeocoderBundle\DataCollector;
4
5
use Bazinga\Bundle\GeocoderBundle\Logger\GeocoderLogger;
6
use Geocoder\Collection;
7
use Geocoder\Provider\Provider;
8
use Geocoder\Query\GeocodeQuery;
9
use Geocoder\Query\ReverseQuery;
10
11
/**
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class ProfilingProvider implements Provider
15
{
16
    /**
17
     * @var Provider
18
     */
19
    private $realProvider;
20
21
    /**
22
     * @var GeocoderLogger
23
     */
24
    private $logger;
25
26
    /**
27
     * @param Provider       $realProvider
28
     * @param GeocoderLogger $logger
29
     */
30
    public function __construct(Provider $realProvider, GeocoderLogger $logger)
31
    {
32
        $this->realProvider = $realProvider;
33
        $this->logger = $logger;
34
    }
35
36 View Code Duplication
    public function geocodeQuery(GeocodeQuery $query): Collection
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...
37
    {
38
        $startTime = microtime(true);
39
        try {
40
            $results = $this->realProvider->geocodeQuery($query);
41
        } finally {
42
            $duration = (microtime(true) - $startTime) * 1000;
43
44
            $this->logger->logRequest(
45
                sprintf('[Geocoding] %s', $query),
46
                $duration,
47
                $this->getName(),
48
                $results
49
            );
50
        }
51
52
        return $results;
53
    }
54
55 View Code Duplication
    public function reverseQuery(ReverseQuery $query): Collection
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...
56
    {
57
        $startTime = microtime(true);
58
        try {
59
            $results = $this->realProvider->reverseQuery($query);
60
        } finally {
61
            $duration = (microtime(true) - $startTime) * 1000;
62
63
            $this->logger->logRequest(
64
                sprintf('[Geocoding] %s', $query),
65
                $duration,
66
                $this->getName(),
67
                $results
68
            );
69
        }
70
71
        return $results;
72
    }
73
74
    public function __call($method, $args)
75
    {
76
        return call_user_func_array([$this->realProvider, $method], $args);
77
    }
78
79
    public function getName(): string
80
    {
81
        return $this->realProvider->getName();
82
    }
83
}
84