Page MenuHomePhabricator

Add a linter rule for use of `is_a`
ClosedPublic

Authored by joshuaspence on Nov 25 2015, 7:47 PM.
Tags
None
Referenced Files
F13091444: D14573.diff
Thu, Apr 25, 2:57 AM
Unknown Object (File)
Fri, Apr 19, 3:52 PM
Unknown Object (File)
Thu, Apr 11, 10:29 AM
Unknown Object (File)
Sun, Apr 7, 11:15 PM
Unknown Object (File)
Sun, Mar 31, 3:18 PM
Unknown Object (File)
Sat, Mar 30, 6:44 PM
Unknown Object (File)
Mar 21 2024, 12:10 PM
Unknown Object (File)
Mar 7 2024, 4:45 AM
Subscribers

Details

Summary

instanceof should be used instead of is_a. I need to do a bit more research here to see if there are any edge cases.

Test Plan

Added unit tests.

Diff Detail

Repository
rARC Arcanist
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

joshuaspence retitled this revision from to Add a linter rule for use of `is_a`.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.

I think this is an edge case:

$subclass = 'Subclass';
is_a($subclass, 'Base', $allow_string = true); // true
$subclass instanceof Base; // false, string is not an instance of anything

I'm also not sure offhand what the distinction between is_a() and is_subclass_of() is.

epriestley edited edge metadata.

(Probably an edge case earlier?)

This revision now requires changes to proceed.Dec 1 2015, 12:21 PM
joshuaspence edited edge metadata.

Seems to work now

epriestley edited edge metadata.
epriestley added inline comments.
src/lint/linter/xhpast/rules/ArcanistIsAShouldBeInstanceOfXHPASTLinterRule.php
30–32

We could probably make evalStatic() smarter about this and have the code do something like:

if (!$allow_string->isSomethingWeCanCallEvalStaticOn()) {
  continue;
}

if ($allow_string->evalStatic()) {
  continue;
}

...to catch 0, etc., some day far in the future.

57

Missing text at end of sentence ("which has... what?")

60

Prefer ($replacement === null) for consistency.

This revision is now accepted and ready to land.Dec 22 2015, 1:43 PM
joshuaspence marked 2 inline comments as done.
joshuaspence edited edge metadata.

Fix a few inlines

This revision was automatically updated to reflect the committed changes.