branch: externals/phpinspect
commit f1dc69956022977baa5b8bede66620e72a4dfcc7
Author: Hugo Thunnissen <de...@hugot.nl>
Commit: Hugo Thunnissen <de...@hugot.nl>

    Detect types used with "instanceoff"
---
 phpinspect-index.el | 2 +-
 test/test-index.el  | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/phpinspect-index.el b/phpinspect-index.el
index 913c2f616a..861e355716 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -513,7 +513,7 @@ Returns a list of type name strings."
       (let ((token (pop tokens))
             (previous-token (car previous-tokens)))
         (cond ((and (phpinspect-word-p previous-token)
-                    (string= "new" (cadr previous-token))
+                    (member (cadr previous-token) `("new" "instanceof"))
                     (phpinspect-word-p token))
                (let ((type (cadr token)))
                  (when (not (string-match-p "\\\\" type))
diff --git a/test/test-index.el b/test/test-index.el
index 31635b950d..faf243eab2 100644
--- a/test/test-index.el
+++ b/test/test-index.el
@@ -96,7 +96,11 @@ public function makeThing(): Thing
 if ((new Monkey())->tree() === true) {
    return new ExtendedThing();
 }
-return StaticThing::create(new ThingFactory())->makeThing((((new 
Potato())->antiPotato(new OtherThing(function (InnerFunctionParam $param) 
{})))));
+return StaticThing::create(new ThingFactory())->makeThing((((new 
Potato())->antiPotato(new OtherThing(function (InnerFunctionParam $param) {
+if ($param instanceof InstanceOffed) {
+// nothing
+}
+})))));
 }")))
          (used-types (alist-get 'used-types (car (alist-get 'classes 
result)))))
     (should (equal
@@ -105,7 +109,7 @@ return StaticThing::create(new 
ThingFactory())->makeThing((((new Potato())->anti
                       (copy-sequence
                        '("Cheese" "Bacon" "Ham" "Bagel" "Monkey" 
"ExtendedThing"
                          "StaticThing" "Thing" "ThingFactory" "Potato" 
"OtherThing"
-                         "InnerFunctionParam" "PropertyType"))
+                         "InnerFunctionParam" "PropertyType" "InstanceOffed"))
                       #'string<))
              (sort used-types (lambda (s1 s2) (string< (phpinspect-name-string 
s1) (phpinspect-name-string s2))))))))
 

Reply via email to