Passed
Push — master ( b1fefe...1b2e02 )
by Michael
05:24
created

AbstractDatabase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 63
ccs 12
cts 18
cp 0.6667
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 10 2
A getLogger() 0 4 1
A setLogger() 0 8 2
lastIdCreated() 0 1 ?
1
<?php
2
namespace DAL;
3
4
use \Psr\Log\LoggerAwareInterface;
5
use \Psr\Log\LoggerInterface;
6
use \Psr\Log\NullLogger;
7
8
abstract class AbstractDatabase implements LoggerAwareInterface, ReadableInterface, WritableInterface
9
{
10
11
    private $logger;
12
13
    /**
14
     * Instantiates the AbstractDatabase. Should be called from inheritors.
15
     */
16 40
    public function __construct()
17
    {
18 40
        $this->logger = new NullLogger();
19 40
    }
20
21
    /**
22
     * @param string $table The table that will be accessed and written.
23
     * @return array|null
24
     */
25 3
    public function find($table, Condition $criteria = null, array $options = [])
26
    {
27 3
        $options['limit'] = 1;
28 3
        $data             = $this->findAll($table, $criteria, $options);
29 3
        $result           = reset($data);
30 3
        if ($result === false) {
31 1
            return null;
32
        }
33 2
        return $result;
34
    }
35
36
    /**
37
     * Returns the current logger object.
38
     *
39
     * @return LoggerInterface
40
     */
41 2
    public function getLogger()
42
    {
43 2
        return $this->logger;
44
    }
45
46
    /**
47
     * Sets the logger to $value.
48
     *
49
     * @param LoggerInterface $value A logger to be used for this database.
50
     *
51
     * @return void
52
     */
53
    public function setLogger(LoggerInterface $value)
54
    {
55
        if (null === $value) {
56
            $value = new NullLogger();
57
        }
58
59
        $this->logger = $value;
60
    }
61
62
    /**
63
     * Returns the id of the last record created, or null if no creation took place.
64
     *
65
     * Must be implemented by inheritors.
66
     *
67
     * @return mixed
68
     */
69
    abstract public function lastIdCreated();
70
}
71