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

Commit

Permalink
Make the extension official
Browse files Browse the repository at this point in the history
  • Loading branch information
lookyman committed Apr 18, 2018
1 parent c9f4635 commit 0800e6a
Show file tree
Hide file tree
Showing 28 changed files with 470 additions and 331 deletions.
6 changes: 3 additions & 3 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
service_name: travis-ci
coverage_clover: tests/tmp/clover.xml
json_path: tests/tmp/coveralls.json
16 changes: 8 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
ruleset.xml export-ignore
tests export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
build.xml
phpcs.xml
phpstan.neon export-ignore
48 changes: 10 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
language: php

sudo: false

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

env:
- DEPENDENCIES="--prefer-lowest"
- DEPENDENCIES=""

php:
- 7.1
- 7.2
- master

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

install:
- travis_retry composer update --no-interaction --prefer-dist $DEPENDENCIES

env:
- dependencies=lowest
- dependencies=highest
before_script:
- composer self-update
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest --no-interaction; fi;
- if [ "$dependencies" = "highest" ]; then composer update --no-interaction; fi;
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

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
- vendor/bin/phing
after_script:
- php vendor/bin/coveralls -v
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
# 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/appDevDebugProjectContainer.xml # or srcDevDebugProjectContainer.xml for Symfony 4+
Expand All @@ -30,7 +36,3 @@ parameters:
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.
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>
50 changes: 23 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
{
"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",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.10"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phpunit/phpunit": "^6.4 || ^7.0",
"phpstan/phpstan-phpunit": "^0.9.0",
"symfony/framework-bundle": "^4.0",
"phpstan/phpstan-strict-rules": "^0.9.0",
"lookyman/coding-standard": "0.1.0"
"consistence/coding-standard": "^3.0.1",
"jakub-onderka/php-parallel-lint": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"phpunit/phpunit": "^7.0",
"phing/phing": "^2.16.0",
"phpstan/phpstan-strict-rules": "^0.10",
"satooshi/php-coveralls": "^1.0",
"slevomat/coding-standard": "^4.5.2",
"phpstan/phpstan-phpunit": "^0.10",
"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%)
43 changes: 43 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
</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>
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
<!-- <rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/> -->
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="src=>PHPStan,tests=>PHPStan"/>
</properties>
</rule>
<exclude-pattern>tests/*/data</exclude-pattern>
</ruleset>
4 changes: 0 additions & 4 deletions phpcs.xml.dist

This file was deleted.

5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ includes:

parameters:
excludes_analyse:
- %rootDir%/../../../tests/*/data/*
- */tests/*/data/*
ignoreErrors:
- '#Call to an undefined method object::noMethod\(\)\.#'
- '#Offset mixed does not exist on array\(\)\.#'

0 comments on commit 0800e6a

Please sign in to comment.