Add resolvecontext structure and optimze type resolving process

The resolvecontext will from now on be used as store for all data required to resolve the
return type of a statement at any given point.

`phpinspect--word-end-regex` has been altered to match words that are directly followed by
other, "non-word" characters.

`phpinspect-describe-handler` has been added to list and describe handlers during runtime.

A bug has been fixed that made the parser interpret the "static" keyword inside functions
as a class attribute in stead of just a word.

Aside from the company backend, `phpinspect-eldoc-function` has been simplified and
adapted to make use of the resolvecontext structure.

The resolving of statment/variable types has been altered to make use of imperative loops
in a couple of places for the sake of simplicity and optimization.
WIP
Hugo Thunnissen 3 years ago
parent e8f486f095
commit 098146bfc5

1
.gitignore vendored

@ -0,0 +1 @@
*.elc

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:variable "repo") (:terminator ";")) (:private (:variable "user_repo") (:terminator ";")) (:private (:variable "twig") (:terminator ";")) (:private (:variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil)))))))))

@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\Address;
use Symfony\Component\HttpFoundation\RedirectResponse;
use App\Repository\AddressRepository;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class AddressController
{
const A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE = 'a value';
public const ARRAY_CONSTANT = [
'key' => 'value',
'key' => 0
];
private $repo;
private $user_repo;
private $twig;
private $em;
public function __construct(
AddressRepository $repo,
UserRepository $user_repo,
Environment $twig,
EntityManagerInterface $em
) {
$this->repo = $repo;
$this->user_repo = $user_repo;
$this->twig = $twig;
$this->em = $em;
}
/**
* @Route("/address/add", methods={"GET"})
*/
public function addAddressPage(Request $req): Response
{
$user = $this->user_repo->findOne($req->get('user'));
return new Response(
$this->twig->render('address/create.html.twig', [
'user' => $user,
])
);
}
/**
* @Route("/address/add", methods={"POST"})
*/
public function addAddressAction(Request $req): Response
{
$user = $this->user_repo->findOne($req->request->get('user'));
$address_string = $req->request->get('address');
$address = new Address($user, $address_string);
$this->em->persist($address);
$this->em->flush();
return new RedirectResponse('/user/' . $user->getLoginName() . '/manage');
}
/**
* @Route("/address/delete", methods={"POST"})
*/
public function deleteAddressAction(Request $req): Response
{
$address = $this->repo->find($req->request->get('address'));
// This is what a while looks like to phpinspect when it parses up
// until "point" to complete.
$this->em->remove($this->em->

@ -127,5 +127,30 @@
(phpinspect-test-read-fixture-data
"class-index-1-2-undestructive-merge"))))
(ert-deftest phpinspect-find-innermost-incomplete-nested-token ()
(let ((resolvecontext (phpinspect--get-resolvecontext
(phpinspect-test-read-fixture-data "IncompleteClass"))))
(should (equal (phpinspect--resolvecontext-subject resolvecontext)
'((:variable "this")
(:object-attrib (:word "em"))
(:object-attrib nil))))
(should (phpinspect-root-p
(car (last (phpinspect--resolvecontext-enclosing-tokens
resolvecontext)))))
(should (phpinspect-incomplete-list-p
(car (phpinspect--resolvecontext-enclosing-tokens
resolvecontext))))
(should (phpinspect-incomplete-function-p
(cadr (phpinspect--resolvecontext-enclosing-tokens
resolvecontext))))
(should (phpinspect-incomplete-class-p
(cadddr (phpinspect--resolvecontext-enclosing-tokens
resolvecontext))))))
(provide 'phpinspect-test)
;;; phpinspect-test.el ends here

Loading…
Cancel
Save