Completed
Push — 2.x ( a7000d...0738f0 )
by Paul
03:32 queued 01:11
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
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Failure;
10
11
use JsonSerializable;
12
13
/**
14
 *
15
 * Represents the failure of a rule specification.
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class Failure implements JsonSerializable
21
{
22
    /**
23
     *
24
     * The field that failed.
25
     *
26
     * @var string
27
     *
28
     */
29
    protected $field;
30
31
    /**
32
     *
33
     * The failure message.
34
     *
35
     * @var string
36
     *
37
     */
38
    protected $message;
39
40
    /**
41
     *
42
     * The arguments passed to the rule specification.
43
     *
44
     * @var array
45
     *
46
     */
47
    protected $args = array();
48
49
    /**
50
     *
51
     * Constructor.
52
     *
53
     * @param string $field The field that failed.
54
     *
55
     * @param string $message The failure message.
56
     *
57
     * @param array $args The arguments passed to the rule specification.
58
     *
59
     * @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...
60
     *
61
     */
62 9
    public function __construct(
63
        $field,
64
        $message,
65
        array $args = array()
66
    ) {
67 9
        $this->field = $field;
68 9
        $this->message = $message;
69 9
        $this->args = $args;
70 9
    }
71
72
    /**
73
     *
74
     * Returns the field that failed.
75
     *
76
     * @return string
77
     *
78
     */
79 1
    public function getField()
80
    {
81 1
        return $this->field;
82
    }
83
84
    /**
85
     *
86
     * Returns the failure message.
87
     *
88
     * @return string
89
     *
90
     */
91 8
    public function getMessage()
92
    {
93 8
        return $this->message;
94
    }
95
96
    /**
97
     *
98
     * Returns the arguments passed to the rule specification.
99
     *
100
     * @return array
101
     *
102
     */
103 1
    public function getArgs()
104
    {
105 1
        return $this->args;
106
    }
107
108
   /**
109
    *
110
    * Returns an array for json_encode.
111
    *
112
    * @return array
113
    *
114
    */
115 1
    public function jsonSerialize()
116
    {
117
        return array(
118 1
            'field' => $this->field,
119 1
            'message' => $this->message,
120 1
            'args' => $this->args,
121 1
        );
122
    }
123
}
124