Completed
Push — master ( b5db7c...f58f47 )
by Tobias
01:02
created

TimedGeocoder.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder;
14
15
use Geocoder\Query\GeocodeQuery;
16
use Geocoder\Query\ReverseQuery;
17
use Geocoder\Provider\Provider;
18
use Symfony\Component\Stopwatch\Stopwatch;
19
20
/**
21
 * This Geocoder allows you to profile your API/Database calls.
22
 *
23
 * @author Markus Bachmann <[email protected]>
24
 */
25
final class TimedGeocoder implements Geocoder
26
{
27 1
    use GeocoderTrait;
28
29
    /**
30
     * @var Provider
31
     */
32
    private $delegate;
33
34
    /**
35
     * @var Stopwatch
36
     */
37
    private $stopwatch;
38
39 4
    public function __construct(Provider $delegate, Stopwatch $stopwatch)
40
    {
41 4
        $this->delegate = $delegate;
42 4
        $this->stopwatch = $stopwatch;
43 4
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2 View Code Duplication
    public function geocodeQuery(GeocodeQuery $query): Collection
0 ignored issues
show
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...
49
    {
50 2
        $this->stopwatch->start('geocode', 'geocoder');
51
52
        try {
53 2
            $result = $this->delegate->geocodeQuery($query);
54 1
        } catch (\Throwable $e) {
55 1
            $this->stopwatch->stop('geocode');
56
57 1
            throw $e;
58
        }
59
60 1
        $this->stopwatch->stop('geocode');
61
62 1
        return $result;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 2 View Code Duplication
    public function reverseQuery(ReverseQuery $query): Collection
0 ignored issues
show
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...
69
    {
70 2
        $this->stopwatch->start('reverse', 'geocoder');
71
72
        try {
73 2
            $result = $this->delegate->reverseQuery($query);
74 1
        } catch (\Throwable $e) {
75 1
            $this->stopwatch->stop('reverse');
76
77 1
            throw $e;
78
        }
79
80 1
        $this->stopwatch->stop('reverse');
81
82 1
        return $result;
83
    }
84
85
    public function __call($method, $args)
86
    {
87
        return call_user_func_array([$this->delegate, $method], $args);
88
    }
89
90
    public function getName(): string
91
    {
92
        return 'timed_geocoder';
93
    }
94
}
95