Completed
Push — master ( b2bf11...c2b2ec )
by Markus
24s
created

StatementOfAccount::getStatementForDate()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 6
nop 1
crap 20
1
<?php
2
3
namespace Fhp\Model\StatementOfAccount;
4
5
/**
6
 * Class StatementOfAccount
7
 * @package Fhp\Model\StatementOfAccount
8
 */
9
class StatementOfAccount
10
{
11
    /**
12
     * @var Statement[]
13
     */
14
    protected $statements = array();
15
16
    /**
17
     * Get statements
18
     *
19
     * @return Statement[]
20
     */
21 1
    public function getStatements()
22
    {
23 1
        return $this->statements;
24
    }
25
26
    /**
27
     * Set statements
28
     *
29
     * @param array $statements
30
     *
31
     * @return $this
32
     */
33 1
    public function setStatements(array $statements = null)
34
    {
35 1
        $this->statements = null == $statements ? array() : $statements;
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * @param Statement $statement
42
     */
43 1
    public function addStatement(Statement $statement)
44
    {
45 1
        $this->statements[] = $statement;
46 1
    }
47
48
    /**
49
     * Gets statement for given date.
50
     *
51
     * @param string|\DateTime $date
52
     * @return Statement|null
53
     */
54
    public function getStatementForDate($date)
55
    {
56
        if (is_string($date)) {
57
            $date = new \DateTime($date);
58
        }
59
60
        foreach ($this->statements as $stmt) {
61
            if ($stmt->getDate() == $date) {
62
                return $stmt;
63
            }
64
        }
65
66
        return null;
67
    }
68
69
    /**
70
     * Checks if a statement with given date exists.
71
     *
72
     * @param string|\DateTime $date
73
     * @return bool
74
     */
75
    public function hasStatementForDate($date)
76
    {
77
        if (is_string($date)) {
78
            $date = new \DateTime($date);
79
        }
80
81
        return null !== $this->getStatementForDate($date);
82
    }
83
}
84