-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECP-8568] Configure and enable PHPStan
- Loading branch information
1 parent
ecc3b5c
commit be3883a
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,6 @@ jobs: | |
|
||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit | ||
|
||
- name: Run PHPStan | ||
run: composer phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Adyen\Shopware\AdyenPaymentShopware6; | ||
use Shopware\Core\Framework\Plugin\KernelPluginLoader\StaticKernelPluginLoader; | ||
use Shopware\Core\DevOps\StaticAnalyze\StaticAnalyzeKernel; | ||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
$projectRoot = dirname(__DIR__, 4); | ||
$pluginRootPath = dirname(__DIR__); | ||
|
||
$classLoader = require $projectRoot . '/vendor/autoload.php'; | ||
if (file_exists($projectRoot . '/.env')) { | ||
(new Dotenv())->usePutEnv()->load($projectRoot . '/.env'); | ||
} | ||
|
||
$composerJson = json_decode((string) file_get_contents($pluginRootPath . '/composer.json'), true); | ||
$adyenPaymentsShopware6 = [ | ||
'autoload' => $composerJson['autoload'], | ||
'baseClass' => AdyenPaymentShopware6::class, | ||
'managedByComposer' => false, | ||
'name' => 'AdyenPaymentsShopware6', | ||
'version' => $composerJson['version'], | ||
'active' => true, | ||
'path' => $pluginRootPath, | ||
]; | ||
$pluginLoader = new StaticKernelPluginLoader($classLoader, null, [$adyenPaymentsShopware6]); | ||
|
||
$kernel = new StaticAnalyzeKernel('dev', true, $pluginLoader, 'phpstan-test-cache-id'); | ||
$kernel->boot(); | ||
|
||
$phpStanConfigDist = file_get_contents($pluginRootPath . '/phpstan.neon.dist'); | ||
if ($phpStanConfigDist === false) { | ||
throw new RuntimeException('phpstan.neon.dist file not found'); | ||
} | ||
|
||
// because the cache dir is hashed by Shopware, we need to set the PHPStan config dynamically | ||
$phpStanConfig = str_replace( | ||
[ | ||
'%ShopwareHashedCacheDir%', | ||
'%ShopwareRoot%', | ||
'%ShopwareKernelClass%', | ||
], | ||
[ | ||
str_replace($kernel->getProjectDir(), '', $kernel->getCacheDir()), | ||
$projectRoot . (is_dir($projectRoot . '/platform') ? '/platform' : ''), | ||
str_replace('\\', '_', get_class($kernel)), | ||
], | ||
$phpStanConfigDist | ||
); | ||
|
||
file_put_contents(__DIR__ . '/../phpstan.neon.dist', $phpStanConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
$projectRoot = $_SERVER['PROJECT_ROOT'] ?? dirname(__DIR__, 4); | ||
|
||
require_once $projectRoot . '/vendor/autoload.php'; | ||
|
||
if (file_exists($projectRoot . '/.env')) { | ||
(new Dotenv())->usePutEnv()->load($projectRoot . '/.env'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
includes: | ||
- %ShopwareRoot%/vendor/phpstan/phpstan/conf/bleedingEdge.neon | ||
|
||
parameters: | ||
phpVersion: 80100 | ||
level: 8 | ||
tmpDir: var/cache/phpstan | ||
inferPrivatePropertyTypeFromConstructor: true | ||
checkMissingIterableValueType: false | ||
checkGenericClassInNonGenericObjectType: false | ||
reportUnmatchedIgnoredErrors: false | ||
|
||
paths: | ||
- src | ||
excludePaths: | ||
- src/Resources | ||
- src/DevOps/Rector | ||
- src/Test | ||
|
||
ignoreErrors: | ||
# We won't type all arrays/iterables for now | ||
- '#no value type specified in iterable type#' | ||
|
||
- # ignore attributes, since we have to support PHP 7.4 for Shopware 6.4 | ||
message: '#use the .* attribute instead#' | ||
|
||
- # ignore Plus deprecations | ||
message: '#deprecated.*(Plus|PLUS|_PAYMENT_|MERCHANT_LOCATION)#' | ||
|
||
- # ignore Symfony 6 message queue deprecations | ||
message: '#AsMessageHandler#' | ||
|
||
- # ignore param type coverage | ||
message: '#.*Add more param types to get over.*#' | ||
|
||
- # ignore lineItemPayloadDeprecation deprecations | ||
message: '#Call to deprecated method setPayloadValue\(\) of class .*LineItem#' | ||
|
||
- # ignore DomainException deprecations | ||
message: '#use .*Exception::.* instead#' | ||
|
||
- # ignore deprecated StockUpdater (PPI-805) | ||
message : '#deprecated class Shopware\\Core\\Content\\Product\\DataAbstractionLayer\\StockUpdater#' | ||
|
||
- # ignore deprecated UrlGenerator | ||
message : '#Use AbstractMediaUrlGenerator instead#' | ||
|
||
bootstrapFiles: | ||
- bin/static-analyze-autoloader.php |