Completed
Push — master ( a72680...1055c6 )
by Tomas
16:41 queued 11s
created

DataCollectorSymfonyCompatibilityTrait::collect()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 0
cts 13
cp 0
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 20
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
if (Kernel::VERSION_ID >= 40308) {
19 View Code Duplication
    trait DataCollectorSymfonyCompatibilityTrait
0 ignored issues
show
Duplication introduced by
This class 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...
20
    {
21
        /**
22
         * {@inheritdoc}
23
         */
24
        public function collect(Request $request, Response $response, \Throwable $exception = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
        {
26
            if (!empty($this->data['queries'])) {
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
                // To avoid collection more that once.
28
                return;
29
            }
30
31
            /** @var ProfilingPlugin[] $instances */
32
            $instances = $this->instances;
0 ignored issues
show
Bug introduced by
The property instances does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
            foreach ($instances as $instance) {
35
                foreach ($instance->getQueries() as $query) {
36
                    $query['query'] = $this->cloneVar($query['query']);
0 ignored issues
show
Bug introduced by
It seems like cloneVar() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
37
                    $query['result'] = $this->cloneVar($query['result']);
0 ignored issues
show
Bug introduced by
It seems like cloneVar() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
38
                    $this->data['queries'][] = $query;
39
                }
40
            }
41
        }
42
    }
43
} else {
44 View Code Duplication
    trait DataCollectorSymfonyCompatibilityTrait
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Bazinga\GeocoderBundle\D...mfonyCompatibilityTrait has been defined more than once; this definition is ignored, only the first definition in this file (L19-42) is considered.

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.

Loading history...
Duplication introduced by
This class 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...
45
    {
46
        /**
47
         * {@inheritdoc}
48
         */
49
        public function collect(Request $request, Response $response, \Exception $exception = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
It seems like cloneVar() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
62
                    $query['result'] = $this->cloneVar($query['result']);
0 ignored issues
show
Bug introduced by
It seems like cloneVar() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
                    $this->data['queries'][] = $query;
64
                }
65
            }
66
        }
67
    }
68
}
69