1
1
<?php
2
- /*
3
- * The MIT License
4
- *
5
- * Copyright 2019 Ibrahim, WebFiori Json library.
2
+ /**
3
+ * This file is licensed under MIT License.
6
4
*
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
5
+ * Copyright (c) 2019 Ibrahim BinAlshikh
13
6
*
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
7
+ * For more information on the license, please visit:
8
+ * https://github.com/WebFiori/.github/blob/main/LICENSE
16
9
*
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
10
*/
25
11
namespace webfiori \json ;
26
12
@@ -95,12 +81,12 @@ class Json {
95
81
* Creates new instance of the class.
96
82
*
97
83
* @param array|string $initialData Initial data which is used to initialize
98
- * the object. It can be a string which looks like JSON or it can be an
84
+ * the object. It can be a string which looks like JSON, or it can be an
99
85
* associative array. If it is an associative array, then the keys will be
100
86
* acting as properties and the value of each key will be the value of
101
87
* the property.
102
88
*
103
- * @param boolean $isFormatted If this attribute is set to true, the generated
89
+ * @param bool $isFormatted If this attribute is set to true, the generated
104
90
* JSON will be indented and have new lines (readable). Note that the parameter
105
91
* will be ignored if the constant 'WF_VERBOSE' is defined and is set to true.
106
92
*
@@ -124,9 +110,9 @@ public function __construct(array $initialData = [], $isFormatted = false) {
124
110
* @param string $key The value of the key. Note that the style of the key
125
111
* does not matter.
126
112
*
127
- * @return Json|mixed|null The return type will depends on the value which
113
+ * @return Json|mixed|null The return type will depend on the value which
128
114
* was set by any method which can be used to add props. It can be a number,
129
- * a boolean, string, an object or null if does not exist.
115
+ * a boolean, string, an object or null if it does not exist.
130
116
*
131
117
* @since 1.2
132
118
*/
@@ -189,7 +175,7 @@ public function __toString() {
189
175
* is an array. If set to true, the array will be added as an object.
190
176
* Default is false.
191
177
*
192
- * @return boolean The method will return true if the value is set.
178
+ * @return bool The method will return true if the value is set.
193
179
* If the given value or key is invalid, the method will return false.
194
180
*
195
181
* @since 1.1
@@ -215,11 +201,11 @@ public function add(string $key, $value, $arrayAsObj = false) {
215
201
*
216
202
* @param array $value The array that will be added.
217
203
*
218
- * @param boolean $asObject If this parameter is set to true,
204
+ * @param bool $asObject If this parameter is set to true,
219
205
* the array will be added as an object in JSON string. Note that if the
220
206
* array is associative, each index will be added as an object. Default is false.
221
207
*
222
- * @return boolean The method will return false if the given key is invalid
208
+ * @return bool The method will return false if the given key is invalid
223
209
* or the given value is not an array.
224
210
*/
225
211
public function addArray (string $ key , $ value , $ asObject = false ) {
@@ -248,16 +234,16 @@ public function addArray(string $key, $value, $asObject = false) {
248
234
*
249
235
* @param string $key The name of the key.
250
236
*
251
- * @param boolean $val true or false. If not specified,
237
+ * @param bool $val true or false. If not specified,
252
238
* The default will be true.
253
239
*
254
- * @return boolean The method will return true in case the value is set.
240
+ * @return bool The method will return true in case the value is set.
255
241
* If the given value is not a boolean or the key value is invalid string,
256
242
* the method will return false.
257
243
*
258
244
* @since 1.0
259
245
*/
260
- public function addBoolean ($ key , $ val = true ) {
246
+ public function addBoolean ($ key , $ val = true ) : bool {
261
247
if (!$ this ->updateExisting ($ key , $ val )) {
262
248
$ prop = $ this ->createProb ($ key , $ val );
263
249
@@ -294,10 +280,10 @@ public function addMultiple(array $arr) {
294
280
*
295
281
* @param string $key The name of value key.
296
282
*
297
- * @return boolean The method will return true if the value is set.
283
+ * @return bool The method will return true if the value is set.
298
284
* If the given value or key is invalid, the method will return false.
299
285
*/
300
- public function addNull (string $ key ) {
286
+ public function addNull (string $ key ) : bool {
301
287
$ nul = null ;
302
288
303
289
if (!$ this ->updateExisting ($ key , $ nul )) {
@@ -327,7 +313,7 @@ public function addNull(string $key) {
327
313
*
328
314
* @param int|double $value The value of the key.
329
315
*
330
- * @return boolean The method will return true in case the number is
316
+ * @return bool The method will return true in case the number is
331
317
* added. If the given value is not a number or the key value is invalid
332
318
* string, the method
333
319
* will return false.
@@ -356,19 +342,19 @@ public function addNumber(string $key, $value) {
356
342
* The object that will be added can implement the interface JsonI to make
357
343
* the generated JSON string customizable. Also, the object can be of
358
344
* type Json. If the given value is an object that does not implement the
359
- * interface JsonI or it is not of type Json,
345
+ * interface JsonI, or it is not of type Json,
360
346
* The method will try to extract object information based on its "getXxxxx()" public
361
347
* methods. Assuming that the object has 2 public methods with names
362
348
* <code>getFirstProp()</code> and <code>getSecondProp()</code>.
363
- * In that case, the generated JSON will be on the formate
349
+ * In that case, the generated JSON will be on the format
364
350
* <b>{"FirstProp":"prop-1","SecondProp":""}</b>.
365
351
* This method also can be used to update the value of an existing property.
366
352
*
367
353
* @param string $key The key value.
368
354
*
369
355
* @param JsonI|Json|object $val The object that will be added.
370
356
*
371
- * @return boolean The method will return true if the object is added.
357
+ * @return bool The method will return true if the object is added.
372
358
* If the key value is invalid string, the method will return false.
373
359
*
374
360
* @since 1.0
@@ -394,11 +380,11 @@ public function addObject(string $key, &$val) {
394
380
*
395
381
* This method also can be used to update the value of an existing property.
396
382
*
397
- * @param string $key The name of the key. Must be non empty string.
383
+ * @param string $key The name of the key. Must be non- empty string.
398
384
*
399
385
* @param string $val The value of the string.
400
386
*
401
- * @return boolean The method will return true in case the string is added.
387
+ * @return bool The method will return true in case the string is added.
402
388
* If the given value is not a string or the given key is invalid, the
403
389
* method will return false.
404
390
*
@@ -558,7 +544,7 @@ public function getPropStyle() {
558
544
*
559
545
* @param string $key The name of the key.
560
546
*
561
- * @return boolean The method will return true if the
547
+ * @return bool The method will return true if the
562
548
* key exists. false if not.
563
549
*
564
550
* @since 1.2
@@ -574,7 +560,8 @@ public function hasKey($key) {
574
560
* This can be used to make the generated output readable by adding
575
561
* indentation and new lines.
576
562
*
577
- * @return boolean True if will be formatted. False otherwise.
563
+ * @return bool The method will return true if the output will be formatted.
564
+ * False otherwise.
578
565
*/
579
566
public function isFormatted () {
580
567
return $ this ->formatted ;
@@ -616,7 +603,7 @@ public function remove($keyName) {
616
603
* a tree. If not formatted, the output string will be generated as one line.
617
604
*
618
605
*
619
- * @param boolean $bool True to make the output formatted and false to make
606
+ * @param bool $bool True to make the output formatted and false to make
620
607
* it not.
621
608
*
622
609
* @since 1.2.5
@@ -671,7 +658,7 @@ public function setPropsStyle($style) {
671
658
* sent to. If the file does not exist, the method will attempt to create it.
672
659
*
673
660
* @param string $path The folder in file system that the file will be created
674
- * at. If does not exist, the method will attempt to create it.
661
+ * at. If it does not exist, the method will attempt to create it.
675
662
*
676
663
* @param bool $override If a file exist in the specified location with same
677
664
* name and this parameter is set to true, the method will override existing
0 commit comments