Skip to content

Commit

Permalink
feat: Replace squizlabs/php_codesniffer package with `friendsofphp/…
Browse files Browse the repository at this point in the history
…php-cs-fixer`
  • Loading branch information
ambroisemaupate committed Oct 28, 2024
1 parent 71702c5 commit a369090
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 60 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ compose.override.yml
.phpcs-cache
report.txt

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###
openapi.json
/*.sql
/*.zip
Expand All @@ -59,3 +55,8 @@ openapi.json
!/var/export/.gitkeep

supervisord.pid

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ roadiz_skeleton_test:
#- ssh-keyscan -H 'github.com' >> ~/.ssh/known_hosts
script:
- composer install
- php -d memory_limit=-1 vendor/bin/phpcs -p ./src
- php -d memory_limit=-1 vendor/bin/php-cs-fixer check --ansi -vvv
- php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon
- php -d memory_limit=-1 vendor/bin/phpunit --colors=never

Expand Down
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude([
'var',
'docker',
'config',
// Do not fix generated PHP files
'src/GeneratedEntity',
'vendor',
'.data',
'.github',
])
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'blank_line_after_opening_tag' => true,
'declare_strict_types' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache:
docker compose exec -u www-data app php bin/console messenger:stop-workers

test:
docker compose exec -u www-data app php -d "memory_limit=-1" vendor/bin/phpcbf --report=full --report-file=./report.txt -p ./src
docker compose exec -u www-data app php -d "memory_limit=-1" vendor/bin/php-cs-fixer fix --ansi -vvv
docker compose exec -u www-data app php -d "memory_limit=-1" vendor/bin/phpstan analyse -c phpstan.neon
XDEBUG_MODE=coverage php -d "memory_limit=-1" vendor/bin/phpunit

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"symfony/requirements-checker": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3.1",
"phpstan/phpstan-symfony": "^1.3.7",
"phpunit/phpunit": "^9.5",
"rezozero/intervention-request-bundle": "~3.0.0",
"squizlabs/php_codesniffer": "^3.6",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
Expand Down
10 changes: 6 additions & 4 deletions composer.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"symfony/requirements-checker": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3.1",
"phpstan/phpstan-symfony": "^1.3.7",
"phpunit/phpunit": "^9.5",
"rezozero/intervention-request-bundle": "~3.0.0",
"squizlabs/php_codesniffer": "^3.6",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
Expand Down Expand Up @@ -70,16 +70,18 @@
"requirements-checker": "script"
},
"post-install-cmd": [
"@auto-scripts"
"@auto-scripts",
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
],
"post-create-project-cmd": [
"bin/console secrets:generate-keys",
"bin/console secrets:set JWT_PASSPHRASE --random",
"bin/console secrets:set APP_SECRET --random",
"bin/console lexik:jwt:generate-keypair"
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
],
"post-update-cmd": [
"@auto-scripts"
"@auto-scripts",
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
]
},
"conflict": {
Expand Down
10 changes: 6 additions & 4 deletions composer_dev.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"symfony/requirements-checker": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3.1",
"phpstan/phpstan-symfony": "^1.3.7",
"phpunit/phpunit": "^9.5",
"rezozero/intervention-request-bundle": "~3.0.0",
"squizlabs/php_codesniffer": "^3.6",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
Expand Down Expand Up @@ -71,16 +71,18 @@
"requirements-checker": "script"
},
"post-install-cmd": [
"@auto-scripts"
"@auto-scripts",
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
],
"post-create-project-cmd": [
"bin/console secrets:generate-keys",
"bin/console secrets:set JWT_PASSPHRASE --random",
"bin/console secrets:set APP_SECRET --random",
"bin/console lexik:jwt:generate-keypair"
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
],
"post-update-cmd": [
"@auto-scripts"
"@auto-scripts",
"bin/console lexik:jwt:generate-keypair --skip-if-exists"
]
},
"conflict": {
Expand Down
17 changes: 0 additions & 17 deletions phpcs.xml.dist

This file was deleted.

2 changes: 2 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Model/CommonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ final class CommonContent
#[ApiProperty(identifier: true)]
public string $id = 'unique';

#[Groups(["common_content"])]
#[Groups(['common_content'])]
public ?NodesSources $home = null;

#[Groups(["common_content"])]
#[Groups(['common_content'])]
public ?NodesSources $errorPage = null;

#[Groups(["common_content"])]
#[Groups(['common_content'])]
public ?NodesSourcesHeadInterface $head = null;

#[Groups(["common_content"])]
#[Groups(['common_content'])]
public ?array $menus = null;

#[Groups(["common_content"])]
#[Groups(['common_content'])]
public ?array $footers = null;
}
15 changes: 8 additions & 7 deletions src/Controller/GetCommonContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
private readonly ManagerRegistry $managerRegistry,
private readonly NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory,
private readonly PreviewResolverInterface $previewResolver,
private readonly TreeWalkerGenerator $treeWalkerGenerator
private readonly TreeWalkerGenerator $treeWalkerGenerator,
) {
}

Expand All @@ -52,6 +52,7 @@ public function __invoke(Request $request): ?CommonContent
$translation,
4
);

return $resource;
} catch (ResourceNotFoundException $exception) {
throw $this->createNotFoundException($exception->getMessage(), $exception);
Expand All @@ -63,11 +64,12 @@ private function getErrorPage(TranslationInterface $translation): ?NodesSources
if (!class_exists('\App\GeneratedEntity\NSErrorPage')) {
return null;
}

// @phpstan-ignore-next-line
return $this->managerRegistry->getRepository('\App\GeneratedEntity\NSErrorPage')
->findOneBy([
'translation' => $translation,
'node.nodeName' => 'error-page'
'node.nodeName' => 'error-page',
]);
}

Expand Down Expand Up @@ -98,20 +100,19 @@ private function getTranslationFromRequest(?Request $request): TranslationInterf
->findOneAvailableByLocaleOrOverrideLocale((string) $locale);
}
if (null === $translation) {
throw new NotFoundHttpException('No translation for locale ' . $locale);
throw new NotFoundHttpException('No translation for locale '.$locale);
}

return $translation;
}

private function getTranslationRepository(): TranslationRepository
{
$repository = $this->managerRegistry->getRepository(TranslationInterface::class);
if (!$repository instanceof TranslationRepository) {
throw new \RuntimeException(
'Translation repository must be instance of ' .
TranslationRepository::class
);
throw new \RuntimeException('Translation repository must be instance of '.TranslationRepository::class);
}

return $repository;
}
}
2 changes: 2 additions & 0 deletions src/Doctrine/ProjectVersionComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class ProjectVersionComparator implements Comparator
private function getClassname(Version $version): string
{
$tokens = explode('\\', (string) $version);

return $tokens[count($tokens) - 1];
}

public function compare(Version $a, Version $b): int
{
$classA = $this->getClassname($a);
$classB = $this->getClassname($b);

/*
* Only compare class-name timestamp
*/
Expand Down
12 changes: 7 additions & 5 deletions src/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand All @@ -14,22 +16,22 @@ class Kernel extends BaseKernel
protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/' . $this->environment . '/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');

