AbstractCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIsStrict() 0 4 1
A setIsStrict() 0 5 1
A checkAffected() 0 10 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