Completed
Push — 3.x ( 98bb5a...238d5c )
by Hari
10s
created

FailureCollection::isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/MIT-license.php MIT
7
 *
8
 */
9
namespace Aura\Input\Filter;
10
11
use Aura\Filter_Interface\FailureCollectionInterface;
12
13
class FailureCollection  implements FailureCollectionInterface
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before implements keyword; 2 found
Loading history...
14
{
15
    /**
16
     *
17
     * Array of failed messages for fields.
18
     *
19
     * @var array
20
     *
21
     */
22
    protected $messages = [];
23
24
    /**
25
     *
26
     * Is the failure collection empty?
27
     *
28
     * @return bool
29
     *
30
     */
31
    public function isEmpty()
32
    {
33
        return count($this->messages) === 0;
34
    }
35
36
    /**
37
     *
38
     * Adds an additional failure on a field.
39
     *
40
     * @param string $field The field that failed.
41
     *
42
     * @param string|array $messages The failure messages.
43
     *
44
     * @return null
45
     *
46
     */
47
    public function addMessagesForField($field, $messages)
48
    {
49
        if (! isset($this->messages[$field])) {
50
            $this->messages[$field] = [];
51
        }
52
53
        $this->messages[$field] = array_merge(
54
            $this->messages[$field],
55
            (array) $messages
56
        );
57
    }
58
59
    /**
60
     *
61
     * Returns all failure messages for all fields.
62
     *
63
     * @return array
64
     *
65
     */
66
    public function getMessages()
67
    {        
68
        return $this->messages;
69
    }
70
71
    /**
72
     *
73
     * Returns all failure messages for one field.
74
     *
75
     * @param string $field The field name.
76
     *
77
     * @return array
78
     *
79
     */
80
    public function getMessagesForField($field)
81
    {
82
        if (! isset($this->messages[$field])) {
83
            return array();
84
        }
85
86
        return $this->messages[$field];
87
    }
88
}
89