Completed
Push — master ( c4a119...b5db7c )
by Tobias
01:22
created

TimedGeocoder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 45.71 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 84%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 32
loc 70
ccs 21
cts 25
cp 0.84
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A geocodeQuery() 16 16 2
A reverseQuery() 16 16 2
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
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
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...
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
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...
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