if (is_file(\dirname(__DIR__) . '/config/services.yaml')) {
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
$container->import('../config/services.yaml');
$container->import('../config/{services}_' . $this->environment . '.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');
} else {
$container->import('../config/{services}.php');
}
}

protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('../config/{routes}/' . $this->environment . '/*.yaml');
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');

if (is_file(\dirname(__DIR__) . '/config/routes.yaml')) {
if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
$routes->import('../config/routes.yaml');
} else {
$routes->import('../config/{routes}.php');
Expand Down
7 changes: 3 additions & 4 deletions src/Serializer/Normalizer/MenuLinkPathNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
final class MenuLinkPathNormalizer extends AbstractPathNormalizer
{
/**
* @param mixed $object
* @param string|null $format
* @param array $context
* @return array|\ArrayObject|bool|float|int|mixed|string|null
*
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
public function normalize(mixed $object, ?string $format = null, array $context = []): mixed
Expand All @@ -26,12 +24,13 @@ public function normalize(mixed $object, ?string $format = null, array $context
$actualUrl = $this->urlGenerator->generate(
RouteObjectInterface::OBJECT_BASED_ROUTE_NAME,
[
RouteObjectInterface::ROUTE_OBJECT => $object->getLinkInternalReferenceSources()[0]
RouteObjectInterface::ROUTE_OBJECT => $object->getLinkInternalReferenceSources()[0],
]
);
}
$data['url'] = $actualUrl;
}

return $data;
}
}
8 changes: 1 addition & 7 deletions src/TreeWalker/MenuNodeSourceWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use RZ\TreeWalker\AbstractCycleAwareWalker;
use RZ\TreeWalker\Definition\ZeroChildrenDefinition;

/**
* @package App\TreeWalker
*/
final class MenuNodeSourceWalker extends AbstractCycleAwareWalker
{
protected function initializeDefinitions(): void
Expand All @@ -35,10 +32,7 @@ protected function createDefinitionForNodeType(NodeTypeInterface $nodeType): cal
{
$context = $this->getContext();
if (!$context instanceof NodeSourceWalkerContext) {
throw new \InvalidArgumentException(
'TreeWalker context must be instance of ' .
NodeSourceWalkerContext::class
);
throw new \InvalidArgumentException('TreeWalker context must be instance of '.NodeSourceWalkerContext::class);
}
$childrenNodeTypes = $context->getNodeTypeResolver()->getChildrenNodeTypeList($nodeType);
if (count($childrenNodeTypes) > 0) {
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';
Expand Down

0 comments on commit a369090

Please sign in to comment.