Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use friendsofphp/php-cs-fixer instead of squizlabs/php_codesniffer #22

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
XDEBUG_MODE=coverage vendor/bin/phpunit -v
- name: Run PHP Code Sniffer
run: |
php -d "memory_limit=-1" vendor/bin/phpcs --report=full -p
php -d "memory_limit=-1" vendor/bin/php-cs-fixer check --ansi -vvv
- name: Run PHP Stan
run: |
php -d "memory_limit=-1" vendor/bin/phpstan analyse -c phpstan.neon
Expand Down
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Created by https://www.toptal.com/developers/gitignore/api/phpstorm
# Edit at https://www.toptal.com/developers/gitignore?templates=phpstorm

Expand Down Expand Up @@ -155,15 +154,15 @@ fabric.properties
!/.data/db_test/.gitkeep
!/.data/pgsql_test/.gitkeep
!/.data/solr/.gitkeep

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###
/report.txt
/composer.lock
/symfony.lock

###> lexik/jwt-authentication-bundle ###
/config/jwt/*.pem
###< lexik/jwt-authentication-bundle ###

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude(['var', 'vendor', 'docker', 'lib/EntityGenerator/tests/Mocks', 'config'])
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'blank_line_after_opening_tag' => true,
'declare_strict_types' => true,
])
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->setFinder($finder)
;
29 changes: 0 additions & 29 deletions .phpcs.xml

This file was deleted.

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
vendor/bin/monorepo-builder validate
make phpstan
XDEBUG_MODE=coverage vendor/bin/phpunit -v
php -d "memory_limit=-1" vendor/bin/phpcs -p
php -d "memory_limit=-1" vendor/bin/php-cs-fixer check --ansi -vvv
php -d "memory_limit=-1" bin/console lint:twig ./lib/Documents/src/Resources/views
php -d "memory_limit=-1" bin/console lint:twig ./lib/RoadizCoreBundle/templates
php -d "memory_limit=-1" bin/console lint:twig ./lib/RoadizFontBundle/templates
Expand All @@ -19,7 +19,10 @@ phpunit:
APP_ENV=test docker compose exec -u www-data app php vendor/bin/phpunit -v

fix:
php -d "memory_limit=-1" vendor/bin/phpcbf -p
php -d "memory_limit=-1" vendor/bin/php-cs-fixer fix --ansi -vvv

check:
php -d "memory_limit=-1" vendor/bin/php-cs-fixer check --ansi -vvv

requirements:
vendor/bin/requirements-checker
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"ambroisemaupate/intervention-request": "^4.0",
"async-aws/simple-s3": "^1.1",
"doctrine/doctrine-fixtures-bundle": "^3.6",
"friendsofphp/php-cs-fixer": "^3.64",
"league/flysystem-async-aws-s3": "^3.10",
"league/flysystem-aws-s3-v3": "^3.10",
"php-coveralls/php-coveralls": "^2.4",
Expand All @@ -149,7 +150,6 @@
"phpstan/phpstan-symfony": "^1.1.8",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.5",
"squizlabs/php_codesniffer": "^3.5",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
Expand Down
2 changes: 2 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Expand Down
2 changes: 2 additions & 0 deletions config/preload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}
2 changes: 0 additions & 2 deletions lib/DocGenerator/.github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
4 changes: 0 additions & 4 deletions lib/DocGenerator/Makefile

This file was deleted.

3 changes: 1 addition & 2 deletions lib/DocGenerator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
}
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
"squizlabs/php_codesniffer": "^3.5"
"phpstan/phpstan": "^1.5.3"
},
"extra": {
"branch-alias": {
Expand Down
17 changes: 0 additions & 17 deletions lib/DocGenerator/phpcs.xml.dist

This file was deleted.

25 changes: 8 additions & 17 deletions lib/DocGenerator/src/Generators/AbstractFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ abstract class AbstractFieldGenerator
protected ParameterBag $nodeTypesBag;
protected MarkdownGeneratorFactory $markdownGeneratorFactory;

/**
* @param MarkdownGeneratorFactory $fieldGeneratorFactory
* @param NodeTypeFieldInterface $field
* @param ParameterBag $nodeTypesBag
* @param TranslatorInterface $translator
*/
public function __construct(
MarkdownGeneratorFactory $fieldGeneratorFactory,
NodeTypeFieldInterface $field,
ParameterBag $nodeTypesBag,
TranslatorInterface $translator
TranslatorInterface $translator,
) {
$this->field = $field;
$this->nodeTypesBag = $nodeTypesBag;
Expand All @@ -35,13 +29,10 @@ public function __construct(

abstract public function getContents(): string;

/**
* @return string
*/
public function getIntroduction(): string
{
$lines = [
'### ' . $this->field->getLabel(),
'### '.$this->field->getLabel(),
];
if (!empty($this->field->getDescription())) {
$lines[] = $this->field->getDescription();
Expand All @@ -50,19 +41,19 @@ public function getIntroduction(): string
'',
'| | |',
'| --- | --- |',
'| **' . trim($this->translator->trans('docs.type')) . '** | ' . $this->translator->trans($this->field->getTypeName()) . ' |',
'| **' . trim($this->translator->trans('docs.technical_name')) . '** | `' . $this->field->getVarName() . '` |',
'| **' . trim($this->translator->trans('docs.universal')) . '** | *' . $this->markdownGeneratorFactory->getHumanBool($this->field->isUniversal()) . '* |',
'| **'.trim($this->translator->trans('docs.type')).'** | '.$this->translator->trans($this->field->getTypeName()).' |',
'| **'.trim($this->translator->trans('docs.technical_name')).'** | `'.$this->field->getVarName().'` |',
'| **'.trim($this->translator->trans('docs.universal')).'** | *'.$this->markdownGeneratorFactory->getHumanBool($this->field->isUniversal()).'* |',
]);

if (!empty($this->field->getGroupName())) {
$lines[] = '| **' . trim($this->translator->trans('docs.group')) . '** | ' . $this->field->getGroupName() . ' |';
$lines[] = '| **'.trim($this->translator->trans('docs.group')).'** | '.$this->field->getGroupName().' |';
}

if (!$this->field->isVisible()) {
$lines[] = '| **' . trim($this->translator->trans('docs.visible')) . '** | *' . $this->markdownGeneratorFactory->getHumanBool($this->field->isVisible()) . '* |';
$lines[] = '| **'.trim($this->translator->trans('docs.visible')).'** | *'.$this->markdownGeneratorFactory->getHumanBool($this->field->isVisible()).'* |';
}

return implode("\n", $lines) . "\n";
return implode("\n", $lines)."\n";
}
}
11 changes: 7 additions & 4 deletions lib/DocGenerator/src/Generators/ChildrenNodeFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function getContents(): string
{
return implode("\n\n", [
$this->getIntroduction(),
'#### ' . $this->translator->trans('docs.available_children_blocks'),
$this->getAvailableChildren()
'#### '.$this->translator->trans('docs.available_children_blocks'),
$this->getAvailableChildren(),
]);
}

