From c115e237129d611413b5658f469e61382a383d88 Mon Sep 17 00:00:00 2001 From: Arul Date: Sat, 5 Jun 2021 11:25:26 +0800 Subject: [PATCH] Uses strict comparison everywhere to avoid weird runtime errors --- src/AutoLoader.php | 10 +++---- src/CommentParser.php | 38 ++++++++++++------------- src/Data/Obj.php | 2 +- src/Data/Text.php | 4 +-- src/Data/ValidationInfo.php | 14 +++++----- src/Data/Validator.php | 16 +++++------ src/Data/ValueObject.php | 2 +- src/Explorer/v1/Explorer.php | 28 +++++++++---------- src/Explorer/v2/Explorer.php | 26 ++++++++--------- src/Filter/RateLimit.php | 4 +-- src/Format/CsvFormat.php | 4 +-- src/Format/HtmlFormat.php | 8 +++--- src/Format/JsonFormat.php | 8 +++--- src/Format/PlistFormat.php | 2 +- src/Format/UploadFormat.php | 2 +- src/Format/XmlFormat.php | 16 +++++------ src/Resources.php | 44 ++++++++++++++--------------- src/Restler.php | 34 +++++++++++------------ src/Routes.php | 54 ++++++++++++++++++------------------ src/Scope.php | 2 +- src/UI/Emmet.php | 38 ++++++++++++------------- src/UI/Forms.php | 40 +++++++++++++------------- src/UI/Nav.php | 8 +++--- src/UI/Tags.php | 6 ++-- src/Util.php | 10 +++---- src/views/debug.php | 2 +- 26 files changed, 211 insertions(+), 211 deletions(-) diff --git a/src/AutoLoader.php b/src/AutoLoader.php index 5ed160a07..d6fe25132 100644 --- a/src/AutoLoader.php +++ b/src/AutoLoader.php @@ -92,7 +92,7 @@ public static function thereCanBeOnlyOne() { * key. Default is false we haven't seen this * class. Most of the time it will be the filename * for include and is set to true if we are unable - * to load this class iow true == it does not exist. + * to load this class iow true === it does not exist. * value may also be a callable auto loader function. * * @return mixed The known value for the key or false if key has no value @@ -143,7 +143,7 @@ protected function __construct() if (false !== $path = stream_resolve_include_path( implode($slash, $includePath) )) - if ('composer' == end($includePath) && + if ('composer' === end($includePath) && false !== $classmapPath = stream_resolve_include_path( "$path{$slash}autoload_classmap.php" ) @@ -162,7 +162,7 @@ protected function __construct() $paths = array_filter(array_map( function ($path) { - if (false == $realPath = @realpath($path)) + if (false === $realPath = @realpath($path)) return null; return $realPath . DIRECTORY_SEPARATOR; }, @@ -310,8 +310,8 @@ private function loadThisLoader($className, $loader) */ private function alias($className, $currentClass) { - if ($className == 'Luracast\Restler\string') return; - if ($className == 'Luracast\Restler\mixed') return; + if ($className === 'Luracast\Restler\string') return; + if ($className === 'Luracast\Restler\mixed') return; if ($className != $currentClass && false !== strpos($className, $currentClass)) if (!class_exists($currentClass, false) diff --git a/src/CommentParser.php b/src/CommentParser.php index 6b8b9178f..e1e8e9d1e 100644 --- a/src/CommentParser.php +++ b/src/CommentParser.php @@ -154,13 +154,13 @@ private function extractData($comment) $line = trim($line); $newParam = false; if (empty ($line)) { - if ($mode == 0) { + if ($mode === 0) { $mode++; } else { $addNewline = true; } continue; - } elseif ($line[0] == '@') { + } elseif ($line[0] === '@') { $mode = 2; $newParam = true; } @@ -172,7 +172,7 @@ private function extractData($comment) $longDescription = $description; $description[] = array_shift($longDescription); $mode = 1; - } elseif (substr($line, -1) == '.') { + } elseif (substr($line, -1) === '.') { $mode = 1; } break; @@ -281,7 +281,7 @@ private function parseParam($param, array $value, array $embedded) } } elseif ($allowMultiple) { $data[$param][] = $value; - } elseif ($param == 'param') { + } elseif ($param === 'param') { $arr = array( $data[$param], $value @@ -324,15 +324,15 @@ private function parseEmbeddedData($subject) $name = $matches[1]; $value = $matches[2]; $subject = str_replace($matches[0], '', $subject); - if ($name == 'pattern') { + if ($name === 'pattern') { throw new Exception('Inline pattern tag should follow {@pattern /REGEX_PATTERN_HERE/} format and can optionally include PCRE modifiers following the ending `/`'); } elseif (isset(static::$allowsArrayValue[$name])) { $value = explode(static::$arrayDelimiter, $value); - } elseif ($value == 'true' || $value == 'false') { - $value = $value == 'true'; - } elseif ($value == '') { + } elseif ($value === 'true' || $value === 'false') { + $value = $value === 'true'; + } elseif ($value === '') { $value = true; - } elseif ($name == 'required') { + } elseif ($name === 'required') { $value = explode(static::$arrayDelimiter, $value); } if (defined('Luracast\\Restler\\UI\\HtmlForm::'.$name)) { @@ -359,7 +359,7 @@ private function parseEmbeddedData($subject) $data = $format->decode($str); } } else { // auto detect - if ($str[0] == '{') { + if ($str[0] === '{') { $d = json_decode($str, true); if (json_last_error() != JSON_ERROR_NONE) { throw new Exception('Error parsing embedded JSON data' @@ -378,8 +378,8 @@ private function parseEmbeddedData($subject) $d[$key] = $val; } if (is_string($val)) { - if ($val == 'true' || $val == 'false') { - $d[$key] = $val == 'true' ? true : false; + if ($val === 'true' || $val === 'false') { + $d[$key] = $val === 'true' ? true : false; } else { $val = explode(self::$arrayDelimiter, $val); if (count($val) > 1) { @@ -451,7 +451,7 @@ private function formatAuthor(array $value) { $r = array(); $email = end($value); - if ($email[0] == '<') { + if ($email[0] === '<') { $email = substr($email, 1, -1); array_pop($value); $r['email'] = $email; @@ -464,7 +464,7 @@ private function formatReturn(array $value) { $data = explode('|', array_shift($value)); $r = array( - 'type' => count($data) == 1 ? $data[0] : $data + 'type' => count($data) === 1 ? $data[0] : $data ); $r['description'] = implode(' ', $value); return $r; @@ -476,15 +476,15 @@ private function formatParam(array $value) $data = array_shift($value); if (empty($data)) { $r['type'] = 'mixed'; - } elseif ($data[0] == '$') { + } elseif ($data[0] === '$') { $r['name'] = substr($data, 1); $r['type'] = 'mixed'; } else { $data = explode('|', $data); - $r['type'] = count($data) == 1 ? $data[0] : $data; + $r['type'] = count($data) === 1 ? $data[0] : $data; $data = array_shift($value); - if (!empty($data) && $data[0] == '$') { + if (!empty($data) && $data[0] === '$') { $r['name'] = substr($data, 1); } } @@ -504,12 +504,12 @@ private function formatVar(array $value) $data = array_shift($value); if (empty($data)) { $r['type'] = 'mixed'; - } elseif ($data[0] == '$') { + } elseif ($data[0] === '$') { $r['name'] = substr($data, 1); $r['type'] = 'mixed'; } else { $data = explode('|', $data); - $r['type'] = count($data) == 1 ? $data[0] : $data; + $r['type'] = count($data) === 1 ? $data[0] : $data; } if (isset($r['type']) && Text::endsWith($r['type'], '[]')) { $r[static::$embeddedDataName]['type'] = substr($r['type'], 0, -2); diff --git a/src/Data/Obj.php b/src/Data/Obj.php index 8fe2a79ab..c82a54add 100644 --- a/src/Data/Obj.php +++ b/src/Data/Obj.php @@ -128,7 +128,7 @@ public static function toArray($object, $array [$key] = $value; $count++; } - return $forceObjectTypeWhenEmpty && $count == 0 ? $object : $array; + return $forceObjectTypeWhenEmpty && $count === 0 ? $object : $array; } return $object; diff --git a/src/Data/Text.php b/src/Data/Text.php index cd1149e11..3203feafc 100644 --- a/src/Data/Text.php +++ b/src/Data/Text.php @@ -57,7 +57,7 @@ public static function beginsWith($haystack, $needle) public static function endsWith($haystack, $needle) { $length = strlen($needle); - if ($length == 0) { + if ($length === 0) { return true; } return (substr($haystack, -$length) === $needle); @@ -93,4 +93,4 @@ public static function slug($name) { return preg_replace('/[^a-zA-Z]+/', '-', strtolower(strip_tags($name))); } -} \ No newline at end of file +} diff --git a/src/Data/ValidationInfo.php b/src/Data/ValidationInfo.php index fc05c5386..a609c9c2a 100644 --- a/src/Data/ValidationInfo.php +++ b/src/Data/ValidationInfo.php @@ -172,7 +172,7 @@ class ValidationInfo implements iValueObject public static function numericValue($value) { - return ( int )$value == $value + return ( int )$value === $value ? ( int )$value : floatval($value); } @@ -227,19 +227,19 @@ private function getProperty(array &$from, $property) ); unset($from[CommentParser::$embeddedDataName][$property]); - if ($property == 'type' && $p == 'array' && $p2) { + if ($property === 'type' && $p === 'array' && $p2) { $this->contentType = $p2; return $p; } $r = is_null($p2) ? (is_null($p) ? null : $p) : $p2; if (!is_null($r)) { - if ($property == 'min' || $property == 'max') { + if ($property === 'min' || $property === 'max') { return static::numericValue($r); - } elseif ($property == 'required' || $property == 'fix') { + } elseif ($property === 'required' || $property === 'fix') { return static::booleanValue($r); - } elseif ($property == 'choice') { + } elseif ($property === 'choice') { return static::arrayValue($r); - } elseif ($property == 'pattern') { + } elseif ($property === 'pattern') { return static::stringValue($r); } } @@ -256,7 +256,7 @@ public function __construct(array $info) $inner = Util::nestedValue($info, 'properties'); $this->rules = !empty($inner) ? $inner + $info : $info; unset($this->rules['properties']); - if (is_string($this->type) && $this->type == 'integer') { + if (is_string($this->type) && $this->type === 'integer') { $this->type = 'int'; } } diff --git a/src/Data/Validator.php b/src/Data/Validator.php index 023fc7c4d..d6973f85a 100644 --- a/src/Data/Validator.php +++ b/src/Data/Validator.php @@ -514,11 +514,11 @@ public static function validate($input, ValidationInfo $info, $full = null) case 'number' : if (!is_numeric($input)) { $error .= '. Expecting ' - . ($info->type == 'int' ? 'integer' : 'numeric') + . ($info->type === 'int' ? 'integer' : 'numeric') . ' value'; break; } - if ($info->type == 'int' && (int)$input != $input) { + if ($info->type === 'int' && (int)$input != $input) { if ($info->fix) { $r = (int)$input; } else { @@ -600,7 +600,7 @@ public static function validate($input, ValidationInfo $info, $full = null) } } if ($info->fix) { - return $input ? true : false; + return (bool)$input; } $error .= '. Expecting boolean value'; break; @@ -612,20 +612,20 @@ public static function validate($input, ValidationInfo $info, $full = null) $contentType = Util::nestedValue($info, 'contentType') ?: null; if ($info->fix) { - if ($contentType == 'indexed') { + if ($contentType === 'indexed') { $input = $info->filterArray($input, true); - } elseif ($contentType == 'associative') { + } elseif ($contentType === 'associative') { $input = $info->filterArray($input, false); } } elseif ( - $contentType == 'indexed' && + $contentType === 'indexed' && array_values($input) != $input ) { $error .= '. Expecting a list of items but an item is given'; break; } elseif ( - $contentType == 'associative' && - array_values($input) == $input && + $contentType === 'associative' && + array_values($input) === $input && count($input) ) { $error .= '. Expecting an item but a list is given'; diff --git a/src/Data/ValueObject.php b/src/Data/ValueObject.php index 5a2b001e8..53138c7fd 100644 --- a/src/Data/ValueObject.php +++ b/src/Data/ValueObject.php @@ -50,7 +50,7 @@ public function __toArray() $r = get_object_vars($this); $methods = get_class_methods($this); foreach ($methods as $m) { - if (substr($m, 0, 3) == 'get') { + if (substr($m, 0, 3) === 'get') { $r [lcfirst(substr($m, 3))] = @$this->{$m} (); } } diff --git a/src/Explorer/v1/Explorer.php b/src/Explorer/v1/Explorer.php index 7ab8eceef..a4132d983 100644 --- a/src/Explorer/v1/Explorer.php +++ b/src/Explorer/v1/Explorer.php @@ -138,7 +138,7 @@ public function __construct() */ public function get() { - if (func_num_args() > 1 && func_get_arg(0) == 'resources') { + if (func_num_args() > 1 && func_get_arg(0) === 'resources') { /** * BUGFIX: * If we use common resourcePath (e.g. $r->addAPIClass([api-class], 'api/shop')), than we must determine resource-ID of e.g. 'api/shop'! @@ -155,7 +155,7 @@ public function get() $redirect = false; if ( (empty($filename) && substr($_SERVER['REQUEST_URI'], -1, 1) != '/') || - $filename == 'index.html' + $filename === 'index.html' ) { $status = 302; $url = $this->restler->getBaseUrl() . '/' . $this->base() . '/'; @@ -165,7 +165,7 @@ public function get() } if ( isset($this->restler->responseFormat) && - $this->restler->responseFormat->getExtension() == 'js' + $this->restler->responseFormat->getExtension() === 'js' ) { $filename .= '.js'; } @@ -277,7 +277,7 @@ function ($x, $y) use ($order) { } } if (false !== $resource) { - if ($resource == 'root') { + if ($resource === 'root') { $resource = ''; } if (isset($a[$resource])) { @@ -310,9 +310,9 @@ private function operation($route) $r, new ValidationInfo(Util::nestedValue($m, 'return') ?: array()) ); - if (is_null($r->type) || 'mixed' == $r->type) { + if (is_null($r->type) || 'mixed' === $r->type) { $r->type = 'array'; - } elseif ($r->type == 'null') { + } elseif ($r->type === 'null') { $r->type = 'void'; } elseif (Text::contains($r->type, '|')) { $r->type = 'array'; @@ -338,7 +338,7 @@ private function parameters(array $route) foreach ($route['metadata']['param'] as $param) { $info = new ValidationInfo($param); $description = isset($param['description']) ? $param['description'] : ''; - if ('body' == $info->from) { + if ('body' === $info->from) { if ($info->required) { $required = true; } @@ -350,7 +350,7 @@ private function parameters(array $route) } if (!empty($children)) { if ( - 1 == count($children) && + 1 === count($children) && (static::$allowScalarValueOnRequestBody || !empty($children[0]['children'])) ) { $firstChild = $children[0]; @@ -417,7 +417,7 @@ private function parameter(ValidationInfo $info, $description = '') //TODO: $p->items and $p->uniqueItems boolean } $p->description = $description; - $p->paramType = $info->from; //$info->from == 'body' ? 'form' : $info->from; + $p->paramType = $info->from; //$info->from === 'body' ? 'form' : $info->from; $p->required = $info->required; $p->allowMultiple = false; return $p; @@ -497,13 +497,13 @@ private function model($type, array $children) private function setType(&$object, ValidationInfo $info) { //TODO: proper type management - if ($info->type == 'array') { + if ($info->type === 'array') { if ($info->children) { $this->model($info->contentType, $info->children); $object->items = (object)array( '$ref' => $info->contentType ); - } elseif ($info->contentType && $info->contentType == 'associative') { + } elseif ($info->contentType && $info->contentType === 'associative') { unset($info->contentType); $this->model($info->type = 'Object', array( array( @@ -536,11 +536,11 @@ private function setType(&$object, ValidationInfo $info) } $object->type = $info->type; $has64bit = PHP_INT_MAX > 2147483647; - if ($object->type == 'integer') { + if ($object->type === 'integer') { $object->format = $has64bit ? 'int64' : 'int32'; - } elseif ($object->type == 'number') { + } elseif ($object->type === 'number') { $object->format = $has64bit ? 'double' : 'float'; @@ -607,4 +607,4 @@ public static function __getMaximumSupportedVersion() { return Scope::get('Restler')->getApiVersion(); } -} \ No newline at end of file +} diff --git a/src/Explorer/v2/Explorer.php b/src/Explorer/v2/Explorer.php index f72e01c2b..12a3ebe82 100644 --- a/src/Explorer/v2/Explorer.php +++ b/src/Explorer/v2/Explorer.php @@ -144,7 +144,7 @@ class Explorer implements iProvideMultiVersionApi */ public function get() { - if (func_num_args() > 1 && func_get_arg(0) == 'swagger') { + if (func_num_args() > 1 && func_get_arg(0) === 'swagger') { /** * BUGFIX: * If we use common resourcePath (e.g. $r->addAPIClass([api-class], 'api/shop')), than we must determine resource-ID of e.g. 'api/shop'! @@ -162,7 +162,7 @@ public function get() $redirect = false; if ( (empty($filename) && substr($_SERVER['REQUEST_URI'], -1, 1) != '/') || - $filename == 'index.html' + $filename === 'index.html' ) { $status = 302; $url = $this->restler->getBaseUrl() . '/' . $this->base() . '/'; @@ -172,7 +172,7 @@ public function get() } if ( isset($this->restler->responseFormat) && - $this->restler->responseFormat->getExtension() == 'js' + $this->restler->responseFormat->getExtension() === 'js' ) { $filename .= '.js'; } @@ -267,9 +267,9 @@ private function operation($route) $r, new ValidationInfo(Util::nestedValue($m, 'return') ?: array()) ); - if (is_null($r->type) || 'mixed' == $r->type) { + if (is_null($r->type) || 'mixed' === $r->type) { $r->type = 'array'; - } elseif ($r->type == 'null') { + } elseif ($r->type === 'null') { $r->type = 'void'; } elseif (Text::contains($r->type, '|')) { $r->type = 'array'; @@ -295,7 +295,7 @@ private function parameters(array $route) foreach ($route['metadata']['param'] as $param) { $info = new ValidationInfo($param); $description = isset($param['description']) ? $param['description'] : ''; - if ('body' == $info->from) { + if ('body' === $info->from) { if ($param['name'] === Defaults::$fullRequestDataName) { continue; } @@ -310,7 +310,7 @@ private function parameters(array $route) } if (!empty($children)) { if ( - 1 == count($children) && + 1 === count($children) && (static::$allowScalarValueOnRequestBody || !empty($children[0]['children'])) ) { $firstChild = $children[0]; @@ -378,7 +378,7 @@ private function parameter(ValidationInfo $info, $description = '') //TODO: $p->items and $p->uniqueItems boolean } $p->description = $description; - $p->in = $info->from; //$info->from == 'body' ? 'form' : $info->from; + $p->in = $info->from; //$info->from === 'body' ? 'form' : $info->from; $p->required = $info->required; //$p->allowMultiple = false; @@ -458,7 +458,7 @@ private function setType(&$object, ValidationInfo $info) { //TODO: proper type management $type = Util::getShortName($info->type); - if ($info->type == 'array') { + if ($info->type === 'array') { $object->type = 'array'; if ($info->children) { $contentType = Util::getShortName($info->contentType); @@ -466,7 +466,7 @@ private function setType(&$object, ValidationInfo $info) $object->items = (object)array( '$ref' => "#/definitions/$contentType" ); - } elseif ($info->contentType && $info->contentType == 'associative') { + } elseif ($info->contentType && $info->contentType === 'associative') { unset($info->contentType); $this->model($info->type = 'Object', array( array( @@ -516,11 +516,11 @@ private function setType(&$object, ValidationInfo $info) } $has64bit = PHP_INT_MAX > 2147483647; if (isset($object->type)) { - if ($object->type == 'integer') { + if ($object->type === 'integer') { $object->format = $has64bit ? 'int64' : 'int32'; - } elseif ($object->type == 'number') { + } elseif ($object->type === 'number') { $object->format = $has64bit ? 'double' : 'float'; @@ -583,4 +583,4 @@ public static function __getMaximumSupportedVersion() { return Scope::get('Restler')->getApiVersion(); } -} \ No newline at end of file +} diff --git a/src/Filter/RateLimit.php b/src/Filter/RateLimit.php index e5705136f..8b938959c 100644 --- a/src/Filter/RateLimit.php +++ b/src/Filter/RateLimit.php @@ -77,7 +77,7 @@ public static function setLimit( public function __isAllowed() { if (static::$authenticatedUsagePerUnit - == static::$usagePerUnit + === static::$usagePerUnit ) return $this->check(); return null; } @@ -175,4 +175,4 @@ private function duration($secs) } return implode(' ', $ret); //." $unit."; } -} \ No newline at end of file +} diff --git a/src/Format/CsvFormat.php b/src/Format/CsvFormat.php index c33557f84..a938989ca 100644 --- a/src/Format/CsvFormat.php +++ b/src/Format/CsvFormat.php @@ -48,7 +48,7 @@ public function encode($data, $humanReadable = false) Obj::$separatorChar = false; $data = Obj::toArray($data); Obj::$separatorChar = $char; - if (is_array($data) && array_values($data) == $data) { + if (is_array($data) && array_values($data) === $data) { //if indexed array $lines = array(); $row = array_shift($data); @@ -178,4 +178,4 @@ public function decodeStream($stream) Obj::$separatorChar = $char; return $decoded; } -} \ No newline at end of file +} diff --git a/src/Format/HtmlFormat.php b/src/Format/HtmlFormat.php index 493e3e440..ec8d9e0ed 100644 --- a/src/Format/HtmlFormat.php +++ b/src/Format/HtmlFormat.php @@ -251,7 +251,7 @@ public static function mustache($data, $debug = true) */ public static function php($data, $debug = true) { - if (static::$view == 'debug') { + if (static::$view === 'debug') { static::$viewPath = dirname(__DIR__) . '/views'; } $view = static::getViewFile(true); @@ -429,11 +429,11 @@ public function encode($data, $humanReadable = false) } } if (method_exists($class = get_called_class(), $template)) { - if ($template == 'blade') { + if ($template === 'blade') { $this->checkDependency(self::BLADE); - } elseif ($template == 'twig') { + } elseif ($template === 'twig') { $this->checkDependency(self::TWIG); - } elseif ($template == 'mustache' || $template == 'handlebar') { + } elseif ($template === 'mustache' || $template === 'handlebar') { $this->checkDependency(self::MUSTACHE); } return call_user_func("$class::$template", $data, $humanReadable); diff --git a/src/Format/JsonFormat.php b/src/Format/JsonFormat.php index 170676c07..f83d47f3b 100644 --- a/src/Format/JsonFormat.php +++ b/src/Format/JsonFormat.php @@ -63,12 +63,12 @@ public function encode($data, $humanReadable = false) self::$unEscapedSlashes = $humanReadable; } if (is_null(self::$unEscapedUnicode)) { - self::$unEscapedUnicode = $this->charset == 'utf-8'; + self::$unEscapedUnicode = $this->charset === 'utf-8'; } $options = 0; - if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) // PHP >= 5.4 + if ((PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION >= 4) // PHP >= 5.4 || PHP_MAJOR_VERSION > 5 // PHP >= 6.0 ) { @@ -134,7 +134,7 @@ public function decode($data) $options = 0; if (self::$bigIntAsString) { - if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) // PHP >= 5.4 + if ((PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION >= 4) // PHP >= 5.4 || PHP_MAJOR_VERSION > 5 // PHP >= 6.0 ) { $options |= JSON_BIGINT_AS_STRING; @@ -214,7 +214,7 @@ private function formatJson($json) } break; case '"' : - if ($c == 0) { + if ($c === 0) { $inString = true; } elseif ($c > 0 && $json [$c - 1] != '\\') { $inString = !$inString; diff --git a/src/Format/PlistFormat.php b/src/Format/PlistFormat.php index f1eca0193..fff368b1b 100644 --- a/src/Format/PlistFormat.php +++ b/src/Format/PlistFormat.php @@ -32,7 +32,7 @@ class PlistFormat extends DependentMultiFormat public function setMIME($mime) { static::$mime = $mime; - static::$compact = $mime == 'application/x-plist'; + static::$compact = $mime === 'application/x-plist'; } /** diff --git a/src/Format/UploadFormat.php b/src/Format/UploadFormat.php index b58b0f02b..dbcf71bf3 100644 --- a/src/Format/UploadFormat.php +++ b/src/Format/UploadFormat.php @@ -93,7 +93,7 @@ protected static function checkFile(& $file, $doMimeCheck = false, $doSizeCheck } } catch (RestException $e) { if (static::$suppressExceptionsAsError) { - $file['error'] = $e->getCode() == 413 ? 1 : 6; + $file['error'] = $e->getCode() === 413 ? 1 : 6; $file['exception'] = $e; } else { throw $e; diff --git a/src/Format/XmlFormat.php b/src/Format/XmlFormat.php index 6f8606eb1..4fa893263 100644 --- a/src/Format/XmlFormat.php +++ b/src/Format/XmlFormat.php @@ -109,7 +109,7 @@ public function encode($data, $humanReadable = false) if (static::$useNamespaces) { foreach (static::$namespaces as $prefix => $ns) { if (isset(static::$namespacedProperties[static::$rootName]) - && static::$namespacedProperties[static::$rootName] == $prefix + && static::$namespacedProperties[static::$rootName] === $prefix ) { continue; } @@ -185,7 +185,7 @@ public function write(XMLWriter $xml, $data, $parent) $text [] = (string)$data; } if (!empty($text)) { - if (count($text) == 1) { + if (count($text) === 1) { in_array($parent, static::$cdataNames) ? $xml->writeCdata(implode('', $text)) : $xml->text(implode('', $text)); @@ -200,7 +200,7 @@ public function write(XMLWriter $xml, $data, $parent) public function decode($data) { try { - if ($data == '') { + if ($data === '') { return array(); } libxml_use_internal_errors(true); @@ -221,7 +221,7 @@ public function decode($data) $namespaces = $xml->getNamespaces(); if (count($namespaces)) { $p = strpos($data, $xml->getName()); - if ($p && $data[$p - 1] == ':') { + if ($p && $data[$p - 1] === ':') { $s = strpos($data, '<') + 1; $prefix = substr($data, $s, $p - $s - 1); static::$namespacedProperties[static::$rootName] = $prefix; @@ -229,7 +229,7 @@ public function decode($data) } } $data = $this->read($xml); - if (count($data) == 1 && isset($data[static::$textNodeName])) { + if (count($data) === 1 && isset($data[static::$textNodeName])) { $data = $data[static::$textNodeName]; } @@ -258,7 +258,7 @@ public function read(SimpleXMLElement $xml, $namespaces = null) } $children = $xml->children(); foreach ($children as $key => $value) { - if ($key == static::$defaultTagName) { + if ($key === static::$defaultTagName) { $r[] = $this->read($value); } elseif (isset($r[$key])) { if (is_array($r[$key])) { @@ -338,10 +338,10 @@ public static function setType($value) if (empty($value) && $value !== '0') { return null; } - if ($value == 'true') { + if ($value === 'true') { return true; } - if ($value == 'false') { + if ($value === 'false') { return true; } if (is_numeric($value)) { diff --git a/src/Resources.php b/src/Resources.php index d45756b39..18abfdecf 100644 --- a/src/Resources.php +++ b/src/Resources.php @@ -198,10 +198,10 @@ public function get($id = '') } elseif (false !== ($pos = strpos($id, '-v'))) { //$version = intval(substr($id, $pos + 2)); $id = substr($id, 0, $pos); - } elseif ($id[0] == 'v' && is_numeric($v = substr($id, 1))) { + } elseif ($id[0] === 'v' && is_numeric($v = substr($id, 1))) { $id = ''; //$version = $v; - } elseif ($id == 'root' || $id == 'index') { + } elseif ($id === 'root' || $id === 'index') { $id = ''; } $this->_models = new stdClass(); @@ -244,14 +244,14 @@ public function get($id = '') } foreach (static::$excludedPaths as $exclude) { if (empty($exclude)) { - if ($fullPath == $exclude) + if ($fullPath === $exclude) continue 2; } elseif (Text::beginsWith($fullPath, $exclude)) { continue 2; } } $m = $route['metadata']; - if ($id == '' && $m['resourcePath'] != '') { + if ($id === '' && $m['resourcePath'] != '') { continue; } if (isset($filter[$httpMethod][$fullPath])) { @@ -272,10 +272,10 @@ public function get($id = '') } $parts = explode('/', $fullPath); $pos = count($parts) - 1; - if (count($parts) == 1 && $httpMethod == 'GET') { + if (count($parts) === 1 && $httpMethod === 'GET') { } else { for ($i = 0; $i < count($parts); $i++) { - if (strlen($parts[$i]) && $parts[$i][0] == '{') { + if (strlen($parts[$i]) && $parts[$i][0] === '{') { $pos = $i - 1; break; } @@ -325,7 +325,7 @@ public function get($id = '') foreach ($m['param'] as $param) { //combine body params as one $p = $this->_parameter($param); - if ($p->paramType == 'body') { + if ($p->paramType === 'body') { $this->_appendToBody($p); } else { $operation->parameters[] = $p; @@ -349,7 +349,7 @@ public function get($id = '') $this->_model($responseClass); $operation->responseClass = $this->_noNamespace($responseClass); - } elseif (strtolower($responseClass) == 'array') { + } elseif (strtolower($responseClass) === 'array') { $operation->responseClass = 'Array'; $rt = $m['return']; if (isset( @@ -370,7 +370,7 @@ public function get($id = '') if (static::$groupOperations) { foreach ($r->apis as $a) { - if ($a->path == "$prefix/$fullPath") { + if ($a->path === "$prefix/$fullPath") { $api = $a; break; } @@ -531,16 +531,16 @@ protected function _parameter($param) if (is_array($type)) { $type = array_shift($type); } - if ($type == 'array') { + if ($type === 'array') { $contentType = Util::nestedValue( $param, CommentParser::$embeddedDataName, 'type' ); if ($contentType) { - if ($contentType == 'indexed') { + if ($contentType === 'indexed') { $type = 'Array'; - } elseif ($contentType == 'associative') { + } elseif ($contentType === 'associative') { $type = 'Object'; } else { $type = "Array[$contentType]"; @@ -599,7 +599,7 @@ protected function _getBody() $n = isset($this->_bodyParam['names']) ? array_values($this->_bodyParam['names']) : array(); - if (count($n) == 1) { + if (count($n) === 1) { if (isset($this->_models->{$n[0]->dataType})) { // ============ custom class =================== $r = $n[0]; @@ -648,7 +648,7 @@ protected function _getBody() $r->defaultValue = "[ ]"; return $r; } - } elseif ($n[0]->dataType == 'Array') { + } elseif ($n[0]->dataType === 'Array') { // ============ array =============================== $r = $n[0]; $r->description = "Paste JSON array data here" @@ -657,7 +657,7 @@ protected function _getBody() $r->defaultValue = "[\n {\n \"" . "property\" : \"\"\n }\n]"; return $r; - } elseif ($n[0]->dataType == 'Object') { + } elseif ($n[0]->dataType === 'Object') { // ============ object ============================== $r = $n[0]; $r->description = "Paste JSON object data here" @@ -671,7 +671,7 @@ protected function _getBody() $p = array_values($this->_bodyParam['description']); $r->name = 'REQUEST_BODY'; $r->description = "Paste JSON data here"; - if (count($p) == 0 && $this->_fullDataRequested) { + if (count($p) === 0 && $this->_fullDataRequested) { $r->required = $this->_fullDataRequested->required; $r->defaultValue = "{\n \"property\" : \"\"\n}"; } else { @@ -763,7 +763,7 @@ protected function _model($className, $instance = null) ) { $properties[$key]['required'] = true; } - if ($type == 'Array') { + if ($type === 'Array') { $itemType = Util::nestedValue( $propertyMetaData, CommentParser::$embeddedDataName, @@ -905,7 +905,7 @@ public function index() $nextVersion = $version + 1; if ($nextVersion <= $this->restler->getApiVersion()) { list($status, $data) = $this->_loadResource("/v$nextVersion/resources.json"); - if ($status == 200) { + if ($status === 200) { $r->apis = array_merge($r->apis, $data->apis); $r->apiVersion = $data->apiVersion; } @@ -936,7 +936,7 @@ protected function _mapResources(array $allRoutes, array &$map, $version = 1) foreach ($allRoutes as $fullPath => $routes) { $path = explode('/', $fullPath); $resource = isset($path[0]) ? $path[0] : ''; - if ($resource == 'resources' || Text::endsWith($resource, 'index')) + if ($resource === 'resources' || Text::endsWith($resource, 'index')) continue; foreach ($routes as $httpMethod => $route) { if (in_array($httpMethod, static::$excludedHttpMethods)) { @@ -948,7 +948,7 @@ protected function _mapResources(array $allRoutes, array &$map, $version = 1) foreach (static::$excludedPaths as $exclude) { if (empty($exclude)) { - if ($fullPath == $exclude) + if ($fullPath === $exclude) continue 2; } elseif (Text::beginsWith($fullPath, $exclude)) { continue 2; @@ -956,8 +956,8 @@ protected function _mapResources(array $allRoutes, array &$map, $version = 1) } $res = $resource - ? ($version == 1 ? "/resources/$resource" : "/v$version/resources/$resource-v$version") - : ($version == 1 ? "/resources/root" : "/v$version/resources/root-v$version"); + ? ($version === 1 ? "/resources/$resource" : "/v$version/resources/$resource-v$version") + : ($version === 1 ? "/resources/root" : "/v$version/resources/root-v$version"); if (empty($map[$res])) { $map[$res] = isset( diff --git a/src/Restler.php b/src/Restler.php index 983d79372..8b5389f1b 100644 --- a/src/Restler.php +++ b/src/Restler.php @@ -404,7 +404,7 @@ public function setSupportedFormats($format = null /*[, $format2...$farmatN]*/) if (!$obj instanceof iFormat) throw new Exception('Invalid format class; must implement ' . 'iFormat interface'); - if ($throwException && get_class($obj) == get_class($this->requestFormat)) { + if ($throwException && get_class($obj) === get_class($this->requestFormat)) { $throwException = false; } @@ -517,9 +517,9 @@ protected function getPath() $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '80'; $port = isset($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['HTTP_X_FORWARDED_PORT'] : $port; // Amazon ELB } - $https = $port == '443' || - (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || // Amazon ELB - (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'); + $https = $port === '443' || + (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || // Amazon ELB + (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'); $baseUrl = ($https ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']; if ($port != '80' && $port != '443') $baseUrl .= ':' . $port; @@ -537,12 +537,12 @@ protected function getPath() rtrim($path, '/') //remove trailing slash if found ); - if (Defaults::$useUrlBasedVersioning && strlen($path) && $path[0] == 'v') { + if (Defaults::$useUrlBasedVersioning && strlen($path) && $path[0] === 'v') { $version = intval(substr($path, 1)); if ($version && $version <= $this->apiVersion) { $this->requestedApiVersion = $version; $path = explode('/', $path, 2); - $path = count($path) == 2 ? $path[1] : ''; + $path = count($path) === 2 ? $path[1] : ''; } } else { $this->requestedApiVersion = $this->apiMinimumVersion; @@ -572,7 +572,7 @@ protected function getRequestFormat() if (false !== $pos = strpos($mime, ';')) { $mime = substr($mime, 0, $pos); } - if ($mime == UrlEncodedFormat::MIME) + if ($mime === UrlEncodedFormat::MIME) $format = Scope::get('UrlEncodedFormat'); elseif (isset($this->formatMap[$mime])) { $format = Scope::get($this->formatMap[$mime]); @@ -619,9 +619,9 @@ public function getRequestStream() public function getRequestData($includeQueryParameters = true) { $get = UrlEncodedFormat::decoderTypeFix($_GET); - if ($this->requestMethod == 'PUT' - || $this->requestMethod == 'PATCH' - || $this->requestMethod == 'POST' + if ($this->requestMethod === 'PUT' + || $this->requestMethod === 'PATCH' + || $this->requestMethod === 'POST' ) { if (!empty($this->requestData)) { return $includeQueryParameters @@ -712,7 +712,7 @@ protected function negotiate() protected function negotiateCORS() { if ( - $this->requestMethod == 'OPTIONS' + $this->requestMethod === 'OPTIONS' && Defaults::$crossOriginResourceSharing ) { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) @@ -724,7 +724,7 @@ protected function negotiateCORS() . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); header('Access-Control-Allow-Origin: ' . - ((Defaults::$accessControlAllowOrigin == '*' && isset($_SERVER['HTTP_ORIGIN'])) + ((Defaults::$accessControlAllowOrigin === '*' && isset($_SERVER['HTTP_ORIGIN'])) ? $_SERVER['HTTP_ORIGIN'] : Defaults::$accessControlAllowOrigin)); header('Access-Control-Allow-Credentials: true'); @@ -889,7 +889,7 @@ protected function negotiateLanguage() $langList = Util::sortByPriority($_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langList as $lang => $quality) { foreach (Defaults::$supportedLanguages as $supported) { - if (strcasecmp($supported, $lang) == 0) { + if (strcasecmp($supported, $lang) === 0) { $found = true; Defaults::$language = $supported; break 2; @@ -1093,7 +1093,7 @@ protected function compose() public function composeHeaders(RestException $e = null) { //only GET method should be cached if allowed by API developer - $expires = $this->requestMethod == 'GET' ? Defaults::$headerExpires : 0; + $expires = $this->requestMethod === 'GET' ? Defaults::$headerExpires : 0; if(!is_array(Defaults::$headerCacheControl)) Defaults::$headerCacheControl = array(Defaults::$headerCacheControl); $cacheControl = Defaults::$headerCacheControl[0]; @@ -1112,7 +1112,7 @@ public function composeHeaders(RestException $e = null) && isset($_SERVER['HTTP_ORIGIN']) ) { header('Access-Control-Allow-Origin: ' . - (Defaults::$accessControlAllowOrigin == '*' + (Defaults::$accessControlAllowOrigin === '*' ? $_SERVER['HTTP_ORIGIN'] : Defaults::$accessControlAllowOrigin) ); @@ -1167,7 +1167,7 @@ protected function respond() usleep(1e6 * (Defaults::$throttle / 1e3 - $elapsed)); } } - if ($this->responseCode == 401) { + if ($this->responseCode === 401) { $authString = count($this->authClasses) ? Scope::get($this->authClasses[0])->__getWWWAuthenticateString() : 'Unknown'; @@ -1605,7 +1605,7 @@ public function getEvents() */ public function __get($name) { - if ($name[0] == '_') { + if ($name[0] === '_') { $hiddenProperty = substr($name, 1); if (isset($this->$hiddenProperty)) { return $this->$hiddenProperty; diff --git a/src/Routes.php b/src/Routes.php index 8d9f837bb..7d2e49a49 100644 --- a/src/Routes.php +++ b/src/Routes.php @@ -89,7 +89,7 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) foreach ($methods as $method) { $methodUrl = strtolower($method->getName()); //method name should not begin with _ - if ($methodUrl[0] == '_') { + if ($methodUrl[0] === '_') { continue; } $doc = $method->getDocComment(); @@ -101,7 +101,7 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) } //@access should not be private if (isset($metadata['access']) - && $metadata['access'] == 'private' + && $metadata['access'] === 'private' ) { continue; } @@ -161,7 +161,7 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) if (is_null($type) && isset($m['type'])) { $type = $m['type']; } - if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type == 'string') { + if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type === 'string') { $p['type'] = static::$fieldTypesByName[$m['name']]; } $m ['default'] = $defaults [$position]; @@ -189,7 +189,7 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) if (isset($modelName)) { $m['model'] = $modelName; } - if ($m['name'] == Defaults::$fullRequestDataName) { + if ($m['name'] === Defaults::$fullRequestDataName) { $from = 'body'; if (!isset($m['type'])) { $type = $m['type'] = 'array'; @@ -215,7 +215,7 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) $type = $m['type'] = static::type($defaults[$position]); } - if ($allowAmbiguity || $from == 'path') { + if ($allowAmbiguity || $from === 'path') { $pathParams [] = $position; } $position++; @@ -224,9 +224,9 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) if ($method->isProtected()) { $accessLevel = 3; } elseif (isset($metadata['access'])) { - if ($metadata['access'] == 'protected') { + if ($metadata['access'] === 'protected') { $accessLevel = 2; - } elseif ($metadata['access'] == 'hybrid') { + } elseif ($metadata['access'] === 'hybrid') { $accessLevel = 1; } } elseif (isset($metadata['protected'])) { @@ -266,9 +266,9 @@ public static function addAPIClass($className, $resourcePath = '', $version = 1) strpos($url, ':' . $p['name']); if ($inPath) { $copy['metadata']['param'][$i][$dataName]['from'] = 'path'; - } elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') { + } elseif ($httpMethod === 'GET' || $httpMethod === 'DELETE') { $copy['metadata']['param'][$i][$dataName]['from'] = 'query'; - } elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] == 'path') { + } elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] === 'path') { $copy['metadata']['param'][$i][$dataName]['from'] = 'body'; } } @@ -297,15 +297,15 @@ function ($matches) use ($copy) { } else { $httpMethod = 'GET'; } - if ($methodUrl == 'index') { + if ($methodUrl === 'index') { $methodUrl = ''; } $url = empty($methodUrl) ? rtrim($resourcePath, '/') : $resourcePath . $methodUrl; for ($position = 0; $position < count($params); $position++) { $from = $metadata['param'][$position][$dataName]['from']; - if ($from == 'body' && ($httpMethod == 'GET' || - $httpMethod == 'DELETE') + if ($from === 'body' && ($httpMethod === 'GET' || + $httpMethod === 'DELETE') ) { $call['metadata']['param'][$position][$dataName]['from'] = 'query'; @@ -323,7 +323,7 @@ function ($matches) use ($copy) { ? $call['metadata']['param'][$position]['type'] : null) . $position . '}'; - if ($allowAmbiguity || $position == $lastPathParam) { + if ($allowAmbiguity || $position === $lastPathParam) { static::addPath($url, $call, $httpMethod, $version); } } @@ -359,13 +359,13 @@ function ($matches) use ($call) { $path ); //check for wildcard routes - if (substr($path, -1, 1) == '*') { + if (substr($path, -1, 1) === '*') { $path = rtrim($path, '/*'); static::$routes["v$version"]['*'][$path][$httpMethod] = $call; } else { static::$routes["v$version"][$path][$httpMethod] = $call; //create an alias with index if the method name is index - if ($call['methodName'] == 'index') + if ($call['methodName'] === 'index') static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call; } } @@ -388,7 +388,7 @@ public static function find($path, $httpMethod, if (!$p) { throw new RestException( 404, - $version == 1 ? '' : "Version $version is not supported" + $version === 1 ? '' : "Version $version is not supported" ); } $status = 404; @@ -416,7 +416,7 @@ public static function find($path, $httpMethod, } //================== dynamic routes ============================= //add newline char if trailing slash is found - if (substr($path, -1) == '/') + if (substr($path, -1) === '/') $path .= PHP_EOL; //if double slash is found fill in newline char; $path = str_replace('//', '/' . PHP_EOL . '/', $path); @@ -437,7 +437,7 @@ public static function find($path, $httpMethod, } $index = intval(substr($k, 1)); $details = $value[$httpMethod]['metadata']['param'][$index]; - if ($k[0] == 's' || strpos($k, static::pathVarTypeOf($v)) === 0) { + if ($k[0] === 's' || strpos($k, static::pathVarTypeOf($v)) === 0) { //remove the newlines $data[$details['name']] = trim($v, PHP_EOL); } else { @@ -453,14 +453,14 @@ public static function find($path, $httpMethod, } } } - if ($status == 404) { + if ($status === 404) { //check if other methods are allowed if (isset($p[$path])) { $status = 405; $methods = array_keys($p[$path]); } } - if ($status == 405) { + if ($status === 405) { header('Allow: ' . implode(', ', $methods)); } throw new RestException($status, $message); @@ -483,7 +483,7 @@ public static function findAll(array $excludedPaths = array(), array $excludedHt } foreach ($excludedPaths as $exclude) { if (empty($exclude)) { - if ($fullPath == $exclude || $fullPath == 'index') + if ($fullPath === $exclude || $fullPath === 'index') continue 2; } elseif (Text::beginsWith($fullPath, $exclude)) { continue 2; @@ -557,14 +557,14 @@ protected static function populate(array $call, $data) $lastBodyParamIndex = -1; $lastM = null; foreach ($call['metadata']['param'] as $k => $m) { - if ($m[$dataName]['from'] == 'body') { + if ($m[$dataName]['from'] === 'body') { $bodyParamCount++; $lastBodyParamIndex = $k; $lastM = $m; } } if ( - $bodyParamCount == 1 && + $bodyParamCount === 1 && !array_key_exists($lastM['name'], $data) && array_key_exists(Defaults::$fullRequestDataName, $data) && !is_null($d = $data[Defaults::$fullRequestDataName]) @@ -661,7 +661,7 @@ protected static function getTypeAndModel(ReflectionClass $class, array $scope, if (!isset($prop[$dataName]['label'])) { $prop[$dataName]['label'] = Text::title($prop['name']); } - if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] == 'string' && !isset($prop[$dataName]['type'])) { + if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] === 'string' && !isset($prop[$dataName]['type'])) { $prop[$dataName]['type'] = static::$fieldTypesByName[$prop['name']]; } $children[$prop['name']] = $prop; @@ -788,7 +788,7 @@ public static function scope(ReflectionClass $class) $last = 0; foreach ($tokens as $token) { if (is_string($token)) { - if ($reading && ',' == $token) { + if ($reading && ',' === $token) { //===== STOP =====// $reading = false; if (!empty($namespace)) @@ -803,7 +803,7 @@ public static function scope(ReflectionClass $class) if (!empty($namespace)) $imports[$alias] = trim($namespace, '\\'); } - } elseif (T_USE == $token[0]) { + } elseif (T_USE === $token[0]) { //===== START =====// $reading = true; $namespace = ''; @@ -815,7 +815,7 @@ public static function scope(ReflectionClass $class) continue 2; case T_STRING: $alias = $token[1]; - if (T_AS == $last) { + if (T_AS === $last) { break; } //don't break; diff --git a/src/Scope.php b/src/Scope.php index 6f7b49daf..81ba36dd8 100644 --- a/src/Scope.php +++ b/src/Scope.php @@ -205,7 +205,7 @@ public static function resolve($className, array $scope) } $divider = '\\'; - if ($className[0] == $divider) { + if ($className[0] === $divider) { $qualified = trim($className, $divider); } elseif (array_key_exists($className, $scope)) { $qualified = $scope[$className]; diff --git a/src/UI/Emmet.php b/src/UI/Emmet.php index 66090568a..58185d635 100644 --- a/src/UI/Emmet.php +++ b/src/UI/Emmet.php @@ -66,7 +66,7 @@ function ( & $tokens, & $tag ) { $digits = 0; - if ($delimiter == null) + if ($delimiter === null) $delimiter = array( '.' => true, '#' => true, @@ -87,8 +87,8 @@ function ( if ($digits) { $negative = false; $offset = 0; - if ('@' == $t) { - if ('-' == ($t = array_shift($tokens))) { + if ('@' === $t) { + if ('-' === ($t = array_shift($tokens))) { $negative = true; if (is_numeric(reset($tokens))) { $offset = array_shift($tokens); @@ -98,7 +98,7 @@ function ( } else { array_unshift($tokens, $t); } - } elseif ('#' == ($h = array_shift($tokens))) { + } elseif ('#' === ($h = array_shift($tokens))) { if (!empty($t)) { $data = Util::nestedValue($data, $t); if (is_null($data)) { @@ -139,9 +139,9 @@ function (Callable $self, $round, $total, $data) ); if (is_null($a)) return; - if ('=' == ($v = array_shift($tokens))) { + if ('=' === ($v = array_shift($tokens))) { //value - if ('"' == ($v = array_shift($tokens))) { + if ('"' === ($v = array_shift($tokens))) { $text = ''; $tag->$a($parseText( $text, $round, $total, $data, @@ -155,14 +155,14 @@ function (Callable $self, $round, $total, $data) array(' ' => true, ']' => true) )); } - if (' ' == ($v = array_shift($tokens))) { + if (' ' === ($v = array_shift($tokens))) { $self($self, $round, $total, $data); } - } elseif (']' == $v) { + } elseif (']' === $v) { //end $tag->$a(''); return; - } elseif (' ' == $v) { + } elseif (' ' === $v) { $tag->$a(''); $self($self, $round, $total, $data); } @@ -224,13 +224,13 @@ function ( case '>': $isInChild = true; $offsetTokens = null; - if ('{' == ($t = array_shift($tokens))) { + if ('{' === ($t = array_shift($tokens))) { array_unshift($tokens, $t); $child = new T(); $tag[] = $child; $parent = $tag; $tag = $child; - } elseif ('[' == $t) { + } elseif ('[' === $t) { array_unshift($tokens, $t); } else { $child = new T($t); @@ -246,11 +246,11 @@ function ( $tokens = array(); break; } - if ('{' == ($t = array_shift($tokens))) { + if ('{' === ($t = array_shift($tokens))) { $tag = $tag->parent; array_unshift($tokens, $t); break; - } elseif ('[' == $t) { + } elseif ('[' === $t) { array_unshift($tokens, $t); } else { $child = new T($t); @@ -268,7 +268,7 @@ function ( $tag = $tag->parent; if ($tag->parent) $tag = $tag->parent; - while ('^' == ($t = array_shift($tokens))) { + while ('^' === ($t = array_shift($tokens))) { if ($tag->parent) $tag = $tag->parent; } @@ -302,7 +302,7 @@ function ( } } $indexed = array_values($data); - $times = is_array($data) && $indexed == $data + $times = is_array($data) && $indexed === $data ? count($data) : 0; } $source = $tag; @@ -343,7 +343,7 @@ function ( } }; $parse($parse); - return count($root) == 1 ? $root[0] : $root; + return count($root) === 1 ? $root[0] : $root; } public static function tokenize($string) @@ -357,8 +357,8 @@ public static function tokenize($string) $tokens = array(); for ($i = $start; $i < $pos; $i++) { $token = $string[$i]; - if (('#' == $token || '.' == $token) && - (!empty($tokens) || $i == 0) + if (('#' === $token || '.' === $token) && + (!empty($tokens) || $i === 0) ) { $r[] = ''; } @@ -386,4 +386,4 @@ public static function tokenize($string) [10] => 4 */ } -} \ No newline at end of file +} diff --git a/src/UI/Forms.php b/src/UI/Forms.php index 20749a2e6..5c18f3605 100644 --- a/src/UI/Forms.php +++ b/src/UI/Forms.php @@ -116,16 +116,16 @@ public static function get($method = 'POST', $action = null, $dataOnly = false, $action = $restler->url; } - $info = $restler->url == $action - && Util::getRequestMethod() == $method + $info = $restler->url === $action + && Util::getRequestMethod() === $method ? $restler->apiMethodInfo : Routes::find( trim($action, '/'), $method, $restler->getRequestedApiVersion(), static::$preFill || - ($restler->requestMethod == $method && - $restler->url == $action) + ($restler->requestMethod === $method && + $restler->url === $action) ? $restler->getRequestData() : array() ); @@ -242,13 +242,13 @@ public static function fields($dataOnly = false) $value = Util::nestedValue($values, $k); if ( is_scalar($value) || - ($p['type'] == 'array' && is_array($value) && $value == array_values($value)) || - is_object($value) && $p['type'] == get_class($value) + ($p['type'] === 'array' && is_array($value) && $value === array_values($value)) || + is_object($value) && $p['type'] === get_class($value) ) { $p['value'] = $value; } static::$validationInfo = $v = new ValidationInfo($p); - if ($v->from == 'path') { + if ($v->from === 'path') { continue; } if (!empty($v->children)) { @@ -257,13 +257,13 @@ public static function fields($dataOnly = false) $value = Util::nestedValue($v->value, $n); if ( is_scalar($value) || - ($c['type'] == 'array' && is_array($value) && $value == array_values($value)) || - is_object($value) && $c['type'] == get_class($value) + ($c['type'] === 'array' && is_array($value) && $value === array_values($value)) || + is_object($value) && $c['type'] === get_class($value) ) { $c['value'] = $value; } static::$validationInfo = $vc = new ValidationInfo($c); - if ($vc->from == 'path') { + if ($vc->from === 'path') { continue; } $vc->name = $v->name . '[' . $vc->name . ']'; @@ -299,7 +299,7 @@ public static function field(ValidationInfo $p, $dataOnly = false) $options = array(); $name = $p->name; $multiple = null; - if ($p->type == 'array' && $p->contentType != 'associative') { + if ($p->type === 'array' && $p->contentType != 'associative') { $name .= '[]'; $multiple = true; } @@ -309,12 +309,12 @@ public static function field(ValidationInfo $p, $dataOnly = false) $option['text'] = isset($p->rules['select'][$i]) ? $p->rules['select'][$i] : $choice; - if ($choice == $p->value) { + if ($choice === $p->value) { $option['selected'] = true; } $options[] = $option; } - } elseif ($p->type == 'boolean' || $p->type == 'bool') { + } elseif ($p->type === 'boolean' || $p->type === 'bool') { if (Text::beginsWith($type, 'radio') || Text::beginsWith($type, 'select')) { $options[] = array( 'name' => $p->name, @@ -362,13 +362,13 @@ public static function field(ValidationInfo $p, $dataOnly = false) $r += $p->rules; } } - if ($type == 'file') { + if ($type === 'file') { static::$fileUpload = true; if (empty($r['accept'])) { $r['accept'] = implode(', ', UploadFormat::$allowedMimeTypes); } } - if (!empty(Validator::$exceptions[$name]) && static::$info->url == Scope::get('Restler')->url) { + if (!empty(Validator::$exceptions[$name]) && static::$info->url === Scope::get('Restler')->url) { $r['error'] = 'has-error'; $r['message'] = Validator::$exceptions[$p->name]->getMessage(); } @@ -401,7 +401,7 @@ protected static function guessFieldType(ValidationInfo $p, $type = 'type') return $p->$type; } if ($p->choice) { - return $p->type == 'array' ? 'checkbox' : 'select'; + return $p->type === 'array' ? 'checkbox' : 'select'; } switch ($p->$type) { case 'boolean': @@ -413,7 +413,7 @@ protected static function guessFieldType(ValidationInfo $p, $type = 'type') case 'array': return static::guessFieldType($p, 'contentType'); } - if ($p->name == 'password') { + if ($p->name === 'password') { return 'password'; } return 'text'; @@ -452,7 +452,7 @@ public static function key($method = 'POST', $action = null) */ public function __isAllowed() { - if (session_id() == '') { + if (session_id() === '') { session_start(); } /** @var Restler $restler */ @@ -460,7 +460,7 @@ public function __isAllowed() $url = $restler->url; foreach (static::$excludedPaths as $exclude) { if (empty($exclude)) { - if ($url == $exclude) { + if ($url === $exclude) { return true; } } elseif (Text::beginsWith($url, $exclude)) { @@ -475,7 +475,7 @@ public function __isAllowed() isset($_POST[static::FORM_KEY]) && ($target = Util::getRequestMethod() . ' ' . $restler->url) && isset($_SESSION[static::FORM_KEY][$target]) && - $_POST[static::FORM_KEY] == $_SESSION[static::FORM_KEY][$target] + $_POST[static::FORM_KEY] === $_SESSION[static::FORM_KEY][$target] ) { return true; } diff --git a/src/UI/Nav.php b/src/UI/Nav.php index 4a7445ccb..33c47a15b 100644 --- a/src/UI/Nav.php +++ b/src/UI/Nav.php @@ -65,7 +65,7 @@ public static function get($for = '', $activeTrail = null) if (empty(static::$url)) static::$url = ''; static::$activeTrail = $activeTrail = empty($activeTrail) - ? (empty($restler->url) || $restler->url == 'index' + ? (empty($restler->url) || $restler->url === 'index' ? static::$root : $restler->url ) @@ -169,7 +169,7 @@ public static function add($url, $label = null, $trail = null) //remove / prefix and / suffixes and any extension $trail = strtok(trim($trail, '/'), '.'); $parts = explode('/', $trail); - if (count($parts) == 1 && empty($parts[0])) + if (count($parts) === 1 && empty($parts[0])) $parts = array(static::$root); if (isset($r['fragment'])) { $parts[] = $r['fragment']; @@ -203,12 +203,12 @@ public static function build(array $r) $parts = $r['parts']; $last = count($parts) - 1; foreach ($parts as $i => $part) { - if ($i == $last) { + if ($i === $last) { $p[$part]['text'] = $r['label']; $p[$part]['href'] = $r['url']; $p[$part]['class'] = Text::slug($part); /* dynamically do it at run time instead - if ($r['path'] == static::$activeTrail) + if ($r['path'] === static::$activeTrail) $p[$part]['active'] = true; */ } elseif (!isset($p[$part])) { diff --git a/src/UI/Tags.php b/src/UI/Tags.php index 27e90bc89..42396ec8d 100644 --- a/src/UI/Tags.php +++ b/src/UI/Tags.php @@ -163,7 +163,7 @@ public function id($value) public function __get($name) { - if ('parent' == $name) + if ('parent' === $name) return $this->_parent; if (isset($this->attributes[$name])) return $this->attributes[$name]; @@ -172,7 +172,7 @@ public function __get($name) public function __set($name, $value) { - if ('parent' == $name) { + if ('parent' === $name) { if ($this->_parent) { unset($this->_parent[array_search($this, $this->_parent->children)]); } @@ -279,4 +279,4 @@ private function markAsChildren(& $children) $child->_parent = $this; } } -} \ No newline at end of file +} diff --git a/src/Util.php b/src/Util.php index baea51d44..d2a268259 100644 --- a/src/Util.php +++ b/src/Util.php @@ -127,7 +127,7 @@ public static function removeCommonPath($fromPath, $usingPath, $char = '/') $fromPath = explode($char, $fromPath); $usingPath = explode($char, $usingPath); while (count($usingPath)) { - if (count($fromPath) && $fromPath[0] == $usingPath[0]) { + if (count($fromPath) && $fromPath[0] === $usingPath[0]) { array_shift($fromPath); } else { break; @@ -160,7 +160,7 @@ public static function splitCommonPath($fromPath, $usingPath, $char = '/') $usingPath = explode($char, $usingPath); $commonPath = array(); while (count($usingPath)) { - if (count($fromPath) && $fromPath[0] == $usingPath[0]) { + if (count($fromPath) && $fromPath[0] === $usingPath[0]) { $commonPath [] = array_shift($fromPath); } else { break; @@ -190,14 +190,14 @@ public static function getRequestMethod() ) { // support for exceptional clients who can't set the header $m = strtoupper($_REQUEST[Defaults::$httpMethodOverrideProperty]); - if ($m == 'PUT' || $m == 'DELETE' || - $m == 'POST' || $m == 'PATCH' + if ($m === 'PUT' || $m === 'DELETE' || + $m === 'POST' || $m === 'PATCH' ) { $method = $m; } } // support for HEAD request - if ($method == 'HEAD') { + if ($method === 'HEAD') { $method = 'GET'; } return $method; diff --git a/src/views/debug.php b/src/views/debug.php index 2c30fbd8e..644343e3e 100644 --- a/src/views/debug.php +++ b/src/views/debug.php @@ -115,7 +115,7 @@ function render($data, $shadow=true) $reqHeadersArr = array(); $requestHeaders = $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . PHP_EOL; foreach ($reqHeadersArr as $key => $value) { - if ($key == 'Host') + if ($key === 'Host') continue; $requestHeaders .= "$key: $value" . PHP_EOL; }