Completed
Push — inspector_ng ( 972652 )
by grégoire
03:53
created

InspectorTrait   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A executeSql() 0 14 1
1
<?php
2
/*
3
 * This file is part of the Pomm package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Inspector;
11
12
use PommProject\Foundation\Where;
13
use PommProject\Foundation\ConvertedResultIterator;
14
15
/**
16
 * InspectorTrait
17
 *
18
 * Common fonctions for inspectors.
19
 *
20
 * @package     Pomm
21
 * @copyright   2015 Grégoire HUBERT
22
 * @author      Grégoire HUBERT
23
 * @license     X11 {@link http://opensource.org/licenses/mit-license.php}
24
 */
25
trait InspectorTrait
26
{
27
28
    /**
29
     * executeSql
30
     *
31
     * Launch query execution expanding string {condition} with the Where query
32
     * parameter and values.
33
     *
34
     * @param  string         $sql
35
     * @param  Where          $condition
36
     * @return ConvertedResultIterator
37
     */
38
    protected function executeSql($sql, Where $condition = null)
39
    {
40
        $condition = (new Where())->andWhere($condition);
41
        $sql = strtr($sql, ['{condition}' => $condition]);
42
43
        return $this
0 ignored issues
show
Bug introduced by
It seems like getSession() 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...
44
            ->getSession()
45
            ->getClientUsingPooler(
46
                'query_manager',
47
                null
48
            )
49
            ->query($sql, $condition->getValues())
50
            ;
51
    }
52
}
53