diff --git a/phpinspect-imports.el b/phpinspect-imports.el index 31efa76..fbb0cf4 100644 --- a/phpinspect-imports.el +++ b/phpinspect-imports.el @@ -31,6 +31,7 @@ (require 'phpinspect-buffer) (require 'phpinspect-cache) (require 'phpinspect-util) +(require 'phpinspect-type) (defun phpinspect-insert-at-point (point data) (save-excursion @@ -115,12 +116,15 @@ buffer position to insert the use statement at." (dolist (type types) (setq namespace (phpinspect-meta-find-parent-matching-token parent-token #'phpinspect-namespace-p) - namespace-name (phpinspect-namespace-name namespace)) + namespace-name (if namespace + (phpinspect-namespace-name (phpinspect-meta-token namespace)) + "")) ;; Add use statements for types that aren't imported or already referenced ;; with a fully qualified name. (unless (or (or (alist-get type imports)) (gethash (phpinspect-intern-name - (concat namespace-name "\\" (phpinspect-name-string type))) + (phpinspect--resolve-type-name + nil namespace-name (phpinspect-name-string type))) (phpinspect-autoloader-types (phpinspect-project-autoload project)))) (phpinspect-add-use-interactive type buffer project namespace) diff --git a/phpinspect-type.el b/phpinspect-type.el index a7c07c0..1ffee8a 100644 --- a/phpinspect-type.el +++ b/phpinspect-type.el @@ -358,8 +358,9 @@ mutability of the variable") "Extract NAMESPACE name as a string. NAMESPACE should be a namespace token (`phpinspect-namespace-p')." - (or (and (phpinspect-namespace-p namespace) - (phpinspect-word-p (cadr namespace)) + (cl-assert (phpinspect-namespace-p namespace)) + + (or (and (phpinspect-word-p (cadr namespace)) (cadadr namespace)) ""))