Go to file
Farhad Safarov d2f0447add
add class to codebase if service is used by id (#10)
* add class to codebase if service is used by id

* fix doc
2020-03-11 16:43:52 +03:00
src add class to codebase if service is used by id (#10) 2020-03-11 16:43:52 +03:00
tests add class to codebase if service is used by id (#10) 2020-03-11 16:43:52 +03:00
.gitignore refactor container check (#8) 2020-03-09 15:24:39 +03:00
.php_cs.dist refactor container check (#8) 2020-03-09 15:24:39 +03:00
.travis.yml refactor container check (#8) 2020-03-09 15:24:39 +03:00
codeception.yml refactor container check (#8) 2020-03-09 15:24:39 +03:00
composer.json add container unit tests (#9) 2020-03-10 19:00:55 +03:00
LICENSE initial commit 2019-11-12 16:36:05 +03:00
phpunit.xml add container unit tests (#9) 2020-03-10 19:00:55 +03:00
psalm.xml psalm config (#1) 2019-11-12 16:51:13 +03:00
README.md add class to codebase if service is used by id (#10) 2020-03-11 16:43:52 +03:00

Symfony Psalm Plugin

Build Status

Installation

composer require --dev seferov/symfony-psalm-plugin
vendor/bin/psalm-plugin enable seferov/symfony-psalm-plugin

Features

  • Detect ContainerInterface::get() result type. Works better if you configure compiled container XML file.
  • Fixes PossiblyInvalidArgument for Symfony\Component\HttpFoundation\Request::getContent. The plugin calculates real return type by checking the given argument and marks return type as either string or resource.
  • Complains when Container is injected to a service. Use dependency-injection.

Configuration

If you followed installation instructions, psalm-plugin command would added plugin configuration to psalm.xml

<?xml version="1.0"?>
<psalm totallyTyped="true">
    <!--  project configuration -->

    <plugins>
        <pluginClass class="Seferov\SymfonyPsalmPlugin\Plugin" />
    </plugins>
</psalm>

To be able to detect return types of services using ID (generally starts with @ in Symfony YAML config files. Ex: logger service) containerXml must be provided. Example:

<pluginClass class="Seferov\SymfonyPsalmPlugin\Plugin">
    <containerXml>var/cache/dev/App_KernelDevDebugContainer.xml</containerXml>
</pluginClass>

This file path may change based on your Symfony version, file structure and environment settings. Default file for Symfony versions:

  • Symfony 3: var/cache/dev/srcDevDebugProjectContainer.xml
  • Symfony 4: var/cache/dev/srcApp_KernelDevDebugContainer.xml
  • Symfony 5: var/cache/dev/App_KernelDevDebugContainer.xml

Credits