11<?php
2- /*
3- * The MIT License
4- *
5- * Copyright 2019 Ibrahim, WebFiori Json library.
2+ /**
3+ * This file is licensed under MIT License.
64 *
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
136 *
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
169 *
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.
2410 */
2511namespace webfiori \json ;
2612
@@ -95,12 +81,12 @@ class Json {
9581 * Creates new instance of the class.
9682 *
9783 * @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
9985 * associative array. If it is an associative array, then the keys will be
10086 * acting as properties and the value of each key will be the value of
10187 * the property.
10288 *
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
10490 * JSON will be indented and have new lines (readable). Note that the parameter
10591 * will be ignored if the constant 'WF_VERBOSE' is defined and is set to true.
10692 *
@@ -124,9 +110,9 @@ public function __construct(array $initialData = [], $isFormatted = false) {
124110 * @param string $key The value of the key. Note that the style of the key
125111 * does not matter.
126112 *
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
128114 * 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.
130116 *
131117 * @since 1.2
132118 */
@@ -189,7 +175,7 @@ public function __toString() {
189175 * is an array. If set to true, the array will be added as an object.
190176 * Default is false.
191177 *
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.
193179 * If the given value or key is invalid, the method will return false.
194180 *
195181 * @since 1.1
@@ -215,11 +201,11 @@ public function add(string $key, $value, $arrayAsObj = false) {
215201 *
216202 * @param array $value The array that will be added.
217203 *
218- * @param boolean $asObject If this parameter is set to true,
204+ * @param bool $asObject If this parameter is set to true,
219205 * the array will be added as an object in JSON string. Note that if the
220206 * array is associative, each index will be added as an object. Default is false.
221207 *
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
223209 * or the given value is not an array.
224210 */
225211 public function addArray (string $ key , $ value , $ asObject = false ) {
@@ -248,16 +234,16 @@ public function addArray(string $key, $value, $asObject = false) {
248234 *
249235 * @param string $key The name of the key.
250236 *
251- * @param boolean $val true or false. If not specified,
237+ * @param bool $val true or false. If not specified,
252238 * The default will be true.
253239 *
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.
255241 * If the given value is not a boolean or the key value is invalid string,
256242 * the method will return false.
257243 *
258244 * @since 1.0
259245 */
260- public function addBoolean ($ key , $ val = true ) {
246+ public function addBoolean ($ key , $ val = true ) : bool {
261247 if (!$ this ->updateExisting ($ key , $ val )) {
262248 $ prop = $ this ->createProb ($ key , $ val );
263249
@@ -294,10 +280,10 @@ public function addMultiple(array $arr) {
294280 *
295281 * @param string $key The name of value key.
296282 *
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.
298284 * If the given value or key is invalid, the method will return false.
299285 */
300- public function addNull (string $ key ) {
286+ public function addNull (string $ key ) : bool {
301287 $ nul = null ;
302288
303289 if (!$ this ->updateExisting ($ key , $ nul )) {
@@ -327,7 +313,7 @@ public function addNull(string $key) {
327313 *
328314 * @param int|double $value The value of the key.
329315 *
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
331317 * added. If the given value is not a number or the key value is invalid
332318 * string, the method
333319 * will return false.
@@ -356,19 +342,19 @@ public function addNumber(string $key, $value) {
356342 * The object that will be added can implement the interface JsonI to make
357343 * the generated JSON string customizable. Also, the object can be of
358344 * 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,
360346 * The method will try to extract object information based on its "getXxxxx()" public
361347 * methods. Assuming that the object has 2 public methods with names
362348 * <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
364350 * <b>{"FirstProp":"prop-1","SecondProp":""}</b>.
365351 * This method also can be used to update the value of an existing property.
366352 *
367353 * @param string $key The key value.
368354 *
369355 * @param JsonI|Json|object $val The object that will be added.
370356 *
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.
372358 * If the key value is invalid string, the method will return false.
373359 *
374360 * @since 1.0
@@ -394,11 +380,11 @@ public function addObject(string $key, &$val) {
394380 *
395381 * This method also can be used to update the value of an existing property.
396382 *
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.
398384 *
399385 * @param string $val The value of the string.
400386 *
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.
402388 * If the given value is not a string or the given key is invalid, the
403389 * method will return false.
404390 *
@@ -558,7 +544,7 @@ public function getPropStyle() {
558544 *
559545 * @param string $key The name of the key.
560546 *
561- * @return boolean The method will return true if the
547+ * @return bool The method will return true if the
562548 * key exists. false if not.
563549 *
564550 * @since 1.2
@@ -574,7 +560,8 @@ public function hasKey($key) {
574560 * This can be used to make the generated output readable by adding
575561 * indentation and new lines.
576562 *
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.
578565 */
579566 public function isFormatted () {
580567 return $ this ->formatted ;
@@ -616,7 +603,7 @@ public function remove($keyName) {
616603 * a tree. If not formatted, the output string will be generated as one line.
617604 *
618605 *
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
620607 * it not.
621608 *
622609 * @since 1.2.5
@@ -671,7 +658,7 @@ public function setPropsStyle($style) {
671658 * sent to. If the file does not exist, the method will attempt to create it.
672659 *
673660 * @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.
675662 *
676663 * @param bool $override If a file exist in the specified location with same
677664 * name and this parameter is set to true, the method will override existing
0 commit comments