Giter VIP home page Giter VIP logo

phpstan-symfony's Introduction

DEPRECATED

Use phpstan/phpstan-symfony instead.

Symfony extension for PHPStan

What does it do?

  • Provides correct return type for ContainerInterface::get() method,
  • provides correct return type for Controller::get() method,
  • notifies you when you try to get an unregistered service from the container,
  • notifies you when you try to get a private service from the container.

Installation

composer require --dev lookyman/phpstan-symfony

Configuration

Put this into your phpstan.neon config:

includes:
	- vendor/lookyman/phpstan-symfony/extension.neon
parameters:
	symfony:
		container_xml_path: %rootDir%/../../../var/cache/dev/appDevDebugProjectContainer.xml # or srcDevDebugProjectContainer.xml for Symfony 4+

Limitations

It can only recognize pure strings or ::class constants passed into get() method. This follows from the nature of static code analysis.

You have to provide a path to appDevDebugProjectContainer.xml or similar xml file describing your container.

Need something?

I don't use Symfony that often. So it might be entirely possible that something doesn't work here or that it lacks some functionality. If that's the case, PLEASE DO NOT HESITATE to open an issue or send a pull request. I will have a look at it and together we'll get you what you need. Thanks.

phpstan-symfony's People

Contributors

hectorj avatar lookyman avatar malarzm avatar mzk avatar ossinkine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

phpstan-symfony's Issues

Support for Symfony ~2.8

Hey there,

I was wondering about the lack of support for symfony ~2.8. Given that it is a LTS version and will be supported until the end of 2019 I feel like there are many users that would appreciate the support (full disclosure: including me).

I see that the package requires the symfony-di component and restricts it to ~3.2|~4.0

Do you think support for ~2.8 is possible ? Is that something that would be wort looking into or is it more of a hopeless endeavour?

Kind regards :)

Right ObjectManager::getRepository function return type

Default ObjectManager::getRepository function return type is \Doctrine\Common\Persistence\ObjectRepository
That's right but actually this function are used for returning different repositories. For example if I pass to this function argument App\Entity\Photo that means that this function return to me repository of this entity: App\Repository\PhotoRepository which is extended from ObjectRepository class
Now PHPStan doesn't recognise this type properly, it thinks that this function returns me common ObjectRepository object and of course shows me an error that it can not find my custom methods of my repository class.

Controller's get method is not respected

First, thanks for the plugin! :)

Controller:

abstract class BaseController extends \Symfony\Bundle\FrameworkBundle\Controller\Controller
{
    protected function handleCommand($command)
    {
        $this->get('command_bus')->handle($command);
    }
}

And after analyse I'm getting for the controller:

Call to an undefined method object::handle().

Let me know should I try to hack a failing test case or is this enough.

Default container path

Default path to container should be
container_xml_path: %rootDir%/../../../var/cache/dev/appDevDebugProjectContainer.xml

xml file names appDevDebugProjectContainer.xml, not srcDevDebugProjectContainer.xml.

Test service container

Symfony 4.1 introduced new testing service container which allows to get private services in tests.
For example following code is correct:

namespace App\Tests\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

class DefaultControllerTest extends WebTestCase
{
    public function testIndex(): void
    {
        $client = static::createClient();

        /** @var ContainerInterface $container */
        $container = $client->getContainer();
        $entityManager = $container->get(EntityManagerInterface::class);
        // do something with entity manager

        $client->request('GET', '/');

        $this->assertSame(200, $client->getResponse()->getStatusCode());
    }
}

But PHPStan throws error "Service "Doctrine\ORM\EntityManagerInterface" is private."

Dependency on roave/security-advisories

While I certainly get the benefit from including that repository, I do not quite understand why it is listed as a dependency and not a dev-dependency.

Good for this project to make use of secure packages only, but forcing such limitations upon all users who would want to install this extensions seems a bit harsh, doesn't it ?

New parameter name

srcDevDebugProjectContainerXml is very strange. It does not say at all why it is needed. Moreover parameters is usually named using snake notation.
I suggest to change it to container_xml_path.
If you agree or you can suggest better name I will create a PR.

PHP Fatal error: Cannot make non static method PHPStan\Type\DynamicMethodReturnTypeExtension::getClass() static

Hey! Just installed this extension and it throws:

PHP Fatal error:  Cannot make non static method PHPStan\Type\DynamicMethodReturnTypeExtension::getClass() static in class Lookyman\PHPStan\Symfony\Type\ContainerInterfaceDynamicReturnTypeExtension in /path/vendor/lookyman/phpstan-symfony/src/Type/ContainerInterfaceDynamicReturnTypeExtension.php on line 18

Is there a bug or am I doing something wrong?

PHP71 and PHPStan 0.9

I iuncluded
- vendor/lookyman/phpstan-symfony/extension.neon

And added a path to service map

services:
    - Lookyman\PHPStan\Symfony\ServiceMap(var/cache/dev/DevDebugProjectContainer.xml)

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.