Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
Merge 9ccc161 into 77923be
Browse files Browse the repository at this point in the history
  • Loading branch information
lookyman authored Jan 21, 2018
2 parents 77923be + 9ccc161 commit 66d770b
Show file tree
Hide file tree
Showing 29 changed files with 437 additions and 305 deletions.
4 changes: 2 additions & 2 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service_name: travis-ci
coverage_clover: coverage.xml
json_path: coverage.json
coverage_clover: tests/tmp/clover.xml
json_path: tests/tmp/coveralls.json
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
build.xml
phpcs.xml
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
ruleset.xml export-ignore
36 changes: 6 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache

env: # intentionally blank

php:
- 7.1
- 7.2

matrix:
fast_finish: true
include:
- php: 7.2
env: COVERAGE="1"
allow_failures:
- php: 7.2
env: COVERAGE="1"

install:
- travis_retry composer install --no-interaction --prefer-dist
before_script:
- composer self-update
- composer install

script:
- >
if [ "$COVERAGE" != "1" ]; then
phpenv config-rm xdebug.ini
&& composer check; fi
- if [ "$COVERAGE" == "1" ]; then ./vendor/bin/phpunit --coverage-clover=./coverage.xml; fi
- vendor/bin/phing

after_success:
- >
if [ $COVERAGE == "1" ]; then
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
&& php ./coveralls.phar --verbose
|| true; fi
after_script:
- php vendor/bin/coveralls -v
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
# Symfony extension for PHPStan
# PHPStan Symfony Framework extensions and rules

