Test Failed
Push — master ( eb1d05...b38a80 )
by Carsten
02:29 queued 11s
created

PdoAddressFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
namespace Germania\Addresses;
3
4
class PdoAddressFactory
5
{
6
	/**
7
	 * @var AddressFactory
8
	 */
9
	public $address_factory; 	
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
10
11
	/**
12
	 * @var PDOStmt
13
	 */
14
	public $stmt; 
15
16
	public static $DB_FIELDS = array(
17
		'id',
18
		'type',
19
		'street1',
20
		'street2',
21
		'zip',
22
		'location',
23
		'country'
24
	);
25
26
	/**
27
	 * @param \PDO                $pdo
28
	 * @param string              $table_name
29
	 * @param AddressFactory|null $address_factory
30
	 */
31
	public function __construct( \PDO $pdo, string $table_name, AddressFactory $address_factory = null )
32
	{
33
		$this->address_factory = $address_factory ?: new AddressFactory;
34
35
		$sql = "SELECT " . implode(",", static::$DB_FIELDS) ."
36
		FROM {$table_name}
37
		WHERE id = :id";
38
39
		$this->stmt = $pdo->prepare( $sql );
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo->prepare($sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\Addresses\PDOStmt> of property $stmt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
		$this->stmt->setFetchMode(\PDO::FETCH_CLASS, PdoAddress::class);
41
	}
42
43
44
	public function __invoke( int $id ) : AddressInterface
45
	{
46
		if (!$this->stmt->execute(['id' => $id]))
47
			throw new \RuntimeException("Could not execute SELECT Address PDOStatement");
48
49
		return $this->stmt->fetch();
50
	}
51
}