QueryTrait::fetchOneFromQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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