Test Setup Failed
Push — master ( 463f80...c01e84 )
by Gabriel
04:52
created

QueryTrait::runSqlQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
nc 1
cc 1
nop 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;
40
41
        return $dbh->query($query);
42
    }
43
}
44