Skip to content

Commit

Permalink
feat: add cs-fixer (#230)
Browse files Browse the repository at this point in the history
* feat: add cs-fixer

* ci: add php-cs-fixer job
  • Loading branch information
shyim authored Nov 10, 2023
1 parent cc69fcd commit 628f8bb
Show file tree
Hide file tree
Showing 65 changed files with 169 additions and 108 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Code Style
on:
pull_request:
push:
branches:
- main

jobs:
php-cs-fixer:
uses: FriendsOfShopware/actions/.github/workflows/php-cs-fixer.yml@main
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"allow-plugins": {
"symfony/runtime": true
}
},
"scripts": {
"cs-fix": "docker run --rm -v $(pwd):$(pwd) -w $(pwd) oskarstark/php-cs-fixer-ga --rules @PER-CS2.0,@PER-CS2.0:risky --allow-risky=yes ."
}
}
1 change: 1 addition & 0 deletions src/Command/ChangeUserPasswordCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand Down
4 changes: 3 additions & 1 deletion src/Command/DevRobotsTxtCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand All @@ -15,7 +16,8 @@
class DevRobotsTxtCommand extends Command
{
public function __construct(
#[Autowire('%kernel.project_dir%/public')] private readonly string $envPath
#[Autowire('%kernel.project_dir%/public')]
private readonly string $envPath
) {
parent::__construct();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/EnvDelCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand All @@ -16,7 +17,8 @@
class EnvDelCommand extends Command
{
public function __construct(
#[Autowire('%kernel.project_dir%/.env')] private readonly string $envPath
#[Autowire('%kernel.project_dir%/.env')]
private readonly string $envPath
) {
parent::__construct();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/EnvGetCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand All @@ -17,7 +18,8 @@
class EnvGetCommand extends Command
{
public function __construct(
#[Autowire('%kernel.project_dir%/.env')] private readonly string $envPath
#[Autowire('%kernel.project_dir%/.env')]
private readonly string $envPath
) {
parent::__construct();
}
Expand Down
5 changes: 2 additions & 3 deletions src/Command/EnvListCommand.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;

use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand('frosh:env:list')]
class EnvListCommand extends EnvGetCommand
{
}
class EnvListCommand extends EnvGetCommand {}
4 changes: 3 additions & 1 deletion src/Command/EnvSetCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand All @@ -16,7 +17,8 @@
class EnvSetCommand extends Command
{
public function __construct(
#[Autowire('%kernel.project_dir%/.env')] private readonly string $envPath
#[Autowire('%kernel.project_dir%/.env')]
private readonly string $envPath
) {
parent::__construct();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/MonitorCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand Down Expand Up @@ -30,7 +31,8 @@ class MonitorCommand extends Command
private const MONITOR_SALESCHANNEL_ARG = 'sales-channel';

public function __construct(
#[Autowire(service: MailService::class)] private readonly AbstractMailService $mailService,
#[Autowire(service: MailService::class)]
private readonly AbstractMailService $mailService,
private readonly SystemConfigService $configService,
private readonly Connection $connection,
private readonly EntityRepository $scheduledTaskRepository
Expand Down
4 changes: 3 additions & 1 deletion src/Command/UpdateComposerPluginsCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand All @@ -20,7 +21,8 @@ class UpdateComposerPluginsCommand extends Command
private readonly Application $application;

public function __construct(
#[Autowire('%kernel.project_dir%')] private readonly string $projectDir,
#[Autowire('%kernel.project_dir%')]
private readonly string $projectDir,
private readonly KernelPluginLoader $pluginLoader
) {
parent::__construct();
Expand Down
1 change: 1 addition & 0 deletions src/Command/UpdatePluginsCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Command;
Expand Down
13 changes: 7 additions & 6 deletions src/Components/CacheAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components;
Expand Down Expand Up @@ -105,14 +106,14 @@ private function getCacheAdapter(AdapterInterface $adapter): AdapterInterface
{
if ($adapter instanceof CacheDecorator) {
// Do not declare function as static
$func = \Closure::bind(fn () => $adapter->decorated, $adapter, $adapter::class);
$func = \Closure::bind(fn() => $adapter->decorated, $adapter, $adapter::class);

return $this->getCacheAdapter($func());
}

if ($adapter instanceof TagAwareAdapter || $adapter instanceof TraceableAdapter) {
// Do not declare function as static
$func = \Closure::bind(fn () => $adapter->pool, $adapter, $adapter::class);
$func = \Closure::bind(fn() => $adapter->pool, $adapter, $adapter::class);

return $this->getCacheAdapter($func());
}
Expand All @@ -123,24 +124,24 @@ private function getCacheAdapter(AdapterInterface $adapter): AdapterInterface
private function getRedis(AdapterInterface $adapter): ?\Redis
{
if ($adapter instanceof RedisTagAwareAdapter) {
$redisProxyGetter = \Closure::bind(fn () => $adapter->redis, $adapter, RedisTagAwareAdapter::class);
$redisProxyGetter = \Closure::bind(fn() => $adapter->redis, $adapter, RedisTagAwareAdapter::class);
} else {
$redisProxyGetter = \Closure::bind(fn () => $adapter->redis, $adapter, RedisAdapter::class);
$redisProxyGetter = \Closure::bind(fn() => $adapter->redis, $adapter, RedisAdapter::class);
}

return $redisProxyGetter();
}

private function getPathFromFilesystemAdapter(FilesystemAdapter $adapter): string
{
$getter = \Closure::bind(fn () => $adapter->directory, $adapter, $adapter::class);
$getter = \Closure::bind(fn() => $adapter->directory, $adapter, $adapter::class);

return $getter();
}

private function getPathOfFilesAdapter(PhpFilesAdapter $adapter): string
{
$getter = \Closure::bind(fn () => $adapter->directory, $adapter, $adapter::class);
$getter = \Closure::bind(fn() => $adapter->directory, $adapter, $adapter::class);

return $getter();
}
Expand Down
1 change: 1 addition & 0 deletions src/Components/CacheHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components;
Expand Down
1 change: 1 addition & 0 deletions src/Components/CacheRegistry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Elasticsearch;
Expand All @@ -11,9 +12,9 @@
final class AdminInfoSubscriberEventListener
{
public function __construct(
#[Autowire('%frosh_tools.elasticsearch.enabled%')] private readonly bool $elasticsearchEnabled
) {
}
#[Autowire('%frosh_tools.elasticsearch.enabled%')]
private readonly bool $elasticsearchEnabled
) {}

public function __invoke(ResponseEvent $event): void
{
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Elasticsearch/DisabledElasticsearchManager.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Elasticsearch;

class DisabledElasticsearchManager extends ElasticsearchManager
{
public function __construct()
{
}
public function __construct() {}

public function isEnabled(): bool
{
Expand Down
10 changes: 6 additions & 4 deletions src/Components/Elasticsearch/ElasticsearchManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Elasticsearch;
Expand All @@ -18,15 +19,16 @@ class ElasticsearchManager
{
public function __construct(
private readonly Client $client,
#[Autowire('%frosh_tools.elasticsearch.enabled%')] private readonly bool $enabled,
#[Autowire('%frosh_tools.elasticsearch.enabled%')]
private readonly bool $enabled,
private readonly ElasticsearchIndexer $indexer,
private readonly MessageBusInterface $messageBus,
private readonly CreateAliasTaskHandler $createAliasTaskHandler,
private readonly ElasticsearchOutdatedIndexDetector $outdatedIndexDetector,
private readonly Connection $connection,
#[Autowire(service: 'shopware.increment.gateway.registry')] private readonly IncrementGatewayRegistry $gatewayRegistry
) {
}
#[Autowire(service: 'shopware.increment.gateway.registry')]
private readonly IncrementGatewayRegistry $gatewayRegistry
) {}

public function isEnabled(): bool
{
Expand Down
1 change: 1 addition & 0 deletions src/Components/Environment/EnvironmentCommentLine.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Environment;
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Environment/EnvironmentFile.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Environment;
Expand All @@ -8,9 +9,7 @@ class EnvironmentFile implements \Stringable
/**
* @param array<string, EnvironmentLine> $items
*/
public function __construct(private array $items)
{
}
public function __construct(private array $items) {}

public function __toString(): string
{
Expand Down
1 change: 1 addition & 0 deletions src/Components/Environment/EnvironmentKeyValue.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Environment;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Environment/EnvironmentLine.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Environment;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Environment/EnvironmentManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Environment;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Exception/CannotClearCacheException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Exception;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Health/Checker/CheckerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('frosh_tools.health_checker')]
interface HealthCheckerInterface
{
}
interface HealthCheckerInterface {}
5 changes: 2 additions & 3 deletions src/Components/Health/Checker/HealthChecker/MysqlChecker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\HealthChecker;
Expand All @@ -10,9 +11,7 @@

class MysqlChecker implements HealthCheckerInterface, CheckerInterface
{
public function __construct(private readonly Connection $connection)
{
}
public function __construct(private readonly Connection $connection) {}

public function collect(HealthCollection $collection): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Components/Health/Checker/HealthChecker/PhpChecker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\HealthChecker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\HealthChecker;
Expand All @@ -11,9 +12,9 @@
class ProductionChecker implements HealthCheckerInterface, CheckerInterface
{
public function __construct(
#[Autowire('%kernel.environment%')] private readonly string $environment
) {
}
#[Autowire('%kernel.environment%')]
private readonly string $environment
) {}

public function collect(HealthCollection $collection): void
{
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Health/Checker/HealthChecker/QueueChecker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\HealthChecker;
Expand All @@ -10,9 +11,7 @@

class QueueChecker implements HealthCheckerInterface, CheckerInterface
{
public function __construct(private readonly Connection $connection)
{
}
public function __construct(private readonly Connection $connection) {}

public function collect(HealthCollection $collection): void
{
Expand Down
Loading

0 comments on commit 628f8bb

Please sign in to comment.