Expand All @@ -25,20 +25,23 @@ protected function getChildrenNodeTypes(): array
if (null !== $this->field->getDefaultValues()) {
return array_filter(array_map(function (string $nodeTypeName) {
$nodeType = $this->nodeTypesBag->get(trim($nodeTypeName));

return $nodeType instanceof NodeTypeInterface ? $nodeType : null;
}, explode(',', $this->field->getDefaultValues())));
}

return [];
}

protected function getAvailableChildren(): string
{
return implode("\n", array_map(function (NodeTypeInterface $nodeType) {
$nodeTypeGenerator = $this->markdownGeneratorFactory->createForNodeType($nodeType);

return implode("\n", [
'* **' . trim($nodeTypeGenerator->getMenuEntry()) . '** ',
'* **'.trim($nodeTypeGenerator->getMenuEntry()).'** ',
$nodeType->getDescription(),
]);
}, $this->getChildrenNodeTypes())) . "\n";
}, $this->getChildrenNodeTypes()))."\n";
}
}
2 changes: 1 addition & 1 deletion lib/DocGenerator/src/Generators/CommonFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class CommonFieldGenerator extends AbstractFieldGenerator
public function getContents(): string
{
return implode("\n\n", [
$this->getIntroduction()
$this->getIntroduction(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public function getContents(): string
{
return implode("\n\n", [
$this->getIntroduction(),
$this->getDefaultValues()
$this->getDefaultValues(),
]);
}

private function getDefaultValues(): string
{
return implode("\n", array_map(function (string $value) {
return implode("\n", [
'* **' . trim($this->translator->trans(trim($value))) . '** `' . $value . '`',
'* **'.trim($this->translator->trans(trim($value))).'** `'.$value.'`',
]);
}, explode(',', $this->field->getDefaultValues() ?? ''))) . "\n";
}, explode(',', $this->field->getDefaultValues() ?? '')))."\n";
}
}
14 changes: 6 additions & 8 deletions lib/DocGenerator/src/Generators/DocumentationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class DocumentationGenerator
private ?array $reachableTypeGenerators = null;
private ?array $nonReachableTypeGenerators = null;

