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

ProfilingProvider::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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