Completed
Pull Request — 2.x (#121)
by
unknown
02:22
created

Failure::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of Aura for PHP.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace Aura\Filter\Failure;
8
9
use JsonSerializable;
10
11
/**
12
 * Represents the failure of a rule specification.
13
 */
14
class Failure implements JsonSerializable
15
{
16
    /**
17
     * The field that failed.
18
     *
19
     * @var string
20
     */
21
    protected $field;
22
23
    /**
24
     * The failure message.
25
     *
26
     * @var string
27
     */
28
    protected $message;
29
30
    /**
31
     * The arguments passed to the rule specification.
32
     *
33
     * @var array
34
     */
35
    protected $args = array();
36
37
    /**
38
     * Constructor.
39
     *
40
     * @param string $field   The field that failed.
41
     * @param string $message The failure message.
42
     * @param array  $args    The arguments passed to the rule specification.
43
     *
44
     * @return self
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
45
     */
46 9
    public function __construct(
47
        $field,
48
        $message,
49
        array $args = array()
50
    ) {
51 9
        $this->field = $field;
52 9
        $this->message = $message;
53 9
        $this->args = $args;
54 9
    }
55
56
    /**
57
     * Returns the field that failed.
58
     *
59
     * @return string
60
     */
61 1
    public function getField()
62
    {
63 1
        return $this->field;
64
    }
65
66
    /**
67
     * Returns the failure message.
68
     *
69
     * @return string
70
     */
71 8
    public function getMessage()
72
    {
73 8
        return $this->message;
74
    }
75
76
    /**
77
     * Returns the arguments passed to the rule specification.
78
     *
79
     * @return array
80
     */
81 1
    public function getArgs()
82
    {
83 1
        return $this->args;
84
    }
85
86
    /**
87
     * Returns an array for json_encode.
88
     *
89
     * @return array
90
     */
91 1
    public function jsonSerialize()
92
    {
93
        return array(
94 1
            'field' => $this->field,
95 1
            'message' => $this->message,
96 1
            'args' => $this->args,
97 1
        );
98
    }
99
}
100