Skip to content

Commit

Permalink
minor #1498 [ci] implement phpstan for static analysis of the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow committed Apr 5, 2024
1 parent f7ee250 commit 30cdf17
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 56 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/ci-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,6 @@ env:
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"

jobs:
coding-standards:
name: "Coding Standards (${{ matrix.php-version }})"

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version:
- '8.1'

steps:
-
name: Checkout code
uses: "actions/checkout@v3"

-
name: Install PHP
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

-
name: Validate composer.json
run: "composer validate --strict --no-check-lock"

-
name: Composer install
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts"

-
name: Composer install php-cs-fixer
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

-
name: Run PHP-CS-Fixer
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"

test:
name: "PHP ${{ matrix.php-version }} + @${{ matrix.symfony-version }} ${{ matrix.dependency-versions }} deps"

Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/ci-static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "CI Static Analysis"

on:
pull_request:
push:
branches:
- 'main'
schedule:
- cron: '0 0 * * *'

env:
PHPUNIT_FLAGS: "-v"
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"

jobs:
coding-standards:
name: "Coding Standards"

runs-on: ubuntu-latest

steps:
-
name: Checkout code
uses: "actions/checkout@v3"

-
name: Install PHP
uses: "shivammathur/setup-php@v2"

-
name: Validate composer.json
run: "composer validate --strict --no-check-lock"

-
name: Composer install
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts"

-
name: Composer install php-cs-fixer
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

-
name: Run PHP-CS-Fixer
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"

phpstan:
name: PHPStan

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: "actions/checkout@v4"

- name: Install PHP
uses: "shivammathur/setup-php@v2"

- name: Install Composer Dependencies
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts"

- name: Install PHPStan
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/phpstan"

- name: Install Optional Dependencies
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/phpstan/includes"

- name: Install PHPUnit
run: "vendor/bin/simple-phpunit --version"

- name: Run PHPStan
run: "tools/phpstan/vendor/bin/phpstan analyze --memory-limit=1G --error-format=github"
26 changes: 26 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
level: 6
bootstrapFiles:
- vendor/autoload.php
- tools/phpstan/includes/vendor/autoload.php
paths:
- src/Maker
- tests/Command
- tests/Docker
- tests/Maker
excludePaths:
- tests/Doctrine/fixtures
- tests/fixtures
- tests/Security/fixtures
- tests/Security/yaml_fixtures
- tests/tmp
- tests/Util/fixtures
- tests/Util/yaml_fixtures
ignoreErrors:
-
message: '#Property .+phpCompatUtil is never read, only written\.#'
path: src/Maker/*

-
message: '#Class Symfony\\Bundle\\MakerBundle\\Maker\\LegacyApiTestCase not found#'
path: src/Maker/*
2 changes: 1 addition & 1 deletion src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
}

foreach ($fileManagerOperations as $path => $manipulatorOrMessage) {
if (\is_string($manipulatorOrMessage)) {
if (\is_string($manipulatorOrMessage)) { /* @phpstan-ignore-line - https://github.com/symfony/maker-bundle/issues/1509 */
$io->comment($manipulatorOrMessage);
} else {
$this->fileManager->dumpFile($path, $manipulatorOrMessage->getSourceCode());
Expand Down
1 change: 1 addition & 0 deletions src/Maker/MakeUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
} else {
$nextSteps[] = sprintf(
'Open <info>%s</info> to finish implementing your user provider.',
/* @phpstan-ignore-next-line - $customProviderPath is defined in this else statement */
$this->fileManager->relativizePath($customProviderPath)
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FunctionalTest extends TestCase
* Smoke test to make sure the DI autowiring works and all makers
* are registered and have the correct arguments.
*/
public function testWiring()
public function testWiring(): void
{
$kernel = new MakerTestKernel('dev', true);

Expand Down
1 change: 1 addition & 0 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ public function getTestDetails(): \Generator
];
}

/** @param array<string, mixed> $data */
private function runEntityTest(MakerTestRunner $runner, array $data = []): void
{
$runner->renderTemplateFile(
Expand Down
4 changes: 2 additions & 2 deletions tests/Maker/MakeFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeForm::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_generates_basic_form' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down Expand Up @@ -204,7 +204,7 @@ public function getTestDetails()
];
}

private function runFormTest(MakerTestRunner $runner, string $filename)
private function runFormTest(MakerTestRunner $runner, string $filename): void
{
$runner->copy(
'make-form/tests/'.$filename,
Expand Down
6 changes: 3 additions & 3 deletions tests/Maker/MakeMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function createMakeMessageTest(): MakerTestDetails
});
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_generates_basic_message' => [$this->createMakeMessageTest()
->run(function (MakerTestRunner $runner) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public function getTestDetails()
];
}

private function runMessageTest(MakerTestRunner $runner, string $filename)
private function runMessageTest(MakerTestRunner $runner, string $filename): void
{
$runner->copy(
'make-message/tests/'.$filename,
Expand All @@ -104,7 +104,7 @@ private function runMessageTest(MakerTestRunner $runner, string $filename)
$runner->runTests();
}

private function configureTransports(MakerTestRunner $runner)
private function configureTransports(MakerTestRunner $runner): void
{
$runner->writeFile(
'config/packages/messenger.yaml',
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeMessengerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeMessengerMiddleware::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_generates_messenger_middleware' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeSerializerEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeSerializerEncoder::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_makes_serializer_encoder' => [$this->createMakerTest()
// serializer-pack 1.1 requires symfony/property-info >= 5.4
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeTwigExtension::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_makes_twig_extension' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeUnitTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getMakerClass(): string
return MakeUnitTest::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_makes_unit_test' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeValidator::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_makes_validator' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMakerClass(): string
return MakeVoter::class;
}

public function getTestDetails()
public function getTestDetails(): \Generator
{
yield 'it_makes_voter' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
Expand Down
14 changes: 14 additions & 0 deletions tools/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require": {
"phpstan/phpstan": "^1.10",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
3 changes: 3 additions & 0 deletions tools/phpstan/includes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!composer.json
22 changes: 22 additions & 0 deletions tools/phpstan/includes/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"require": {
"api-platform/core": "^3.2",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-fixtures-bundle": "^3.5",
"symfony/form": "^7.0",
"symfony/mailer": "^7.0",
"symfony/messenger": "^7.0",
"symfony/orm-pack": "^2.4",
"symfony/scheduler": "^7.0",
"symfony/security-bundle": "^7.0",
"symfony/test-pack": "^1.1",
"symfony/twig-bundle": "^7.0",
"symfony/ux-live-component": "^2.16",
"symfony/ux-turbo": "^2.16",
"symfony/validator": "^7.0",
"symfonycasts/reset-password-bundle": "^1.21",
"symfonycasts/verify-email-bundle": "^1.17",
"symfony/webpack-encore-bundle": "^2.1",
"symfony/panther": "^2.1"
}
}

0 comments on commit 30cdf17

Please sign in to comment.