Database   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A query() 0 13 3
A getName() 0 3 1
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