From ef4c3deae49e7bf6bfc9c526940a5bf350f17f89 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Wed, 6 Mar 2024 20:47:25 +0000 Subject: [PATCH] feat: add php-cs-fixer --- .gitattributes | 3 ++- .github/workflows/php.yml | 15 +++++++++++++++ .gitignore | 3 ++- .php-cs-fixer.php | 13 +++++++++++++ composer.json | 3 ++- src/DependencyInjection/Configuration.php | 3 +-- src/Integration/UseShopwareExceptionIgnores.php | 6 ++---- src/Listener/FixRequestUrlListener.php | 5 +---- src/Listener/SalesChannelContextListener.php | 1 + src/Subscriber/ScheduledTaskSubscriber.php | 7 +++---- 10 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 .php-cs-fixer.php diff --git a/.gitattributes b/.gitattributes index 2c642ba..4bbec17 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,5 @@ /devcontainer export-ignore /.github export-ignore /phpstan.neon export-ignore -/README.md export-ignore \ No newline at end of file +/README.md export-ignore +/.php-cs-fixer.cache export-ignore \ No newline at end of file diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5ffa7a0..9d2f66d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -20,3 +20,18 @@ jobs: - name: Run PHPStan run: vendor/bin/phpstan + cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + - name: Install dependencies + run: composer install + + - name: Run PHP CS Fixer + run: vendor/bin/php-cs-fixer fix --dry-run --diff diff --git a/.gitignore b/.gitignore index 7602b69..d284020 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor -/composer.lock \ No newline at end of file +/composer.lock +/.php-cs-fixer.cache \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..89ff33a --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +setRiskyAllowed(true) + ->setRules([ + '@PER-CS2.0' => true, + '@PER-CS2.0:risky' => true, + ]) + ->setFinder(PhpCsFixer\Finder::create() + ->in(__DIR__ . '/src') + ) +; \ No newline at end of file diff --git a/composer.json b/composer.json index f5fc19f..431be91 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require-dev": { "phpstan/phpstan": "^1.10", "phpstan/phpstan-symfony": "^1.3", - "phpstan/extension-installer": "^1.3" + "phpstan/extension-installer": "^1.3", + "friendsofphp/php-cs-fixer": "^3.51" }, "config": { "allow-plugins": { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 78c7b93..03ee73b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -2,7 +2,6 @@ declare(strict_types=1); - namespace Frosh\SentryBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -23,4 +22,4 @@ public function getConfigTreeBuilder() return $treeBuilder; } -} \ No newline at end of file +} diff --git a/src/Integration/UseShopwareExceptionIgnores.php b/src/Integration/UseShopwareExceptionIgnores.php index e311bb4..001a477 100644 --- a/src/Integration/UseShopwareExceptionIgnores.php +++ b/src/Integration/UseShopwareExceptionIgnores.php @@ -11,15 +11,13 @@ class UseShopwareExceptionIgnores implements IntegrationInterface /** * @param array $exceptions */ - public function __construct(private readonly array $exceptions) - { - } + public function __construct(private readonly array $exceptions) {} public function setupOnce(): void { $exceptions = $this->exceptions; - Scope::addGlobalEventProcessor(function (Event $event) use($exceptions): ?Event { + Scope::addGlobalEventProcessor(function (Event $event) use ($exceptions): ?Event { $eventExceptions = $event->getExceptions()[0] ?? null; if ($eventExceptions === null) { diff --git a/src/Listener/FixRequestUrlListener.php b/src/Listener/FixRequestUrlListener.php index 13d4c2e..f400165 100644 --- a/src/Listener/FixRequestUrlListener.php +++ b/src/Listener/FixRequestUrlListener.php @@ -11,10 +11,7 @@ */ class FixRequestUrlListener { - public function __construct(private readonly HubInterface $hub) - { - - } + public function __construct(private readonly HubInterface $hub) {} public function __invoke(RequestEvent $event): void { diff --git a/src/Listener/SalesChannelContextListener.php b/src/Listener/SalesChannelContextListener.php index 3e78634..af87613 100644 --- a/src/Listener/SalesChannelContextListener.php +++ b/src/Listener/SalesChannelContextListener.php @@ -6,6 +6,7 @@ use Shopware\Core\System\SalesChannel\Event\SalesChannelContextCreatedEvent; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Contracts\Service\ResetInterface; + use function Sentry\configureScope; class SalesChannelContextListener implements ResetInterface diff --git a/src/Subscriber/ScheduledTaskSubscriber.php b/src/Subscriber/ScheduledTaskSubscriber.php index 9afc534..314d6b5 100644 --- a/src/Subscriber/ScheduledTaskSubscriber.php +++ b/src/Subscriber/ScheduledTaskSubscriber.php @@ -22,6 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Sentry\CheckInStatus; use Sentry\MonitorSchedule; + use function Sentry\captureCheckIn; class ScheduledTaskSubscriber implements EventSubscriberInterface @@ -34,9 +35,7 @@ class ScheduledTaskSubscriber implements EventSubscriberInterface public function __construct( private readonly EntityRepository $scheduledTaskRepository, private readonly bool $reportScheduledTasks - ) - { - } + ) {} public static function getSubscribedEvents(): array { @@ -147,4 +146,4 @@ private function fetchScheduledTaskCollection(): void $this->scheduledTaskCollection = $this->scheduledTaskRepository->search($criteria, $context)->getEntities(); } -} \ No newline at end of file +}