Skip to content
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

Assertion::isInstanceOf is not working as expected #3

Closed
robertfausk opened this issue Feb 17, 2019 · 7 comments
Closed

Assertion::isInstanceOf is not working as expected #3

robertfausk opened this issue Feb 17, 2019 · 7 comments

Comments

@robertfausk
Copy link

robertfausk commented Feb 17, 2019

Given controller:

# src/Controller/EventController.php
<?php
declare(strict_types=1);

namespace App\Controller;

use App\Entity\User;
use Assert\Assertion;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;

class EventController
{
    /**
     * @param UserInterface|User $user
     *
     * @return array
     * @Route("/events", name="event_list")
     * @Template(template="event/list.html.twig")
     *
     */
    public function __invoke(UserInterface $user): array
    {
        Assertion::isInstanceOf($user, User::class);
        $team = $user->getTeams();
        ...

Given User class:

<?php
declare(strict_types=1);

namespace App\Entity;

...
use FOS\UserBundle\Model\User as BaseUser; # this one implements \Symfony\Component\Security\Core\User\UserInterface
...

class User extends BaseUser
{
    /**
     * @return Collection|Team[]
     */
    public function getTeams()
    {
        ...
    }

Given phpstan.neon

parameters:
    level: 3
    paths:
        - %currentWorkingDirectory%/src
    includes:
        - vendor/phpstan/phpstan-beberlei-assert/extension.neon
    excludes_analyse:
        - %currentWorkingDirectory%/src/Migrations/Version*.php
    parameters:
        symfony:
            container_xml_path: %rootDir%/../../../var/cache/dev/srcDevDebugProjectContainer.xml

Given phpstan-output:

 ------ ----------------------------------------------------------------- 
  Line   Controller/EventController.php                                   
 ------ ----------------------------------------------------------------- 
  25     Call to an undefined method                                      
         Symfony\Component\Security\Core\User\UserInterface::getTeams().  
 ------ ----------------------------------------------------------------- 

Expected phpstan-output:

 [OK] No errors  

Am I missing something?

PS: I have the same issue with https://github.com/phpstan/phpstan-webmozart-assert. I will open an issue there if this one gets confirmed and if it's not a misconfiguration or misuse on my side.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Feb 17, 2019 via email

@robertfausk
Copy link
Author

Hi, you’re using webmozart/assert but you have installed extension for beberlei/assert. Please install the right extension.
...
-- Ondřej Mirtes

Oh, I'm sorry. I tried both in my project and this was just a ticket creation issue. I have corrected the original post (and also tested it locally again - it's not working).

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Feb 17, 2019 via email

@robertfausk
Copy link
Author

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Feb 17, 2019

I sent you a pull request that fixes your problem (robertfausk/phpstan-assert-instance-of#1). There were two issues (that I fixed in separate commits)

  1. includes does not belong as part of parameters but as its own section. (robertfausk/phpstan-assert-instance-of@1dc541e)
  2. You still referenced webmozart/assert extension and not the right one. (robertfausk/phpstan-assert-instance-of@b3d616d)

@robertfausk
Copy link
Author

Alright thanks. 😀

@github-actions
Copy link

github-actions bot commented May 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants