QueryTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 33
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchOneFromQuery() 0 6 1
A runSqlQuery() 0 9 1
1
<?php
2
3
namespace ByTIC\Codeception\Helper\Traits;
4
5
use Codeception\Module\Db;
6
7
/**
8
 * Class QueryTrait
9
 * @package ByTIC\Common\Tests\Helper\Traits
10
 */
11
trait QueryTrait
12
{
13
    use AbstractTrait;
14
15
    /**
16
     * @param $query
17
     *
18
     * @return mixed
19
     * @throws \Codeception\Exception\ModuleException
20
     */
21
    public function fetchOneFromQuery($query)
22
    {
23
        $result = $this->runSqlQuery($query);
24
25
        return $result->fetch();
26
    }
27
28
    /**
29
     * @param $query
30
     *
31
     * @return mixed
32
     * @throws \Codeception\Exception\ModuleException
33
     */
34
    public function runSqlQuery($query)
35
    {
36
        /** @var Db $dbModule */
37
        $dbModule = $this->getModule("Db");
38
        /** @var \PDO $dbh */
39
        $dbh = $dbModule->dbh;
0 ignored issues
show
Bug introduced by
The property dbh does not seem to exist in Codeception\Module\Db.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
40
41
        return $dbh->query($query);
42
    }
43
}
44