/**
* @param ParameterBag $nodeTypesBag
* @param TranslatorInterface $translator
*/
public function __construct(ParameterBag $nodeTypesBag, TranslatorInterface $translator)
{
$this->nodeTypesBag = $nodeTypesBag;
Expand Down Expand Up @@ -65,6 +61,7 @@ public function getReachableTypeGenerators(): array
return $this->markdownGeneratorFactory->createForNodeType($nodeType);
}, $this->getReachableTypes());
}

return $this->reachableTypeGenerators;
}

Expand All @@ -78,6 +75,7 @@ public function getNonReachableTypeGenerators(): array
return $this->markdownGeneratorFactory->createForNodeType($nodeType);
}, $this->getNonReachableTypes());
}

return $this->nonReachableTypeGenerators;
}

Expand All @@ -103,10 +101,10 @@ public function getNavBar(): string
}

return implode("\n", [
'* ' . $this->translator->trans('docs.pages'),
" * " . implode("\n * ", $pages),
'* ' . $this->translator->trans('docs.blocks'),
" * " . implode("\n * ", $blocks)
'* '.$this->translator->trans('docs.pages'),
' * '.implode("\n * ", $pages),
'* '.$this->translator->trans('docs.blocks'),
' * '.implode("\n * ", $blocks),
]);
}
}
12 changes: 1 addition & 11 deletions lib/DocGenerator/src/Generators/MarkdownGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class MarkdownGeneratorFactory
{
public function __construct(
private readonly ParameterBag $nodeTypesBag,
private readonly TranslatorInterface $translator
private readonly TranslatorInterface $translator,
) {
}

Expand All @@ -22,11 +22,6 @@ public function getHumanBool(bool $bool): string
return $bool ? $this->translator->trans('docs.yes') : $this->translator->trans('docs.no');
}

/**
* @param NodeTypeInterface $nodeType
*
* @return NodeTypeGenerator
*/
public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerator
{
return new NodeTypeGenerator(
Expand All @@ -36,11 +31,6 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
);
}

/**
* @param NodeTypeFieldInterface $field
*
* @return AbstractFieldGenerator
*/
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
{
return match (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public function getContents(): string
{
return implode("\n\n", [
$this->getIntroduction(),
'#### ' . $this->translator->trans('docs.available_referenced_nodes'),
$this->getAvailableChildren()
'#### '.$this->translator->trans('docs.available_referenced_nodes'),
$this->getAvailableChildren(),
]);
}
}
Loading
Loading