Skip to content

Commit 72b5ae2

Browse files
committed
Uses strict comparison everywhere to avoid weird runtime errors
1 parent 1339dfa commit 72b5ae2

26 files changed

+211
-211
lines changed

Diff for: AutoLoader.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static function thereCanBeOnlyOne() {
9292
* key. Default is false we haven't seen this
9393
* class. Most of the time it will be the filename
9494
* for include and is set to true if we are unable
95-
* to load this class iow true == it does not exist.
95+
* to load this class iow true === it does not exist.
9696
* value may also be a callable auto loader function.
9797
*
9898
* @return mixed The known value for the key or false if key has no value
@@ -143,7 +143,7 @@ protected function __construct()
143143
if (false !== $path = stream_resolve_include_path(
144144
implode($slash, $includePath)
145145
))
146-
if ('composer' == end($includePath) &&
146+
if ('composer' === end($includePath) &&
147147
false !== $classmapPath = stream_resolve_include_path(
148148
"$path{$slash}autoload_classmap.php"
149149
)
@@ -162,7 +162,7 @@ protected function __construct()
162162

163163
$paths = array_filter(array_map(
164164
function ($path) {
165-
if (false == $realPath = @realpath($path))
165+
if (false === $realPath = @realpath($path))
166166
return null;
167167
return $realPath . DIRECTORY_SEPARATOR;
168168
},
@@ -310,8 +310,8 @@ private function loadThisLoader($className, $loader)
310310
*/
311311
private function alias($className, $currentClass)
312312
{
313-
if ($className == 'Luracast\Restler\string') return;
314-
if ($className == 'Luracast\Restler\mixed') return;
313+
if ($className === 'Luracast\Restler\string') return;
314+
if ($className === 'Luracast\Restler\mixed') return;
315315
if ($className != $currentClass
316316
&& false !== strpos($className, $currentClass))
317317
if (!class_exists($currentClass, false)

Diff for: CommentParser.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ private function extractData($comment)
154154
$line = trim($line);
155155
$newParam = false;
156156
if (empty ($line)) {
157-
if ($mode == 0) {
157+
if ($mode === 0) {
158158
$mode++;
159159
} else {
160160
$addNewline = true;
161161
}
162162
continue;
163-
} elseif ($line[0] == '@') {
163+
} elseif ($line[0] === '@') {
164164
$mode = 2;
165165
$newParam = true;
166166
}
@@ -172,7 +172,7 @@ private function extractData($comment)
172172
$longDescription = $description;
173173
$description[] = array_shift($longDescription);
174174
$mode = 1;
175-
} elseif (substr($line, -1) == '.') {
175+
} elseif (substr($line, -1) === '.') {
176176
$mode = 1;
177177
}
178178
break;
@@ -281,7 +281,7 @@ private function parseParam($param, array $value, array $embedded)
281281
}
282282
} elseif ($allowMultiple) {
283283
$data[$param][] = $value;
284-
} elseif ($param == 'param') {
284+
} elseif ($param === 'param') {
285285
$arr = array(
286286
$data[$param],
287287
$value
@@ -324,15 +324,15 @@ private function parseEmbeddedData($subject)
324324
$name = $matches[1];
325325
$value = $matches[2];
326326
$subject = str_replace($matches[0], '', $subject);
327-
if ($name == 'pattern') {
327+
if ($name === 'pattern') {
328328
throw new Exception('Inline pattern tag should follow {@pattern /REGEX_PATTERN_HERE/} format and can optionally include PCRE modifiers following the ending `/`');
329329
} elseif (isset(static::$allowsArrayValue[$name])) {
330330
$value = explode(static::$arrayDelimiter, $value);
331-
} elseif ($value == 'true' || $value == 'false') {
332-
$value = $value == 'true';
333-
} elseif ($value == '') {
331+
} elseif ($value === 'true' || $value === 'false') {
332+
$value = $value === 'true';
333+
} elseif ($value === '') {
334334
$value = true;
335-
} elseif ($name == 'required') {
335+
} elseif ($name === 'required') {
336336
$value = explode(static::$arrayDelimiter, $value);
337337
}
338338
if (defined('Luracast\\Restler\\UI\\HtmlForm::'.$name)) {
@@ -359,7 +359,7 @@ private function parseEmbeddedData($subject)
359359
$data = $format->decode($str);
360360
}
361361
} else { // auto detect
362-
if ($str[0] == '{') {
362+
if ($str[0] === '{') {
363363
$d = json_decode($str, true);
364364
if (json_last_error() != JSON_ERROR_NONE) {
365365
throw new Exception('Error parsing embedded JSON data'
@@ -378,8 +378,8 @@ private function parseEmbeddedData($subject)
378378
$d[$key] = $val;
379379
}
380380
if (is_string($val)) {
381-
if ($val == 'true' || $val == 'false') {
382-
$d[$key] = $val == 'true' ? true : false;
381+
if ($val === 'true' || $val === 'false') {
382+
$d[$key] = $val === 'true' ? true : false;
383383
} else {
384384
$val = explode(self::$arrayDelimiter, $val);
385385
if (count($val) > 1) {
@@ -451,7 +451,7 @@ private function formatAuthor(array $value)
451451
{
452452
$r = array();
453453
$email = end($value);
454-
if ($email[0] == '<') {
454+
if ($email[0] === '<') {
455455
$email = substr($email, 1, -1);
456456
array_pop($value);
457457
$r['email'] = $email;
@@ -464,7 +464,7 @@ private function formatReturn(array $value)
464464
{
465465
$data = explode('|', array_shift($value));
466466
$r = array(
467-
'type' => count($data) == 1 ? $data[0] : $data
467+
'type' => count($data) === 1 ? $data[0] : $data
468468
);
469469
$r['description'] = implode(' ', $value);
470470
return $r;
@@ -476,15 +476,15 @@ private function formatParam(array $value)
476476
$data = array_shift($value);
477477
if (empty($data)) {
478478
$r['type'] = 'mixed';
479-
} elseif ($data[0] == '$') {
479+
} elseif ($data[0] === '$') {
480480
$r['name'] = substr($data, 1);
481481
$r['type'] = 'mixed';
482482
} else {
483483
$data = explode('|', $data);
484-
$r['type'] = count($data) == 1 ? $data[0] : $data;
484+
$r['type'] = count($data) === 1 ? $data[0] : $data;
485485

486486
$data = array_shift($value);
487-
if (!empty($data) && $data[0] == '$') {
487+
if (!empty($data) && $data[0] === '$') {
488488
$r['name'] = substr($data, 1);
489489
}
490490
}
@@ -504,12 +504,12 @@ private function formatVar(array $value)
504504
$data = array_shift($value);
505505
if (empty($data)) {
506506
$r['type'] = 'mixed';
507-
} elseif ($data[0] == '$') {
507+
} elseif ($data[0] === '$') {
508508
$r['name'] = substr($data, 1);
509509
$r['type'] = 'mixed';
510510
} else {
511511
$data = explode('|', $data);
512-
$r['type'] = count($data) == 1 ? $data[0] : $data;
512+
$r['type'] = count($data) === 1 ? $data[0] : $data;
513513
}
514514
if (isset($r['type']) && Text::endsWith($r['type'], '[]')) {
515515
$r[static::$embeddedDataName]['type'] = substr($r['type'], 0, -2);

Diff for: Data/Obj.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static function toArray($object,
128128
$array [$key] = $value;
129129
$count++;
130130
}
131-
return $forceObjectTypeWhenEmpty && $count == 0 ? $object : $array;
131+
return $forceObjectTypeWhenEmpty && $count === 0 ? $object : $array;
132132
}
133133

134134
return $object;

Diff for: Data/Text.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function beginsWith($haystack, $needle)
5757
public static function endsWith($haystack, $needle)
5858
{
5959
$length = strlen($needle);
60-
if ($length == 0) {
60+
if ($length === 0) {
6161
return true;
6262
}
6363
return (substr($haystack, -$length) === $needle);
@@ -93,4 +93,4 @@ public static function slug($name)
9393
{
9494
return preg_replace('/[^a-zA-Z]+/', '-', strtolower(strip_tags($name)));
9595
}
96-
}
96+
}

Diff for: Data/ValidationInfo.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ValidationInfo implements iValueObject
172172

173173
public static function numericValue($value)
174174
{
175-
return ( int )$value == $value
175+
return ( int )$value === $value
176176
? ( int )$value
177177
: floatval($value);
178178
}
@@ -227,19 +227,19 @@ private function getProperty(array &$from, $property)
227227
);
228228
unset($from[CommentParser::$embeddedDataName][$property]);
229229

230-
if ($property == 'type' && $p == 'array' && $p2) {
230+
if ($property === 'type' && $p === 'array' && $p2) {
231231
$this->contentType = $p2;
232232
return $p;
233233
}
234234
$r = is_null($p2) ? (is_null($p) ? null : $p) : $p2;
235235
if (!is_null($r)) {
236-
if ($property == 'min' || $property == 'max') {
236+
if ($property === 'min' || $property === 'max') {
237237
return static::numericValue($r);
238-
} elseif ($property == 'required' || $property == 'fix') {
238+
} elseif ($property === 'required' || $property === 'fix') {
239239
return static::booleanValue($r);
240-
} elseif ($property == 'choice') {
240+
} elseif ($property === 'choice') {
241241
return static::arrayValue($r);
242-
} elseif ($property == 'pattern') {
242+
} elseif ($property === 'pattern') {
243243
return static::stringValue($r);
244244
}
245245
}
@@ -256,7 +256,7 @@ public function __construct(array $info)
256256
$inner = Util::nestedValue($info, 'properties');
257257
$this->rules = !empty($inner) ? $inner + $info : $info;
258258
unset($this->rules['properties']);
259-
if (is_string($this->type) && $this->type == 'integer') {
259+
if (is_string($this->type) && $this->type === 'integer') {
260260
$this->type = 'int';
261261
}
262262
}

Diff for: Data/Validator.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,11 @@ public static function validate($input, ValidationInfo $info, $full = null)
514514
case 'number' :
515515
if (!is_numeric($input)) {
516516
$error .= '. Expecting '
517-
. ($info->type == 'int' ? 'integer' : 'numeric')
517+
. ($info->type === 'int' ? 'integer' : 'numeric')
518518
. ' value';
519519
break;
520520
}
521-
if ($info->type == 'int' && (int)$input != $input) {
521+
if ($info->type === 'int' && (int)$input != $input) {
522522
if ($info->fix) {
523523
$r = (int)$input;
524524
} else {
@@ -600,7 +600,7 @@ public static function validate($input, ValidationInfo $info, $full = null)
600600
}
601601
}
602602
if ($info->fix) {
603-
return $input ? true : false;
603+
return (bool)$input;
604604
}
605605
$error .= '. Expecting boolean value';
606606
break;
@@ -612,20 +612,20 @@ public static function validate($input, ValidationInfo $info, $full = null)
612612
$contentType =
613613
Util::nestedValue($info, 'contentType') ?: null;
614614
if ($info->fix) {
615-
if ($contentType == 'indexed') {
615+
if ($contentType === 'indexed') {
616616
$input = $info->filterArray($input, true);
617-
} elseif ($contentType == 'associative') {
617+
} elseif ($contentType === 'associative') {
618618
$input = $info->filterArray($input, false);
619619
}
620620
} elseif (
621-
$contentType == 'indexed' &&
621+
$contentType === 'indexed' &&
622622
array_values($input) != $input
623623
) {
624624
$error .= '. Expecting a list of items but an item is given';
625625
break;
626626
} elseif (
627-
$contentType == 'associative' &&
628-
array_values($input) == $input &&
627+
$contentType === 'associative' &&
628+
array_values($input) === $input &&
629629
count($input)
630630
) {
631631
$error .= '. Expecting an item but a list is given';

Diff for: Data/ValueObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __toArray()
5050
$r = get_object_vars($this);
5151
$methods = get_class_methods($this);
5252
foreach ($methods as $m) {
53-
if (substr($m, 0, 3) == 'get') {
53+
if (substr($m, 0, 3) === 'get') {
5454
$r [lcfirst(substr($m, 3))] = @$this->{$m} ();
5555
}
5656
}

0 commit comments

Comments
 (0)