@@ -22,7 +22,7 @@ class OddNumber
22
22
{
23
23
24
24
// The base class requires this boolean test method:
25
- public static function IsValid ($input) {
25
+ public static function isValid ($input): bool {
26
26
return (is_int($input) && ($input % 2) === 1);
27
27
}
28
28
@@ -50,16 +50,14 @@ Or insert this into your project's `composer.json` file:
50
50
51
51
``` js
52
52
" require" : {
53
- " mle86/value" : " ^1 .0"
53
+ " mle86/value" : " ^2.0 .0"
54
54
}
55
55
```
56
56
57
57
58
58
# Minimum PHP version:
59
59
60
- * PHP 5.4 is needed for the ` AbstractSerializableValue ` class, as it uses the ` JsonSerializable ` interface.
61
-
62
- * PHP 5.3 is sufficient for the rest (the ` Value ` interface and ` AbstractValue ` base class).
60
+ PHP 7.0
63
61
64
62
65
63
# Classes and interfaces:
@@ -84,80 +82,74 @@ This immutable class wraps a single value per instance.
84
82
The constructor enforces validity checks on the input value.
85
83
Therefore, every class instance's wrapped value can be considered valid.
86
84
87
- The validity checks are located in the IsValid class method which all
85
+ The validity checks are located in the isValid class method which all
88
86
subclasses must implement. It is a class method to allow validity checks
89
87
of external values without wrapping them in an instance.
90
88
91
89
92
90
* <code >public function <b >\_\_ construct</b > ($raw\_ value)</code >
93
91
94
- The constructor uses the subclass' `IsValid` method to test its input argument.
92
+ The constructor uses the `isValid` class method to test its input argument.
95
93
Valid values are stored in the new instance, invalid values cause an `InvalidArgumentException` to be thrown.
96
94
Other instances of the same class are always considered valid (*re-wrapping*).
97
95
98
- * <code >public static function <b >IsValid </b > ($test\_ value)</code >
96
+ * <code >public static function <b >isValid </b > ($test\_ value): bool </code >
99
97
100
- Checks the validity of a raw value. If it returns true, a new object can be instantiated with the same value.
98
+ Checks the validity of a raw value.
99
+ If it returns true, a new object can be instantiated with that value.
101
100
Implement this in every subclass!
102
- In the base class implementation, it simply throws a `NotImplementedException`.
103
101
104
102
* <code >final public function <b >value</b > ()</code >
105
103
106
104
Returns the object's wrapped initializer value.
107
105
108
106
* <code >final public function <b >equals</b > ($test\_ value)</code >
109
107
108
+ Equality test.
110
109
This method performs an equality check on other instances or raw values.
111
110
Objects are considered equal if and only if they are instances of the same subclass and carry the same `value()`.
112
111
All other values are considered equal if and only if they are identical (`===`) to the current objects's `value()`.
113
112
114
- * <code >final public static function <b >Wrap </b > (&$value)</code >
113
+ * <code >final public static function <b >wrap </b > (&$value)</code >
115
114
116
115
Replaces a value (by-reference) with instance wrapping that value.
117
- This means of course that the call will fail with an `InvalidArgumentException` if the input value fails the subclass' `IsValid ` check.
116
+ This means of course that the call will fail with an `InvalidArgumentException` if the input value fails the subclass' `isValid ` check.
118
117
If the value already is an instance, it won't be replaced.
119
118
120
- * <code >final public static function <b >WrapOrNull </b > (&$value)</code >
119
+ * <code >final public static function <b >wrapOrNull </b > (&$value)</code >
121
120
122
- Like `Wrap ()`, but won't change `NULL ` values.
121
+ Like `wrap ()`, but won't change `null ` values.
123
122
124
- * <code >final public static function <b >WrapArray </b > (array &$array)</code >
123
+ * <code >final public static function <b >wrapArray </b > (array &$array): array </code >
125
124
126
125
Will replace all values in an array with instances.
127
126
The array will only be altered (by-reference) if all its values are valid.
128
127
Array keys will be preserved.
129
128
130
- * <code >final public static function <b >WrapOrNullArray </b > (array &$array)</code >
129
+ * <code >final public static function <b >wrapOrNullArray </b > (array &$array): array </code >
131
130
132
- Will replace all non-`NULL ` values in an array with instances.
133
- The array will only be changed (by-reference) if all its values are valid (or `NULL `).
131
+ Will replace all non-`null ` values in an array with instances.
132
+ The array will only be changed (by-reference) if all its values are valid (or `null `).
134
133
Array keys will be preserved.
135
134
136
135
137
136
## AbstractSerializableValue
138
137
139
138
This extension of ` AbstractValue ` provides easy serializability for the Value objects.
140
- It implements the PHP 5.4 [ JsonSerializable] ( https://php.net/manual/class.jsonserializable.php ) interface.
139
+ It implements the [ JsonSerializable] ( https://php.net/manual/class.jsonserializable.php ) interface.
141
140
142
- * <code >public function <b >\_\_ toString</b > ()</code >
141
+ * <code >public function <b >\_\_ toString</b > (): string </code >
143
142
144
- Returns the wrapped value –
145
- like `value()`, but with an explicit `(string)` typecast.
146
- This allows string concatenation of Value objects.
143
+ Returns the wrapped value like `value()`, but with an explicit
144
+ `string` typecast. This allows string concatenation of Value objects.
147
145
148
146
* <code >public function <b >jsonSerialize</b > ()</code >
149
147
150
148
Returns the wrapped value –
151
149
like `value()`.
152
- This enables [json_encode()](https://secure.php.net/json_encode) to encode the Value object.
150
+ This enables [json_encode()](https://secure.php.net/json_encode) to encode the object.
153
151
154
152
155
153
## InvalidArgumentException
156
154
157
155
An empty extension of PHP's ` InvalidArgumentException ` .
158
-
159
-
160
- ## NotImplementedException
161
-
162
- An empty extension of PHP's ` ErrorException ` .
163
-
0 commit comments