AbstractCommand::checkAffected()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4
1
<?php
2
/*
3
 * To change this license header, choose License Headers in Project Properties.
4
 * To change this template file, choose Tools | Templates
5
 * and open the template in the editor.
6
 */
7
namespace DSchoenbauer\Sql\Command;
8
9
use DSchoenbauer\Sql\Exception\NoRecordsAffectedException;
10
use PDOStatement;
11
12
/**
13
 * Description of ErrorTrait
14
 *
15
 * @author David Schoenbauer
16
 */
17
abstract class AbstractCommand implements CommandInterface
18
{
19
20
    private $isStrict = false;
21
22 19
    public function getIsStrict()
23
    {
24 19
        return $this->isStrict;
25
    }
26
27 13
    public function setIsStrict($isStrict = true)
28
    {
29 13
        $this->isStrict = boolval($isStrict);
30 13
        return $this;
31
    }
32
33
    /**
34
     * Throws an exception if no records are found / affected
35
     * @param PDOStatement $statement
36
     * @param \Exception $exceptionToThrow
37
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the type for parameter $exceptionToThrow not be null|\Exception?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     * @throws NoRecordsAffectedException
39
     */
40
    
41 20
    public function checkAffected(PDOStatement $statement, \Exception $exceptionToThrow = null)
42
    {
43 20
        if (!$exceptionToThrow instanceof \Exception) {
44 4
            $exceptionToThrow = new NoRecordsAffectedException();
45
        }
46 20
        if (!boolval($statement->rowCount()) && $this->getIsStrict()) {
47 5
            throw $exceptionToThrow;
48
        }
49 15
        return true;
50
    }
51
}
52