## What does it do?
[![Build Status](https://travis-ci.org/phpstan/phpstan-symfony.svg)](https://travis-ci.org/phpstan/phpstan-symfony)
[![Latest Stable Version](https://poser.pugx.org/phpstan/phpstan-symfony/v/stable)](https://packagist.org/packages/phpstan/phpstan-symfony)
[![License](https://poser.pugx.org/phpstan/phpstan-symfony/license)](https://packagist.org/packages/phpstan/phpstan-symfony)

* 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.
* [PHPStan](https://github.com/phpstan/phpstan)

## Installation
This extension provides following features:

```sh
composer require --dev lookyman/phpstan-symfony
```
* 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.

## Usage

## Configuration
To use this extension, require it in [Composer](https://getcomposer.org/):

```bash
composer require --dev phpstan/phpstan-symfony
```

Put this into your `phpstan.neon` config:
And include extension.neon in your project's PHPStan config:

```neon
```
includes:
- vendor/lookyman/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
parameters:
symfony:
container_xml_path: %rootDir%/../../../var/cache/dev/srcDevDebugProjectContainer.xml
```

## 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 `srcDevDebugProjectContainer.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.
97 changes: 97 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="PHPStan Symfony Framework extensions and rules" default="check">

<target name="check" depends="
composer,
lint,
cs,
tests,
phpstan
"/>

<target name="composer">
<exec
executable="composer"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg value="install"/>
</exec>
</target>

<target name="lint">
<exec
executable="vendor/bin/parallel-lint"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg path="src"/>
<arg path="tests"/>
</exec>
</target>

<target name="cs">
<exec
executable="vendor/bin/phpcs"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg value="--extensions=php"/>
<arg value="--encoding=utf-8"/>
<arg value="--tab-width=4"/>
<arg value="-sp"/>
<arg path="src"/>
<arg path="tests"/>
</exec>
</target>

<target name="cs-fix">
<exec
executable="vendor/bin/phpcbf"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg value="--extensions=php"/>
<arg value="--encoding=utf-8"/>
<arg value="--tab-width=4"/>
<arg value="-sp"/>
<arg path="src"/>
<arg path="tests"/>
</exec>
</target>

<target name="tests">
<exec
executable="vendor/bin/phpunit"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg value="-c"/>
<arg value="tests/phpunit.xml"/>
<arg path="tests"/>
</exec>
</target>

<target name="phpstan">
<exec
executable="vendor/bin/phpstan"
logoutput="true"
passthru="true"
checkreturn="true"
>
<arg value="analyse"/>
<arg value="-l"/>
<arg value="7"/>
<arg value="-c"/>
<arg path="phpstan.neon"/>
<arg path="src"/>
<arg path="tests"/>
</exec>
</target>

</project>
45 changes: 20 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
{
"name": "lookyman/phpstan-symfony",
"license": "MIT",
"description": "Symfony extension for PHPStan",
"keywords": ["PHPStan", "Symfony"],
"name": "phpstan/phpstan-symfony",
"description": "Symfony Framework extensions and rules for PHPStan",
"license": ["MIT"],
"authors": [
{
"name": "Lukáš Unger",
"email": "looky.msc@gmail.com",
"homepage": "https://lookyman.net"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.10-dev"
}
},
"require": {
"php": "^7.1"
"php": "~7.1",
"phpstan/phpstan": "^0.9.1"
},
"require-dev": {
"consistence/coding-standard": "^2.0",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phpstan/phpstan": "^0.9.0",
"phing/phing": "^2.16.0",
"phpstan/phpstan-strict-rules": "^0.9",
"satooshi/php-coveralls": "^1.0",
"slevomat/coding-standard": "^3.3.0",
"phpunit/phpunit": "^6.4",
"phpstan/phpstan-phpunit": "^0.9.0",
"symfony/framework-bundle": "^4.0",
"phpstan/phpstan-strict-rules": "^0.9.0",
"lookyman/coding-standard": "0.1.0"
"symfony/framework-bundle": "^4.0"
},
"autoload": {
"psr-4": {
"Lookyman\\PHPStan\\Symfony\\": "src/"
"PHPStan\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lookyman\\PHPStan\\Symfony\\": "tests/"
}
},
"scripts": {
"lint": "parallel-lint ./src ./tests",
"cs": "phpcs --colors --extensions=php --encoding=utf-8 -sp ./src ./tests",
"tests": "phpunit --coverage-text",
"stan": "phpstan analyse -l max -c ./phpstan.neon ./src ./tests",
"check": [
"@lint",
"@cs",
"@tests",
"@stan"
]
"classmap": ["tests/"]
}
}
22 changes: 13 additions & 9 deletions extension.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
services:
-
class: Lookyman\PHPStan\Symfony\Type\ContainerInterfaceDynamicReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
class: PHPStan\Type\Symfony\ContainerInterfaceDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: Lookyman\PHPStan\Symfony\Type\ControllerDynamicReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
class: PHPStan\Type\Symfony\ControllerDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: Lookyman\PHPStan\Symfony\Rules\ContainerInterfacePrivateServiceRule
tags: [phpstan.rules.rule]
class: PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule
tags:
- phpstan.rules.rule
-
class: Lookyman\PHPStan\Symfony\Rules\ContainerInterfaceUnknownServiceRule
tags: [phpstan.rules.rule]
- Lookyman\PHPStan\Symfony\ServiceMap(%symfony.container_xml_path%)
class: PHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule
tags:
- phpstan.rules.rule
- PHPStan\Symfony\ServiceMap(%symfony.container_xml_path%)
36 changes: 36 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<ruleset name="PHPStan PHPUnit extensions and rules">
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
<exclude name="Squiz.Functions.GlobalFunction.Found"/>
</rule>
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions"/>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="caseSensitive" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="0"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<properties>
<property name="usefulAnnotations" type="array" value="
@dataProvider,
@requires
"/>
</properties>
</rule>
<exclude-pattern>tests/*/data</exclude-pattern>
</ruleset>
4 changes: 0 additions & 4 deletions phpcs.xml.dist

This file was deleted.

3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-phpunit/strictRules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
excludes_analyse:
- %rootDir%/../../../tests/*/data/*
- */tests/*/data/*
13 changes: 0 additions & 13 deletions phpunit.xml.dist

This file was deleted.

Loading

0 comments on commit 66d770b

Please sign in to comment.