Database::query()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
c 0
b 0
f 0
nc 5
nop 1
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 3
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Edyan\Neuralyzer\Service;
6
7
use Edyan\Neuralyzer\Exception\NeuralyzerException;
8
use Edyan\Neuralyzer\Utils\DBUtils;
9
10
/**
11
 * Class Database to inject in expression language
12
 */
13
class Database implements ServiceInterface
14
{
15
    /**
16
     * @var DBUtils
17
     */
18
    private $dbUtils;
19
20
    /**
21
     * Used for auto wiring
22
     */
23 53
    public function __construct(DBUtils $dbUtils)
24
    {
25 53
        $this->dbUtils = $dbUtils;
26 53
    }
27
28
    /**
29
     * Returns service's name
30
     */
31
    public function getName(): string
32
    {
33 51
        return 'db';
34
    }
35 51
36
    /**
37
     * @throws NeuralyzerException
38
     *
39
     * @return array
40
     */
41
    public function query(string $sql): ?array
42
    {
43
        $conn = $this->dbUtils->getConn();
44
        $sql = trim($sql);
45 7
        try {
46
            $res = $conn->query($sql);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::query() has been deprecated: Use {@link executeQuery()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
            $res = /** @scrutinizer ignore-deprecated */ $conn->query($sql);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47 7
            if (strpos($sql, 'SELECT') === 0) {
48 7
                return $res->fetchAll();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\ResultStatement::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
                return /** @scrutinizer ignore-deprecated */ $res->fetchAll();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
            }
50 7
51 5
            return null;
52 2
        } catch (\Exception $e) {
53
            throw new NeuralyzerException($e->getMessage());
54
        }
55 3
    }
56
}
57