GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a6816c...6bbc5d )
by Carsten
07:55 queued 12s
created

InsertOrUpdateItemCode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 79
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A __invoke() 0 4 1
A execute() 0 15 1
1
<?php
2
namespace Germania\Nav\ItemCodes\Actions;
3
4
use Germania\Nav\ItemCodes\ItemCodeInterface;
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\NullLogger;
7
8
/**
9
 * Inserts or updates existing ItemCode entry in the database,
10
 * using MySQL's REPLACE statement.
11
 */
12
class InsertOrUpdateItemCode
13
{
14
15
    /**
16
     * The database table to work with
17
     *
18
     * @var string
19
     */
20
    public $table;
21
22
23
    /**
24
     * @var PDOStatement
25
     */
26
    protected $stmt;
27
28
    /**
29
     * @var PDO
30
     */
31
    protected $pdo;
32
33
    /**
34
     * @var LoggerInterface
35
     */
36
    protected $logger;
37
38
39
40
    /**
41
     * @param \PDO                 $pdo    PDO instance
42
     * @param string               $table  Table name to work with.
43
     * @param LoggerInterface|null $logger Optional: PSR3 Logger
44
     */
45 12
    public function __construct(\PDO $pdo, $table, LoggerInterface $logger = null)
46
    {
47 12
        $this->table = $table ?: $this->table;
48
49 12
        $this->pdo    = $pdo;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo of type object<PDO> is incompatible with the declared type object<Germania\Nav\ItemCodes\Actions\PDO> of property $pdo.

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...
50 12
        $this->logger = $logger ?: new NullLogger;
51
52 12
        $sql = "REPLACE INTO {$this->table}
53
        (code, name)
54
        VALUES
55
        (:item_code, :item_name)";
56 12
        $this->stmt = $this->pdo->prepare($sql);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->pdo->prepare($sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\Nav\Item...s\Actions\PDOStatement> 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...
57 12
    }
58
59
60
    /**
61
     * @param  ItemCodeInterface $itemcode
62
     * @return int Number of affected rows, i.e. 2 on REPLACE, 1 on INSERT)
63
     */
64 4
    public function __invoke( ItemCodeInterface $itemcode  )
65
    {
66 4
        return $this->execute( $itemcode );
67
    }
68
69
70
    /**
71
     * @param  ItemCodeInterface $itemcode
72
     * @return int Number of affected rows, i.e. 2 on REPLACE, 1 on INSERT)
73
     */
74 12
    public function execute( ItemCodeInterface $itemcode )
75
    {
76 12
        $bool = $this->stmt->execute([
77 12
            ':item_code' => $itemcode->getCode(),
78 12
            ':item_name' => $itemcode->getName()
79
        ]);
80
81 12
        $this->logger->debug('Logged sales', [
82 12
            'item_code' => $itemcode->getCode(),
83 12
            'result'    => $bool,
84 12
            'count'     => $this->stmt->rowCount()
85
        ]);
86
87 12
        return $this->stmt->rowCount();
88
    }
89
90
}
91