Passed
Pull Request — master (#2)
by tsms
01:48
created

ValidationError   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A getUnit() 0 3 1
A toString() 0 3 1
A getMessage() 0 3 1
A __construct() 0 5 1
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4
/**
5
 * Contains the Calendar_Validator class
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * @category  Date and Time
31
 * @package   Calendar
32
 * @author    Harry Fuecks <[email protected]>
33
 * @copyright 2003-2007 Harry Fuecks
34
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
35
 * @version   CVS: $Id$
36
 * @link      http://pear.php.net/package/Calendar
37
 */
38
namespace PEAR\Calendar;
39
40
/**
41
 * Validation Error Messages
42
 */
43
if (!defined('CALENDAR_VALUE_TOOSMALL')) {
44
    define('CALENDAR_VALUE_TOOSMALL', 'Too small: min = ');
45
}
46
if (!defined('CALENDAR_VALUE_TOOLARGE')) {
47
    define('CALENDAR_VALUE_TOOLARGE', 'Too large: max = ');
48
}
49
50
/**
51
 * For Validation Error messages
52
 *
53
 * @category  Date and Time
54
 * @package   Calendar
55
 * @author    Harry Fuecks <[email protected]>
56
 * @copyright 2003-2007 Harry Fuecks
57
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
58
 * @link      http://pear.php.net/package/Calendar
59
 * @see       Calendar::fetch()
60
 * @access    public
61
 */
62
class ValidationError
63
{
64
    /**
65
     * Date unit (e.g. month,hour,second) which failed test
66
     * @var string
67
     * @access private
68
     */
69
    var $unit;
70
71
    /**
72
     * Value of unit which failed test
73
     * @var int
74
     * @access private
75
     */
76
    var $value;
77
78
    /**
79
     * Validation error message
80
     * @var string
81
     * @access private
82
     */
83
    var $message;
84
85
    /**
86
     * Constructs Calendar_Validation_Error
87
     *
88
     * @param string $unit    Date unit (e.g. month,hour,second)
89
     * @param int    $value   Value of unit which failed test
90
     * @param string $message Validation error message
91
     *
92
     * @access protected
93
     */
94
    function __construct($unit, $value, $message)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
95
    {
96
        $this->unit    = $unit;
97
        $this->value   = $value;
98
        $this->message = $message;
99
    }
100
101
    /**
102
     * Returns the Date unit
103
     *
104
     * @return string
105
     * @access public
106
     */
107
    function getUnit()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
108
    {
109
        return $this->unit;
110
    }
111
112
    /**
113
     * Returns the value of the unit
114
     *
115
     * @return int
116
     * @access public
117
     */
118
    function getValue()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
119
    {
120
        return $this->value;
121
    }
122
123
    /**
124
     * Returns the validation error message
125
     *
126
     * @return string
127
     * @access public
128
     */
129
    function getMessage()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
130
    {
131
        return $this->message;
132
    }
133
134
    /**
135
     * Returns a string containing the unit, value and error message
136
     *
137
     * @return string
138
     * @access public
139
     */
140
    function toString ()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141
    {
142
        return $this->unit.' = '.$this->value.' ['.$this->message.']';
143
    }
144
}
145