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

StatementOfAccount   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 36.36%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 75
ccs 8
cts 22
cp 0.3636
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatements() 0 4 1
A setStatements() 0 6 2
A addStatement() 0 4 1
A getStatementForDate() 0 14 4
A hasStatementForDate() 0 8 2
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