1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the BazingaGeocoderBundle package. |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @license MIT License |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Bazinga\GeocoderBundle\DataCollector; |
12
|
|
|
|
13
|
|
|
use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
17
|
|
|
|
18
|
1 |
|
if (Kernel::VERSION_ID >= 40308) { |
19
|
|
View Code Duplication |
trait DataCollectorSymfonyCompatibilityTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function collect(Request $request, Response $response, \Throwable $exception = null) |
25
|
|
|
{ |
26
|
|
|
if (!empty($this->data['queries'])) { |
27
|
|
|
// To avoid collection more that once. |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @var ProfilingPlugin[] $instances */ |
32
|
|
|
$instances = $this->instances; |
33
|
|
|
|
34
|
|
|
foreach ($instances as $instance) { |
35
|
|
|
foreach ($instance->getQueries() as $query) { |
36
|
|
|
$query['query'] = $this->cloneVar($query['query']); |
37
|
|
|
$query['result'] = $this->cloneVar($query['result']); |
38
|
|
|
$this->data['queries'][] = $query; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} else { |
44
|
|
View Code Duplication |
trait DataCollectorSymfonyCompatibilityTrait |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
50
|
|
|
{ |
51
|
|
|
if (!empty($this->data['queries'])) { |
52
|
|
|
// To avoid collection more that once. |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @var ProfilingPlugin[] $instances */ |
57
|
|
|
$instances = $this->instances; |
58
|
|
|
|
59
|
|
|
foreach ($instances as $instance) { |
60
|
|
|
foreach ($instance->getQueries() as $query) { |
61
|
|
|
$query['query'] = $this->cloneVar($query['query']); |
62
|
|
|
$query['result'] = $this->cloneVar($query['result']); |
63
|
|
|
$this->data['queries'][] = $query; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.