Skip to content

Commit

Permalink
Uses strict comparison everywhere to avoid weird runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Arul- committed Jun 5, 2021
1 parent 8d76732 commit c115e23
Show file tree
Hide file tree
Showing 26 changed files with 211 additions and 211 deletions.
10 changes: 5 additions & 5 deletions src/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand All @@ -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;
},
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions src/CommentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Obj.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -93,4 +93,4 @@ public static function slug($name)
{
return preg_replace('/[^a-zA-Z]+/', '-', strtolower(strip_tags($name)));
}
}
}
14 changes: 7 additions & 7 deletions src/Data/ValidationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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';
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Data/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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} ();
}
}
Expand Down
Loading

0 comments on commit c115e23

Please sign in to comment.