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

PdoAddressDeleter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
namespace Germania\Addresses;
3
4
class PdoAddressDeleter
5
{
6
	/**
7
	 * @var PDOStmt
8
	 */
9
	public $stmt; 
10
11
12
	/**
13
	 * @param \PDO                $pdo
14
	 * @param string              $table_name
15
	 */
16
	public function __construct( \PDO $pdo, string $table_name )
17
	{
18
19
		$sql = "DELETE FROM {$table_name} 
20
		WHERE id = :id
21
		LIMIT 1";
22
23
		$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...
24
	}
25
26
27
28
	public function __invoke( PdoAddressInterface $address ) : int
29
	{
30
		if (!$id = $address->getId())
31
			throw new \UnexpectedValueException("Addess object 'getId' did not return primary key value");
32
33
		$result = $this->stmt->execute([
34
			'id'       => $id
35
		]);
36
37
		if (!$result) {
38
			$msg = sprintf("Could not execute PDOStatement for address ID '%s'", $id);
39
			throw new \RuntimeException($msg);
40
		}
41
42
		return $this->stmt->rowCount();
43
	}
44
}