Skip to content

syntax cleanup, set minimum PHP version to 5.6 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with specific version
uses: shivammathur/setup-php@v2
with:
php-version: '5.4'
php-version: '5.6'

- name: Validate composer.json and composer.lock
run: composer validate --strict
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.4"
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand Down
10 changes: 5 additions & 5 deletions src/Galbar/JsonPath/Expression/Comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public static function evaluate(&$root, &$partial, $leftExpr, $comparator, $righ
}
if ($comparator === Language\Token::COMP_EQ) {
return $left === $right;
} else if ($comparator === Language\Token::COMP_NEQ) {
} elseif ($comparator === Language\Token::COMP_NEQ) {
return $left !== $right;
} else if ($comparator === Language\Token::COMP_LT) {
} elseif ($comparator === Language\Token::COMP_LT) {
return $left < $right;
} else if ($comparator === Language\Token::COMP_GT) {
} elseif ($comparator === Language\Token::COMP_GT) {
return $left > $right;
} else if ($comparator === Language\Token::COMP_LTE) {
} elseif ($comparator === Language\Token::COMP_LTE) {
return $left <= $right;
} else if ($comparator === Language\Token::COMP_GTE) {
} elseif ($comparator === Language\Token::COMP_GTE) {
return $left >= $right;
} else { // $comparator === Language\Token::COMP_RE_MATCH
if (is_string($right) && is_string($left)) {
Expand Down
13 changes: 6 additions & 7 deletions src/Galbar/JsonPath/Expression/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public static function evaluate(&$root, &$partial, $expression)
{
if ($expression === Language\Token::VAL_NULL) {
return null;
} else if ($expression === Language\Token::VAL_TRUE) {
} elseif ($expression === Language\Token::VAL_TRUE) {
return true;
} else if ($expression === Language\Token::VAL_FALSE) {
} elseif ($expression === Language\Token::VAL_FALSE) {
return false;
} else if (is_numeric($expression)) {
} elseif (is_numeric($expression)) {
return floatval($expression);
} else if (preg_match(Language\Regex::EXPR_STRING, $expression)) {
} elseif (preg_match(Language\Regex::EXPR_STRING, $expression)) {
return substr($expression, 1, strlen($expression) - 2);
} else if (preg_match(Language\Regex::EXPR_REGEX, $expression)) {
} elseif (preg_match(Language\Regex::EXPR_REGEX, $expression)) {
return $expression;
} else {
$match = array();
Expand All @@ -54,8 +54,7 @@ public static function evaluate(&$root, &$partial, $expression)
if ($length) {
if (is_array($result[0])) {
return (float) count($result[0]);
}
if (is_string($result[0])) {
} elseif (is_string($result[0])) {
return (float) strlen($result[0]);
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Galbar/JsonPath/InvalidJsonPathException.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class InvalidJsonPathException extends \Exception
*/
public function __construct($token)
{
parent::__construct("Error in JSONPath near '" . $token . "'", 0, null);
parent::__construct("Error in JSONPath near '{$token}'", 0, null);
}
}
12 changes: 6 additions & 6 deletions src/Galbar/JsonPath/JsonObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ function __construct($json = null, $smartGet = false)
{
if ($json === null) {
$this->jsonObject = array();
} else if (is_string($json)) {
} elseif (is_string($json)) {
$this->jsonObject = json_decode($json, true);
if ($this->jsonObject === null) {
throw new InvalidJsonException("string does not contain a valid JSON object.");
throw new InvalidJsonException('String does not contain a valid JSON object.');
}
} else if (is_array($json)) {
} elseif (is_array($json)) {
$this->jsonObject = $json;
} else if (is_object($json)){
} elseif (is_object($json)){
$this->jsonObject = json_decode(json_encode($json), true);
} else {
throw new InvalidJsonException("value does not encode a JSON object.");
throw new InvalidJsonException('Value does not encode a JSON object.');
}
$this->smartGet = $smartGet;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public function &getValue()
*
* @return string
*/
public function getJson($options=0)
public function getJson($options = 0)
{
return json_encode($this->jsonObject, $options);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Galbar/JsonPath/JsonPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function subtreeGet(&$root, &$partial, $jsonPath, $createInexisten
} else {
$jsonPath = $match[2];
}
} else if (Language\ChildSelector::match($jsonPath, $match)) {
} elseif (Language\ChildSelector::match($jsonPath, $match)) {
$contents = $match[0];
foreach ($selection as &$partial) {
list($result, $newHasDiverged) = Operation\SelectChildren::apply($root, $partial, $contents, $createInexistent);
Expand All @@ -71,12 +71,12 @@ public static function subtreeGet(&$root, &$partial, $jsonPath, $createInexisten
} else {
$jsonPath = $match[1];
}
} else if (preg_match(Language\Regex::RECURSIVE_SELECTOR, $jsonPath, $match)) {
} elseif (preg_match(Language\Regex::RECURSIVE_SELECTOR, $jsonPath, $match)) {
$recursivePath = $match[1];
if ($recursivePath[0] === '[') {
$recursivePath = "$$recursivePath";
$recursivePath = "${$recursivePath}";
} else {
$recursivePath = "$.$recursivePath";
$recursivePath = "$.{$recursivePath}";
}
foreach ($selection as &$partial) {
list($result, $newHasDiverged) = Operation\GetRecursive::apply($root, $partial, $recursivePath);
Expand All @@ -87,7 +87,7 @@ public static function subtreeGet(&$root, &$partial, $jsonPath, $createInexisten
$hasDiverged = $hasDiverged || $newHasDiverged;
break;
} else {
$jsonPath = "";
$jsonPath = '';
}
} else {
throw new \JsonPath\InvalidJsonPathException($jsonPath);
Expand Down
1 change: 1 addition & 0 deletions src/Galbar/JsonPath/Language/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Token
const EXPRESSION_END = ')';
const ALL = '*';
const COMA = ',';
const COMMA = ',';
const COLON = ':';
const COMP_EQ = '==';
const COMP_NEQ = '!=';
Expand Down
2 changes: 1 addition & 1 deletion src/Galbar/JsonPath/Operation/SelectChildren.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function($x) { return intval(trim($x)); },
} else if (preg_match(Language\Regex::CHILD_NAME_LIST, $contents, $match)) {
$names = array_map(
function($x) { return trim($x, " \t\n\r\0\x0B'\""); },
explode(Language\Token::COMA, $contents)
explode(Language\Token::COMMA, $contents)
);
if (count($names) > 1) {
$hasDiverged = true;
Expand Down
4 changes: 2 additions & 2 deletions src/Galbar/Utilities/ArraySlice.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static function adjustEndpoint($length, $endpoint, $step)
if ($endpoint < 0) {
$endpoint = ($step < 0 ? -1 : 0);
}
} else if ($endpoint >= $length) {
} elseif ($endpoint >= $length) {
$endpoint = ($step < 0 ? $length - 1 : $length);
}
return $endpoint;
Expand All @@ -71,7 +71,7 @@ private static function adjustSlice($length, &$start, &$stop, &$step)
{
if ($step === null) {
$step = 1;
} else if ($step === 0) {
} elseif ($step === 0) {
throw new \Exception("Step cannot be 0");
}

Expand Down
Loading