AuraSqlQuerySelectProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 5
c 1
b 0
f 1
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\SqlQuery\Common\SelectInterface;
8
use Aura\SqlQuery\QueryFactory;
9
use Ray\AuraSqlModule\Annotation\AuraSqlQueryConfig;
10
use Ray\Di\ProviderInterface;
11
12
/** @implements ProviderInterface<SelectInterface> */
13
class AuraSqlQuerySelectProvider implements ProviderInterface
14
{
15
    private string $db;
16
17
    /**
18
     * @param string $db The database type
19
     *
20
     * @AuraSqlQueryConfig
21
     */
22
    #[AuraSqlQueryConfig()]
23
    public function __construct($db)
24
    {
25
        $this->db = $db;
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function get(): SelectInterface
32
    {
33
        return (new QueryFactory($this->db))->newSelect();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Aura\SqlQuery...$this->db)->newSelect() returns the type Aura\SqlQuery\Common\SelectInterface which is incompatible with the return type mandated by Ray\Di\ProviderInterface::get() of Ray\Di\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
34
    }
35
}
36