-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Type safe comparison in libraries/cms - second iteration #13276
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
Changes from all commits
579bacd
06b1743
15ff27e
15a6212
76a417a
6bca581
8e5d494
f5fe9bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ abstract class JHtmlString | |
| public static function truncate($text, $length = 0, $noSplit = true, $allowHtml = true) | ||
| { | ||
| // Assume a lone open tag is invalid HTML. | ||
| if ($length == 1 && substr($text, 0, 1) == '<') | ||
| if ($length === 1 && substr($text, 0, 1) === '<') | ||
| { | ||
| return '...'; | ||
| } | ||
|
|
@@ -105,7 +105,7 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml | |
| $numOpened = count($openedTags); | ||
|
|
||
| // Not all tags are closed so trim the text and finish. | ||
| if (count($closedTags) != $numOpened) | ||
| if (count($closedTags) !== $numOpened) | ||
| { | ||
| // Closing tags need to be in the reverse order of opening tags. | ||
| $openedTags = array_reverse($openedTags); | ||
|
|
@@ -170,7 +170,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true) | |
| $baseLength = strlen($html); | ||
|
|
||
| // If the original HTML string is shorter than the $maxLength do nothing and return that. | ||
| if ($baseLength <= $maxLength || $maxLength == 0) | ||
| if ($baseLength <= $maxLength || $maxLength === 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure maxlenght is an int? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving as is, because the variable is defined as a parameter to the function, with type integer. |
||
| { | ||
| return $html; | ||
| } | ||
|
|
@@ -182,7 +182,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true) | |
| } | ||
|
|
||
| // Deal with maximum length of 1 where the string starts with a tag. | ||
| if ($maxLength == 1 && substr($html, 0, 1) == '<') | ||
| if ($maxLength === 1 && substr($html, 0, 1) === '<') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving as is, because the variable is defined as a parameter to the function, with type integer. |
||
| { | ||
| $endTagPos = strlen(strstr($html, '>', true)); | ||
| $tag = substr($html, 1, $endTagPos); | ||
|
|
@@ -204,7 +204,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true) | |
| $ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit, $allowHtml = false); | ||
|
|
||
| // It's all HTML, just return it. | ||
| if (strlen($ptString) == 0) | ||
| if (strlen($ptString) === 0) | ||
| { | ||
| return $html; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,7 @@ public static function getAssociations($extension, $tablename, $context, $id, $p | |
| foreach ($items as $tag => $item) | ||
| { | ||
| // Do not return itself as result | ||
| if ((int) $item->{$pk} != $id) | ||
| if ((int) $item->{$pk} !== $id) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure id is an int? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving as is, because the variable is defined as a parameter to the function, with type integer. |
||
| { | ||
| $multilanguageAssociations[$queryKey][$tag] = $item; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,7 +150,7 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, J | |
| // Check for the default args, if so we can optimise cheaply | ||
| $defaults = false; | ||
|
|
||
| if (is_null($plugin) && $autocreate == true && is_null($dispatcher)) | ||
| if (is_null($plugin) && $autocreate === true && is_null($dispatcher)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure autocreate is a boolean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving as is, because the variable is defined as a parameter to the function, with type boolean. |
||
| { | ||
| $defaults = true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure lenght is an int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to not having the ability to do scalar typehinting, no, we aren't. That said, any dev passing a string into a method declaring a parameter as an integer is just asking for trouble as newer PHP releases come out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I agree. Still to keep b/c maybe is better to (int) the var....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a B/C break if the code enforces correct typing of a parameter. Otherwise either we bump to PHP 7 and typehint everything or remove all typehints and we're stuck running
gettype()andis_a()orinstanceofchecks on everything because the documentation is unreliable.Sooner or later the mentality of "well just pass anything in any ol' format" has to be broken. There are far too many issues dealing with something like
0 == '0' == false == null.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. If is not considered a b/c break by the project fine. Just raising the question. For the rest obvisualy i agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with @mbabker. 👍