Skip to content

Commit

Permalink
Add coding standard (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 authored Sep 12, 2024
2 parents 8acc64c + 6d714cb commit 790edee
Show file tree
Hide file tree
Showing 126 changed files with 1,260 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
- name: "Check for security vulnerabilities"
run: symfony security:check

- name: "Validate coding standard"
run: vendor/bin/ecs check

- name: "Validate Container"
run: bin/console lint:container

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.6",
"sylius-labs/coding-standard": "^4.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/debug-bundle": "^6.4 || ^7.0",
"symfony/dom-crawler": "^6.4 || ^7.0",
Expand Down Expand Up @@ -72,7 +73,8 @@
"config": {
"allow-plugins": {
"symfony/flex": true,
"symfony/runtime": true
"symfony/runtime": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
Expand Down
32 changes: 32 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
]);

$ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php');

$ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [
'location' => 'after_open',
'header' =>
'This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.',
])
;
$ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, ['allow_mixed' => true]);

$ecsConfig->skip([
InlineDocCommentDeclarationSniff::class . '.MissingVariable',
'**/var/*',
]);
};
9 changes: 9 additions & 0 deletions src/TwigExtra/config/services.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Symfony\DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Symfony\DependencyInjection;
Expand Down
9 changes: 9 additions & 0 deletions src/TwigExtra/src/Symfony/TwigExtraBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Symfony;
Expand Down
9 changes: 9 additions & 0 deletions src/TwigExtra/src/Twig/Extension/SortByExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Twig\Extension;
Expand Down
11 changes: 10 additions & 1 deletion src/TwigExtra/src/Twig/Ux/ComponentTemplateFinder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\TwigExtra\Twig\Ux;
Expand Down Expand Up @@ -42,6 +51,6 @@ private function getTemplatePath(string $name, string $prefixName, string $prefi

private function normalizeName(string $name, string $prefixName): string
{
return str_replace(':', '/', str_replace($prefixName, '', $name));
return str_replace(':', '/', str_replace($prefixName, '', $name));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Integration\DependencyInjection;
Expand Down Expand Up @@ -48,7 +57,7 @@ public function testItThrowsAnErrorWhenTryingToRegisterNonStringPath(): void
],
],
],
'Invalid configuration for path "sylius_twig_extra.twig_ux.anonymous_component_template_prefixes": Path must be a string. "bool" given.'
'Invalid configuration for path "sylius_twig_extra.twig_ux.anonymous_component_template_prefixes": Path must be a string. "bool" given.',
);
}

Expand Down
17 changes: 13 additions & 4 deletions src/TwigExtra/tests/Unit/Twig/Extension/SortByExtensionTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Unit\Twig\Extension;
Expand Down Expand Up @@ -122,8 +131,8 @@ public function testItSortsAnArrayOfObjectsInDescendingOrderByAProperty(): void
public function testItSortsAnArrayOfObjectsByANestedProperty(): void
{
$firstData = (object) ['data' => (object) ['number' => 3]];
$secondData = (object) ['data' => (object) ['number' => 5]];
$thirdData = (object) ['data' => (object) ['number' => 1]];
$secondData = (object) ['data' => (object) ['number' => 5]];
$thirdData = (object) ['data' => (object) ['number' => 1]];

$arrayBeforeSorting = [
$firstData,
Expand All @@ -141,8 +150,8 @@ public function testItSortsAnArrayOfObjectsByANestedProperty(): void
public function testItSortsAnArrayOfArraysByANestedProperty(): void
{
$firstData = ['data' => ['number' => 3]];
$secondData = ['data' => ['number' => 5]];
$thirdData = ['data' => ['number' => 1]];
$secondData = ['data' => ['number' => 5]];
$thirdData = ['data' => ['number' => 1]];

$arrayBeforeSorting = [
$firstData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Unit\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Unit\Twig\Extension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Unit\Twig\Ux;
Expand Down
11 changes: 11 additions & 0 deletions src/TwigHooks/config/services.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\TwigHooks\Hook\Normalizer\Name\CompositeNameNormalizer;
Expand Down
11 changes: 11 additions & 0 deletions src/TwigHooks/config/services/debug/twig_events.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\TwigHooks\Hook\Renderer\Debug\HookDebugCommentRenderer;
Expand Down
11 changes: 11 additions & 0 deletions src/TwigHooks/config/services/hook_renderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\TwigHooks\Hook\Renderer\HookRenderer;
Expand Down
Loading

0 comments on commit 790edee

Please sign in to comment.