From e0e064b686bac62197fe0eadde43092236d278f7 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 20:42:09 +0300 Subject: [PATCH 1/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 58881b2..f0518fa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ test.* .phpunit.result.cache clover.xml *.phar +.idea/* From f62ed491865bdceab58428cd85fd7eda7e7e485a Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 20:42:49 +0300 Subject: [PATCH 2/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f0518fa..43d4156 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ test.* clover.xml *.phar .idea/* +vendor/* From 96fffe03fcfe83b1f37d763cacd454c456505714 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 20:42:59 +0300 Subject: [PATCH 3/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 43d4156..7830907 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ clover.xml *.phar .idea/* vendor/* +composer.lock From 9343ba379517f4ca1dfdb33a8ec168e0f6c7ea38 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:00:09 +0300 Subject: [PATCH 4/9] Fix Coding Quality Issues --- webfiori/json/CaseConverter.php | 29 +++++++++----- webfiori/json/Json.php | 69 +++++++++++++-------------------- webfiori/json/JsonConverter.php | 25 ++++++++---- webfiori/json/JsonException.php | 9 +++++ webfiori/json/JsonI.php | 24 +++--------- webfiori/json/JsonTypes.php | 27 +++---------- webfiori/json/Property.php | 27 ++++++++----- 7 files changed, 102 insertions(+), 108 deletions(-) diff --git a/webfiori/json/CaseConverter.php b/webfiori/json/CaseConverter.php index 9d7a7fb..96f5cab 100644 --- a/webfiori/json/CaseConverter.php +++ b/webfiori/json/CaseConverter.php @@ -1,8 +1,17 @@ kebab *
  • camel
  • * - * If the given value is non of the given 3, the string woun't be changed. + * If the given value is none of the given 3, the string wouldn't be changed. * * @return string The same string converted to selected style. * * @since 1.0 */ - public static function convert($value, $style) { + public static function convert(string $value, string $style) : string { if ($style == 'snake') { return self::toSnackCase($value); } else if ($style == 'kebab') { @@ -67,7 +76,7 @@ public static function convert($value, $style) { * * @since 1.0 */ - public static function toCamelCase($value) { + public static function toCamelCase(string $value) : string { $retVal = ''; $changeNextCharCase = false; $valueTrim = trim($value); @@ -100,7 +109,7 @@ public static function toCamelCase($value) { * * @since 1.0 */ - public static function toKebabCase($value) { + public static function toKebabCase(string $value) : string { return self::_toSnakeOrKebab($value, '_', '-'); } /** @@ -113,13 +122,13 @@ public static function toKebabCase($value) { * * @since 1.0 */ - public static function toSnackCase($value) { + public static function toSnackCase(string $value) : string { return self::_toSnakeOrKebab($value, '-', '_'); } - private static function _isUpper($char) { + private static function _isUpper(string $char) : bool { return $char >= 'A' && $char <= 'Z'; } - private static function _toSnakeOrKebab($value, $from, $to) { + private static function _toSnakeOrKebab(string $value, string $from, string $to) : string { $attr1 = str_replace($from, $to, trim($value)); $retVal = ''; $isNumFound = false; @@ -140,7 +149,7 @@ private static function _toSnakeOrKebab($value, $from, $to) { return $retVal; } - private static function addChar($x, &$isNumFound, $to, $char, &$snakeOrKebabFound) { + private static function addChar($x, &$isNumFound, $to, $char, &$snakeOrKebabFound) : string { $isUpper = self::_isUpper($char); $retVal = ''; @@ -160,7 +169,7 @@ private static function addChar($x, &$isNumFound, $to, $char, &$snakeOrKebabFoun return $retVal; } - private static function addNumber($x, &$isNumFound, $to, $char, &$snakeOrKebabFound) { + private static function addNumber($x, &$isNumFound, $to, $char, &$snakeOrKebabFound) : string { $retVal = ''; if ($x == 0) { diff --git a/webfiori/json/Json.php b/webfiori/json/Json.php index 81d538d..5ec6692 100644 --- a/webfiori/json/Json.php +++ b/webfiori/json/Json.php @@ -1,26 +1,12 @@ updateExisting($key, $val)) { $prop = $this->createProb($key, $val); @@ -294,10 +280,10 @@ public function addMultiple(array $arr) { * * @param string $key The name of value key. * - * @return boolean The method will return true if the value is set. + * @return bool The method will return true if the value is set. * If the given value or key is invalid, the method will return false. */ - public function addNull(string $key) { + public function addNull(string $key) : bool { $nul = null; if (!$this->updateExisting($key, $nul)) { @@ -327,7 +313,7 @@ public function addNull(string $key) { * * @param int|double $value The value of the key. * - * @return boolean The method will return true in case the number is + * @return bool The method will return true in case the number is * added. If the given value is not a number or the key value is invalid * string, the method * will return false. @@ -356,11 +342,11 @@ public function addNumber(string $key, $value) { * The object that will be added can implement the interface JsonI to make * the generated JSON string customizable. Also, the object can be of * type Json. If the given value is an object that does not implement the - * interface JsonI or it is not of type Json, + * interface JsonI, or it is not of type Json, * The method will try to extract object information based on its "getXxxxx()" public * methods. Assuming that the object has 2 public methods with names * getFirstProp() and getSecondProp(). - * In that case, the generated JSON will be on the formate + * In that case, the generated JSON will be on the format * {"FirstProp":"prop-1","SecondProp":""}. * This method also can be used to update the value of an existing property. * @@ -368,7 +354,7 @@ public function addNumber(string $key, $value) { * * @param JsonI|Json|object $val The object that will be added. * - * @return boolean The method will return true if the object is added. + * @return bool The method will return true if the object is added. * If the key value is invalid string, the method will return false. * * @since 1.0 @@ -394,11 +380,11 @@ public function addObject(string $key, &$val) { * * This method also can be used to update the value of an existing property. * - * @param string $key The name of the key. Must be non empty string. + * @param string $key The name of the key. Must be non-empty string. * * @param string $val The value of the string. * - * @return boolean The method will return true in case the string is added. + * @return bool The method will return true in case the string is added. * If the given value is not a string or the given key is invalid, the * method will return false. * @@ -558,7 +544,7 @@ public function getPropStyle() { * * @param string $key The name of the key. * - * @return boolean The method will return true if the + * @return bool The method will return true if the * key exists. false if not. * * @since 1.2 @@ -574,7 +560,8 @@ public function hasKey($key) { * This can be used to make the generated output readable by adding * indentation and new lines. * - * @return boolean True if will be formatted. False otherwise. + * @return bool The method will return true if the output will be formatted. + * False otherwise. */ public function isFormatted() { return $this->formatted; @@ -616,7 +603,7 @@ public function remove($keyName) { * a tree. If not formatted, the output string will be generated as one line. * * - * @param boolean $bool True to make the output formatted and false to make + * @param bool $bool True to make the output formatted and false to make * it not. * * @since 1.2.5 @@ -671,7 +658,7 @@ public function setPropsStyle($style) { * sent to. If the file does not exist, the method will attempt to create it. * * @param string $path The folder in file system that the file will be created - * at. If does not exist, the method will attempt to create it. + * at. If it does not exist, the method will attempt to create it. * * @param bool $override If a file exist in the specified location with same * name and this parameter is set to true, the method will override existing diff --git a/webfiori/json/JsonConverter.php b/webfiori/json/JsonConverter.php index c4be741..abb9f4a 100644 --- a/webfiori/json/JsonConverter.php +++ b/webfiori/json/JsonConverter.php @@ -1,4 +1,13 @@ name = ''; $this->setStyle('none'); @@ -199,7 +208,7 @@ public function getType() : string { * This method is only used with arrays since in some cases the developer * would like to have associative arrays as objects. * - * @return boolean If the property will be represented as object, true is + * @return bool If the property will be represented as object, true is * returned. False otherwise. * * @since 1.0 @@ -214,25 +223,25 @@ public function isAsObject() : bool { * This method is only used with arrays since in some cases the developer * would like to have associative arrays as objects. * - * @param boolean $bool True to represent the array as object. False + * @param bool $bool True to represent the array as object. False * otherwise. * * @since 1.0 */ - public function setAsObject($bool) { - $this->asObject = $bool === true; + public function setAsObject(bool $bool) { + $this->asObject = $bool; } /** * Sets the name of the property. * * @param string $name The name of the property. * - * @return boolean If the name is set, the method will return true. False + * @return bool If the name is set, the method will return true. False * otherwise. * * @since 1.0 */ - public function setName(string $name) { + public function setName(string $name) : bool { $keyValidity = self::_isValidKey($name, $this->getStyle()); if ($keyValidity === false) { @@ -294,11 +303,11 @@ public function setValue($val) { /** * Checks if the key is a valid key string. * - * The key is invalid if its an empty string. + * The key is invalid if it's an empty string. * * @param string $key The key that will be validated. * - * @return boolean|string If the key is valid, it will be returned + * @return bool|string If the key is valid, it will be returned * after trimmed. If not valid, false is returned. * * @since 1.0 From 58eee573e860b86d9573d7c7bf492c9574ca0e14 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:02:23 +0300 Subject: [PATCH 5/9] Update php_cs.php.dist --- php_cs.php.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php_cs.php.dist b/php_cs.php.dist index ea7b2cb..ac0a570 100644 --- a/php_cs.php.dist +++ b/php_cs.php.dist @@ -6,8 +6,8 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__) ; -return PhpCsFixer\Config::create() - ->setRules([ +$config = new PhpCsFixer\Config(); +return $config->setRules([ 'align_multiline_comment' => [ 'comment_type' => 'phpdocs_only' ], @@ -54,7 +54,7 @@ return PhpCsFixer\Config::create() 'sort_algorithm' => 'alpha' ], 'ordered_class_elements' => [ - 'sortAlgorithm' => 'alpha', + 'sort_algorithm' => 'alpha', 'order' => [ 'constant_public', 'constant_protected', From 4ceebd403baeb4b7b43c20fa9d8415bbf1d150fd Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:02:34 +0300 Subject: [PATCH 6/9] Update CaseConverter.php --- webfiori/json/CaseConverter.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webfiori/json/CaseConverter.php b/webfiori/json/CaseConverter.php index 96f5cab..d8699f2 100644 --- a/webfiori/json/CaseConverter.php +++ b/webfiori/json/CaseConverter.php @@ -59,7 +59,7 @@ public static function convert(string $value, string $style) : string { if ($style == 'snake') { return self::toSnackCase($value); } else if ($style == 'kebab') { - return self::toKebabCase($value); + return self::toKebabCase($value); } else if ($style == 'camel') { return self::toCamelCase($value); } else { @@ -157,9 +157,8 @@ private static function addChar($x, &$isNumFound, $to, $char, &$snakeOrKebabFoun $retVal .= $to.strtolower($char); } else if ($isUpper && $x == 0) { $retVal .= strtolower($char); - } else if ($isUpper && $x != 0 && $snakeOrKebabFound) { + } else if ($isUpper && $x != 0 && $snakeOrKebabFound) { $retVal .= strtolower($char); - } else { $retVal .= $char; } From 95142aee0104fc01dd4a6f57ea3133d28888bce5 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:02:42 +0300 Subject: [PATCH 7/9] Update JsonConverter.php --- webfiori/json/JsonConverter.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webfiori/json/JsonConverter.php b/webfiori/json/JsonConverter.php index abb9f4a..2533f34 100644 --- a/webfiori/json/JsonConverter.php +++ b/webfiori/json/JsonConverter.php @@ -244,9 +244,9 @@ private static function checkJsonType($val, $valType, $propsStyle, $asObj) { } else if ($valType == JsonTypes::OBJ) { $retVal .= self::objToJson($val, $propsStyle); } else if ($valType == JsonTypes::ARR) { - $retVal .= self::arrayToJsonString($val, $asObj, $propsStyle); - + $retVal .= self::arrayToJsonString($val, $asObj, $propsStyle); } + return $retVal; } private static function checkJsonXType($datatype, $value, Property $prop = null, $isArrayValue = false) { @@ -302,7 +302,6 @@ private static function checkJsonXType($datatype, $value, Property $prop = null, } else { $retVal = self::arrayToJsonX($prop, $value); } - } return $retVal; From 05ee9719a2ab422ddcc39187cca85d3ad91a4134 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:03:02 +0300 Subject: [PATCH 8/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7830907..ecc5592 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ clover.xml .idea/* vendor/* composer.lock +.php-cs-fixer.cache From de7fa80845eb0e16c5ef394f4a95358895f20155 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 28 Feb 2023 21:06:13 +0300 Subject: [PATCH 9/9] Update README.md --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5c2c935..b9c37a4 100644 --- a/README.md +++ b/README.md @@ -19,26 +19,26 @@ A helper class library for creating JSON or JSONx strings in PHP. It can be used ## What is JSON? -Accoording to [json.org](https://www.json.org/json-en.html), JSON is a data exchange format which is based partially on JavaScript. It is easy for humans to read and for machines to understand. JSON data is represented as pairs of keys and values. +According to [json.org](https://www.json.org/json-en.html), JSON is a data exchange format which is based partially on JavaScript. It is easy for humans to read and for machines to understand. JSON data is represented as pairs of keys and values. ## Library Features * Support fo creating well formatted JSON. * Support for creating [JSONx](https://www.ibm.com/docs/en/datapower-gateways/10.0.1?topic=20-jsonx). * Ability to decode JSON strings and convert them to `Json` objects. -* Ability to read JSON files and map JSON values to PHP datatypes. -* Ability to manupulate JSON properties as needed. +* Ability to read JSON files and map JSON values to PHP data types. +* Ability to manipulate JSON properties as needed. ## Supported PHP Versions -| Build Status | -|:-----------:| -|| -|| -|| -|| -|| -|| -|| -|
    (dev)| +| Build Status | +|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| +| | +| | +| | +| | +| | +| | +| | +| | ## Installation If you are using composer to manage your dependencies, then it is possible to install the library by including the entry `"webfiori/jsonx":"*"` in the `require` section of your `composer.json` file to install the latest release.