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

QueryTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

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;
40
41
        return $dbh->query($query);
42
    }
43
}
44