Go to file
Matthew Brown fcc034ee13
Merge pull request #16 from bendavies/github-actions-psalm-cache
cache psalm cache in ci to allow --diff --diff-methods
2020-04-19 22:49:26 -04:00
.build cache psalm cache in ci to allow --diff --diff-methods 2020-03-19 10:12:43 +00:00
.github/workflows fix composer.json hashing 2020-03-19 10:12:43 +00:00
src Add null check 2020-04-19 22:48:59 -04:00
tests HeaderBag get return type (#24) 2020-04-14 17:21:05 +03:00
.gitignore cache psalm cache in ci to allow --diff --diff-methods 2020-03-19 10:12:43 +00:00
.php_cs.dist 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 HeaderBag get return type (#24) 2020-04-14 17:21:05 +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 Merge pull request #16 from bendavies/github-actions-psalm-cache 2020-04-19 22:49:26 -04:00
README.md HeaderBag get return type (#24) 2020-04-14 17:21:05 +03:00

Symfony Psalm Plugin

Integrate

Installation

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

Features

  • Detect ContainerInterface::get() result type. Works better if you configure compiled container XML file.
  • Detect return type of console arguments (InputInterface::getArgument()) and options (InputInterface::getOption()). Enforces to use InputArgument and InputOption constants as a part of best practise.
  • 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.
  • Detect return type of Symfony\Component\HttpFoundation\HeaderBag::get (by checking third argument for < Symfony 4.4)
  • 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="Psalm\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="Psalm\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