Connection::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 0
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ExtendedPdo;
8
use SensitiveParameter;
0 ignored issues
show
Bug introduced by
The type SensitiveParameter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
final class Connection
11
{
12
    private ?ExtendedPdo $pdo = null;
13
14
    /**
15
     * @phpstan-param array<string> $options
16
     * @phpstan-param array<string> $queries
17
     */
18
    public function __construct(
19
        private readonly string $dsn,
20
        private readonly string $username = '',
21
        #[SensitiveParameter]
22
        private readonly string $password = '',
23
        /** @var array<string> */
24
        private readonly array $options = [],
25
        /** @var array<string> */
26
        private readonly array $queries = []
27
    ) {
28
    }
29
30
    public function __invoke(): ExtendedPdo
31
    {
32
        if ($this->pdo instanceof ExtendedPdo) {
33
            return $this->pdo;
34
        }
35
36
        $this->pdo = new ExtendedPdo($this->dsn, $this->username, $this->password, $this->options, $this->queries);
37
38
        return $this->pdo;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->pdo returns the type null which is incompatible with the type-hinted return Aura\Sql\ExtendedPdo.
Loading history...
39
    }
40
}
41