@@ -32,46 +32,46 @@ discard block |
||
32 | 32 | const TYPE_ERROR = 'error'; |
33 | 33 | const TYPE_SUCCESS = 'success'; |
34 | 34 | |
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | 38 | protected $message = ''; |
39 | 39 | |
40 | - /** |
|
41 | - * @var bool |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | 43 | protected $valid = true; |
44 | 44 | |
45 | - /** |
|
46 | - * @var object |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var object |
|
47 | + */ |
|
48 | 48 | protected $subject; |
49 | 49 | |
50 | - /** |
|
51 | - * @var integer |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var integer |
|
52 | + */ |
|
53 | 53 | protected $code = 0; |
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | 58 | protected $type = ''; |
59 | 59 | |
60 | - /** |
|
61 | - * @var integer |
|
62 | - */ |
|
60 | + /** |
|
61 | + * @var integer |
|
62 | + */ |
|
63 | 63 | private static $counter = 0; |
64 | 64 | |
65 | - /** |
|
66 | - * @var int |
|
67 | - */ |
|
65 | + /** |
|
66 | + * @var int |
|
67 | + */ |
|
68 | 68 | private $id; |
69 | 69 | |
70 | - /** |
|
71 | - * The subject being validated. |
|
72 | - * |
|
73 | - * @param object $subject |
|
74 | - */ |
|
70 | + /** |
|
71 | + * The subject being validated. |
|
72 | + * |
|
73 | + * @param object $subject |
|
74 | + */ |
|
75 | 75 | public function __construct(object $subject) |
76 | 76 | { |
77 | 77 | $this->subject = $subject; |
@@ -81,21 +81,21 @@ discard block |
||
81 | 81 | $this->id = self::$counter; |
82 | 82 | } |
83 | 83 | |
84 | - /** |
|
85 | - * Retrieves the ID of the result, which is unique within a request. |
|
86 | - * |
|
87 | - * @return int |
|
88 | - */ |
|
84 | + /** |
|
85 | + * Retrieves the ID of the result, which is unique within a request. |
|
86 | + * |
|
87 | + * @return int |
|
88 | + */ |
|
89 | 89 | public function getID() : int |
90 | 90 | { |
91 | 91 | return $this->id; |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Whether the validation was successful. |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
94 | + /** |
|
95 | + * Whether the validation was successful. |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | 99 | public function isValid() : bool |
100 | 100 | { |
101 | 101 | return $this->valid; |
@@ -126,33 +126,33 @@ discard block |
||
126 | 126 | return $this->type === $type; |
127 | 127 | } |
128 | 128 | |
129 | - /** |
|
130 | - * Retrieves the subject that was validated. |
|
131 | - * |
|
132 | - * @return object |
|
133 | - */ |
|
129 | + /** |
|
130 | + * Retrieves the subject that was validated. |
|
131 | + * |
|
132 | + * @return object |
|
133 | + */ |
|
134 | 134 | public function getSubject() : object |
135 | 135 | { |
136 | 136 | return $this->subject; |
137 | 137 | } |
138 | 138 | |
139 | - /** |
|
140 | - * Makes the result a succes, with the specified message. |
|
141 | - * |
|
142 | - * @param string $message Should not contain a date, just the system specific info. |
|
143 | - * @return OperationResult |
|
144 | - */ |
|
139 | + /** |
|
140 | + * Makes the result a succes, with the specified message. |
|
141 | + * |
|
142 | + * @param string $message Should not contain a date, just the system specific info. |
|
143 | + * @return OperationResult |
|
144 | + */ |
|
145 | 145 | public function makeSuccess(string $message, int $code=0) : OperationResult |
146 | 146 | { |
147 | 147 | return $this->setMessage(self::TYPE_SUCCESS, $message, $code, true); |
148 | 148 | } |
149 | 149 | |
150 | - /** |
|
151 | - * Sets the result as an error. |
|
152 | - * |
|
153 | - * @param string $message Should be as detailed as possible. |
|
154 | - * @return OperationResult |
|
155 | - */ |
|
150 | + /** |
|
151 | + * Sets the result as an error. |
|
152 | + * |
|
153 | + * @param string $message Should be as detailed as possible. |
|
154 | + * @return OperationResult |
|
155 | + */ |
|
156 | 156 | public function makeError(string $message, int $code=0) : OperationResult |
157 | 157 | { |
158 | 158 | return $this->setMessage(self::TYPE_ERROR, $message, $code, false); |
@@ -183,21 +183,21 @@ discard block |
||
183 | 183 | return $this->type; |
184 | 184 | } |
185 | 185 | |
186 | - /** |
|
187 | - * Retrieves the error message, if an error occurred. |
|
188 | - * |
|
189 | - * @return string The error message, or an empty string if no error occurred. |
|
190 | - */ |
|
186 | + /** |
|
187 | + * Retrieves the error message, if an error occurred. |
|
188 | + * |
|
189 | + * @return string The error message, or an empty string if no error occurred. |
|
190 | + */ |
|
191 | 191 | public function getErrorMessage() : string |
192 | 192 | { |
193 | 193 | return $this->getMessage(self::TYPE_ERROR); |
194 | 194 | } |
195 | 195 | |
196 | - /** |
|
197 | - * Retrieves the success message, if one has been provided. |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
196 | + /** |
|
197 | + * Retrieves the success message, if one has been provided. |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | 201 | public function getSuccessMessage() : string |
202 | 202 | { |
203 | 203 | return $this->getMessage(self::TYPE_SUCCESS); |
@@ -213,21 +213,21 @@ discard block |
||
213 | 213 | return $this->getMessage(self::TYPE_WARNING); |
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * Whether a specific error/success code has been specified. |
|
218 | - * |
|
219 | - * @return bool |
|
220 | - */ |
|
216 | + /** |
|
217 | + * Whether a specific error/success code has been specified. |
|
218 | + * |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | 221 | public function hasCode() : bool |
222 | 222 | { |
223 | 223 | return $this->code > 0; |
224 | 224 | } |
225 | 225 | |
226 | - /** |
|
227 | - * Retrieves the error/success code, if any. |
|
228 | - * |
|
229 | - * @return int The error code, or 0 if none. |
|
230 | - */ |
|
226 | + /** |
|
227 | + * Retrieves the error/success code, if any. |
|
228 | + * |
|
229 | + * @return int The error code, or 0 if none. |
|
230 | + */ |
|
231 | 231 | public function getCode() : int |
232 | 232 | { |
233 | 233 | return $this->code; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $message Should not contain a date, just the system specific info. |
143 | 143 | * @return OperationResult |
144 | 144 | */ |
145 | - public function makeSuccess(string $message, int $code=0) : OperationResult |
|
145 | + public function makeSuccess(string $message, int $code = 0) : OperationResult |
|
146 | 146 | { |
147 | 147 | return $this->setMessage(self::TYPE_SUCCESS, $message, $code, true); |
148 | 148 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $message Should be as detailed as possible. |
154 | 154 | * @return OperationResult |
155 | 155 | */ |
156 | - public function makeError(string $message, int $code=0) : OperationResult |
|
156 | + public function makeError(string $message, int $code = 0) : OperationResult |
|
157 | 157 | { |
158 | 158 | return $this->setMessage(self::TYPE_ERROR, $message, $code, false); |
159 | 159 | } |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | return $this->code; |
234 | 234 | } |
235 | 235 | |
236 | - public function getMessage(string $type='') : string |
|
236 | + public function getMessage(string $type = '') : string |
|
237 | 237 | { |
238 | - if(!empty($type)) |
|
238 | + if (!empty($type)) |
|
239 | 239 | { |
240 | - if($this->type === $type) |
|
240 | + if ($this->type === $type) |
|
241 | 241 | { |
242 | 242 | return $this->message; |
243 | 243 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class OperationResult_Collection extends OperationResult |
28 | 28 | { |
29 | - /** |
|
30 | - * @var OperationResult[] |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var OperationResult[] |
|
31 | + */ |
|
32 | 32 | protected $results = array(); |
33 | 33 | |
34 | 34 | public function makeError(string $message, int $code=0) : OperationResult |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | return $this; |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * @return OperationResult[] |
|
111 | - */ |
|
109 | + /** |
|
110 | + * @return OperationResult[] |
|
111 | + */ |
|
112 | 112 | public function getResults() : array |
113 | 113 | { |
114 | 114 | return $this->results; |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected $results = array(); |
33 | 33 | |
34 | - public function makeError(string $message, int $code=0) : OperationResult |
|
34 | + public function makeError(string $message, int $code = 0) : OperationResult |
|
35 | 35 | { |
36 | 36 | return $this->add('makeError', $message, $code); |
37 | 37 | } |
38 | 38 | |
39 | - public function makeSuccess(string $message, int $code=0) : OperationResult |
|
39 | + public function makeSuccess(string $message, int $code = 0) : OperationResult |
|
40 | 40 | { |
41 | 41 | return $this->add('makeSuccess', $message, $code); |
42 | 42 | } |
43 | 43 | |
44 | - public function makeWarning(string $message, int $code=0) : OperationResult |
|
44 | + public function makeWarning(string $message, int $code = 0) : OperationResult |
|
45 | 45 | { |
46 | 46 | return $this->add('makeWarning', $message, $code); |
47 | 47 | } |
48 | 48 | |
49 | - public function makeNotice(string $message, int $code=0) : OperationResult |
|
49 | + public function makeNotice(string $message, int $code = 0) : OperationResult |
|
50 | 50 | { |
51 | 51 | return $this->add('makeNotice', $message, $code); |
52 | 52 | } |
53 | 53 | |
54 | - protected function add(string $method, string $message, int $code=0) : OperationResult |
|
54 | + protected function add(string $method, string $message, int $code = 0) : OperationResult |
|
55 | 55 | { |
56 | 56 | $result = new OperationResult($this->subject); |
57 | 57 | $result->$method($message, $code); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function addResult(OperationResult $result) : OperationResult_Collection |
65 | 65 | { |
66 | - if($result instanceof OperationResult_Collection) |
|
66 | + if ($result instanceof OperationResult_Collection) |
|
67 | 67 | { |
68 | 68 | return $this->importCollection($result); |
69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | $results = $collection->getResults(); |
77 | 77 | |
78 | - foreach($results as $result) |
|
78 | + foreach ($results as $result) |
|
79 | 79 | { |
80 | 80 | $this->addResult($result); |
81 | 81 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | |
112 | 112 | public function isValid() : bool |
113 | 113 | { |
114 | - foreach($this->results as $result) |
|
114 | + foreach ($this->results as $result) |
|
115 | 115 | { |
116 | - if(!$result->isValid()) |
|
116 | + if (!$result->isValid()) |
|
117 | 117 | { |
118 | 118 | return false; |
119 | 119 | } |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | |
125 | 125 | public function hasCode() : bool |
126 | 126 | { |
127 | - foreach($this->results as $result) |
|
127 | + foreach ($this->results as $result) |
|
128 | 128 | { |
129 | - if($result->hasCode()) |
|
129 | + if ($result->hasCode()) |
|
130 | 130 | { |
131 | 131 | return true; |
132 | 132 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | |
138 | 138 | public function getCode() : int |
139 | 139 | { |
140 | - foreach($this->results as $result) |
|
140 | + foreach ($this->results as $result) |
|
141 | 141 | { |
142 | - if($result->hasCode()) |
|
142 | + if ($result->hasCode()) |
|
143 | 143 | { |
144 | 144 | return $result->getCode(); |
145 | 145 | } |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | return 0; |
149 | 149 | } |
150 | 150 | |
151 | - public function getMessage(string $type='') : string |
|
151 | + public function getMessage(string $type = '') : string |
|
152 | 152 | { |
153 | - foreach($this->results as $result) |
|
153 | + foreach ($this->results as $result) |
|
154 | 154 | { |
155 | 155 | $msg = $result->getMessage($type); |
156 | 156 | |
157 | - if(!empty($msg)) |
|
157 | + if (!empty($msg)) |
|
158 | 158 | { |
159 | 159 | return $msg; |
160 | 160 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | |
166 | 166 | public function containsCode(int $code) : bool |
167 | 167 | { |
168 | - foreach($this->results as $result) |
|
168 | + foreach ($this->results as $result) |
|
169 | 169 | { |
170 | - if($result->getCode() === $code) |
|
170 | + if ($result->getCode() === $code) |
|
171 | 171 | { |
172 | 172 | return true; |
173 | 173 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | { |
201 | 201 | $amount = 0; |
202 | 202 | |
203 | - foreach($this->results as $result) |
|
203 | + foreach ($this->results as $result) |
|
204 | 204 | { |
205 | - if($result->isType($type)) |
|
205 | + if ($result->isType($type)) |
|
206 | 206 | { |
207 | 207 | $amount++; |
208 | 208 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | { |
241 | 241 | $results = array(); |
242 | 242 | |
243 | - foreach($this->results as $result) |
|
243 | + foreach ($this->results as $result) |
|
244 | 244 | { |
245 | - if($result->isType($type)) |
|
245 | + if ($result->isType($type)) |
|
246 | 246 | { |
247 | 247 | $results[] = $result; |
248 | 248 | } |
@@ -253,9 +253,9 @@ discard block |
||
253 | 253 | |
254 | 254 | public function isType(string $type) : bool |
255 | 255 | { |
256 | - foreach($this->results as $result) |
|
256 | + foreach ($this->results as $result) |
|
257 | 257 | { |
258 | - if($result->isType($type)) |
|
258 | + if ($result->isType($type)) |
|
259 | 259 | { |
260 | 260 | return true; |
261 | 261 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $lines[] = 'Collection #'.$this->getID(); |
272 | 272 | $lines[] = 'Subject: '.get_class($this->subject); |
273 | 273 | |
274 | - foreach($this->results as $result) |
|
274 | + foreach ($this->results as $result) |
|
275 | 275 | { |
276 | 276 | $lines[] = ' - '.$result->getType().' #'.$result->getCode().' "'.$result->getMessage($result->getType()).'"'; |
277 | 277 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | */ |
26 | 26 | trait Traits_Classable |
27 | 27 | { |
28 | - /** |
|
29 | - * @var string[] |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string[] |
|
30 | + */ |
|
31 | 31 | protected $classes = array(); |
32 | 32 | |
33 | 33 | public function addClass(string $name) |
@@ -65,30 +65,30 @@ discard block |
||
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Retrieves a list of all classes, if any. |
|
70 | - * |
|
71 | - * @return string[] |
|
72 | - */ |
|
68 | + /** |
|
69 | + * Retrieves a list of all classes, if any. |
|
70 | + * |
|
71 | + * @return string[] |
|
72 | + */ |
|
73 | 73 | public function getClasses() : array |
74 | 74 | { |
75 | 75 | return $this->classes; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * Renders the class names list as space-separated string for use in an HTML tag. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
78 | + /** |
|
79 | + * Renders the class names list as space-separated string for use in an HTML tag. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | 83 | public function classesToString() : string |
84 | 84 | { |
85 | 85 | return implode(' ', $this->classes); |
86 | 86 | } |
87 | 87 | |
88 | - /** |
|
89 | - * Renders the "class" attribute string for inserting into an HTML tag. |
|
90 | - * @return string |
|
91 | - */ |
|
88 | + /** |
|
89 | + * Renders the "class" attribute string for inserting into an HTML tag. |
|
90 | + * @return string |
|
91 | + */ |
|
92 | 92 | public function classesToAttribute() : string |
93 | 93 | { |
94 | 94 | if(!empty($this->classes)) |
@@ -117,42 +117,42 @@ discard block |
||
117 | 117 | */ |
118 | 118 | interface Interface_Classable |
119 | 119 | { |
120 | - /** |
|
121 | - * @param string $name |
|
122 | - * @return $this |
|
123 | - */ |
|
120 | + /** |
|
121 | + * @param string $name |
|
122 | + * @return $this |
|
123 | + */ |
|
124 | 124 | public function addClass(string $name); |
125 | 125 | |
126 | - /** |
|
127 | - * @param array $names |
|
128 | - * @return $this |
|
129 | - */ |
|
126 | + /** |
|
127 | + * @param array $names |
|
128 | + * @return $this |
|
129 | + */ |
|
130 | 130 | public function addClasses(array $names); |
131 | 131 | |
132 | - /** |
|
133 | - * @param string $name |
|
134 | - * @return bool |
|
135 | - */ |
|
132 | + /** |
|
133 | + * @param string $name |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | 136 | public function hasClass(string $name) : bool; |
137 | 137 | |
138 | - /** |
|
139 | - * @param string $name |
|
140 | - * @return $this |
|
141 | - */ |
|
138 | + /** |
|
139 | + * @param string $name |
|
140 | + * @return $this |
|
141 | + */ |
|
142 | 142 | public function removeClass(string $name); |
143 | 143 | |
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | 147 | public function getClasses() : array; |
148 | 148 | |
149 | - /** |
|
150 | - * @return string |
|
151 | - */ |
|
149 | + /** |
|
150 | + * @return string |
|
151 | + */ |
|
152 | 152 | public function classesToString() : string; |
153 | 153 | |
154 | - /** |
|
155 | - * @return string |
|
156 | - */ |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + */ |
|
157 | 157 | public function classesToAttribute() : string; |
158 | 158 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public function addClass(string $name) |
34 | 34 | { |
35 | - if(!in_array($name, $this->classes)) { |
|
35 | + if (!in_array($name, $this->classes)) { |
|
36 | 36 | $this->classes[] = $name; |
37 | 37 | } |
38 | 38 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | public function addClasses(array $names) |
43 | 43 | { |
44 | - foreach($names as $name) { |
|
44 | + foreach ($names as $name) { |
|
45 | 45 | $this->addClass($name); |
46 | 46 | } |
47 | 47 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | { |
58 | 58 | $idx = array_search($name, $this->classes); |
59 | 59 | |
60 | - if($idx !== false) { |
|
60 | + if ($idx !== false) { |
|
61 | 61 | unset($this->classes[$idx]); |
62 | 62 | sort($this->classes); |
63 | 63 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function classesToAttribute() : string |
93 | 93 | { |
94 | - if(!empty($this->classes)) |
|
94 | + if (!empty($this->classes)) |
|
95 | 95 | { |
96 | 96 | return sprintf( |
97 | 97 | ' class="%s" ', |