diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..e320afd53 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,63 @@ +on: [push, pull_request] + +name: Lint + +jobs: + php-cs-fixer: + name: PHP-CS-Fixer + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - name: "Run PHP-CS-Fixer" + uses: docker://oskarstark/php-cs-fixer-ga:2.16.1 + with: + args: --ansi --verbose --diff --dry-run + + composer-normalize: + name: composer-normalize + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - name: "Run composer-normalize" + uses: docker://localheinz/composer-normalize-action:0.5.2 + with: + args: --dry-run + + yaml-files: + name: YAML files + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - name: "Install Ruby 2.6" + uses: actions/setup-ruby@v1 + with: + ruby-version: '2.6' + - run: gem install yaml-lint + - name: "Linting..." + run: make lint-yaml + + xml-files: + name: XML files + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - run: sudo apt-get install libxml2-utils + + - name: "Linting..." + run: make lint-xml diff --git a/.php_cs.dist b/.php_cs.dist index 063efb18c..dd93021ca 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -26,6 +26,7 @@ $rules = [ 'header_comment' => [ 'header' => $header, ], + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'no_extra_blank_lines' => true, 'no_php4_constructor' => true, 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], diff --git a/.travis.yml b/.travis.yml index f3c804488..ff5b6a65a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,11 +17,6 @@ php: dist: xenial -addons: - apt: - packages: - - libxml2-utils - cache: pip: true directories: @@ -38,8 +33,6 @@ env: matrix: fast_finish: true include: - - php: '7.3' - env: TARGET=lint - php: '7.2' env: COMPOSER_FLAGS="--prefer-lowest" - php: '7.3' diff --git a/.travis/check_relevant_lint.sh b/.travis/check_relevant_lint.sh deleted file mode 100755 index 317cfeccf..000000000 --- a/.travis/check_relevant_lint.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -ev - -RELEVANT_FILES=$(git diff --name-only HEAD upstream/${TRAVIS_BRANCH} -- '*.json' '*.yml' '*.xml' '*.xliff' '*.php') - -if [[ -z ${RELEVANT_FILES} ]]; then echo -n 'KO'; exit 0; fi; diff --git a/.travis/install_lint.sh b/.travis/install_lint.sh deleted file mode 100755 index 864c751ee..000000000 --- a/.travis/install_lint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env sh -set -ev - -mkdir --parents "${HOME}/bin" - -wget "http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar" --output-document="${HOME}/bin/php-cs-fixer" -chmod u+x "${HOME}/bin/php-cs-fixer" - -composer global require sllh/composer-lint:@stable --prefer-dist --no-interaction - -gem install yaml-lint diff --git a/Makefile b/Makefile index 80bf9629e..3e7fd990e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: @echo "Please choose a task." .PHONY: all -lint: lint-composer lint-yaml lint-composer lint-xml lint-php +lint: lint-composer lint-yaml lint-xml lint-php .PHONY: lint lint-composer: diff --git a/src/Component/Generator/PostgresReference.php b/src/Component/Generator/PostgresReference.php index 363cff367..532490f37 100644 --- a/src/Component/Generator/PostgresReference.php +++ b/src/Component/Generator/PostgresReference.php @@ -35,8 +35,10 @@ public function invoice(InvoiceInterface $invoice): void throw new \RuntimeException('The invoice is not persisted into the database'); } - $this->generateReference($invoice, - $this->registry->getManager()->getClassMetadata(\get_class($invoice))->table['name']); + $this->generateReference( + $invoice, + $this->registry->getManager()->getClassMetadata(\get_class($invoice))->table['name'] + ); } public function order(OrderInterface $order): void @@ -45,8 +47,10 @@ public function order(OrderInterface $order): void throw new \RuntimeException('The order is not persisted into the database'); } - $this->generateReference($order, - $this->registry->getManager()->getClassMetadata(\get_class($order))->table['name']); + $this->generateReference( + $order, + $this->registry->getManager()->getClassMetadata(\get_class($order))->table['name'] + ); } /** @@ -75,7 +79,8 @@ private function generateReference($object, $tableName) $statement = $this->registry->getConnection()->query($sql); $row = $statement->fetch(); - $reference = sprintf('%02d%02d%02d%06d', + $reference = sprintf( + '%02d%02d%02d%06d', $date->format('y'), $date->format('n'), $date->format('j'), diff --git a/src/Component/Payment/Scellius/ScelliusPayment.php b/src/Component/Payment/Scellius/ScelliusPayment.php index 8da08bf35..7cbeafb51 100644 --- a/src/Component/Payment/Scellius/ScelliusPayment.php +++ b/src/Component/Payment/Scellius/ScelliusPayment.php @@ -521,7 +521,8 @@ public function applyTransactionId(TransactionInterface $transaction): void */ private function getResponseData(TransactionInterface $transaction) { - $cmd = sprintf('cd %s && %s pathfile=%s message=%s ', + $cmd = sprintf( + 'cd %s && %s pathfile=%s message=%s ', $this->getOption('base_folder'), $this->getOption('response_command'), $this->getOption('pathfile'), diff --git a/src/CustomerBundle/Twig/Extension/AddressExtension.php b/src/CustomerBundle/Twig/Extension/AddressExtension.php index ba5a1ffc4..b9003ea5c 100644 --- a/src/CustomerBundle/Twig/Extension/AddressExtension.php +++ b/src/CustomerBundle/Twig/Extension/AddressExtension.php @@ -99,7 +99,9 @@ public function renderAddress(\Twig_Environment $environment, $address, $showNam ]; } - return $environment->render('@SonataCustomer/Addresses/_address.html.twig', [ + return $environment->render( + '@SonataCustomer/Addresses/_address.html.twig', + [ 'address' => $addressArray, 'showName' => $showName, 'showEdit' => $showEdit, diff --git a/src/ProductBundle/Admin/ProductVariationAdmin.php b/src/ProductBundle/Admin/ProductVariationAdmin.php index c929388a8..00d6c3d5b 100644 --- a/src/ProductBundle/Admin/ProductVariationAdmin.php +++ b/src/ProductBundle/Admin/ProductVariationAdmin.php @@ -33,7 +33,8 @@ public function getBaseRoutePattern() if ('sonata.product.admin.product.variation' === $this->getCode() && !$this->isChild()) { // variation $this->baseRoutePattern = '/sonata/product/variation'; } elseif ('sonata.product.admin.product.variation' === $this->getCode() && $this->isChild()) { // variation - $this->baseRoutePattern = sprintf('%s/{id}/%s', + $this->baseRoutePattern = sprintf( + '%s/{id}/%s', $this->getParent()->getBaseRoutePattern(), $this->urlize('variation', '-') ); @@ -56,7 +57,8 @@ public function getBaseRouteName() if ('sonata.product.admin.product.variation' === $this->getCode() && !$this->isChild()) { // variation $this->baseRouteName = 'admin_sonata_product_variation'; } elseif ('sonata.product.admin.product.variation' === $this->getCode() && $this->isChild()) { // variation - $this->baseRouteName = sprintf('%s_%s', + $this->baseRouteName = sprintf( + '%s_%s', $this->getParent()->getBaseRouteName(), $this->urlize('variation') ); diff --git a/src/ProductBundle/Command/GenerateProductCommand.php b/src/ProductBundle/Command/GenerateProductCommand.php index 29885b77f..cfd00dd2e 100644 --- a/src/ProductBundle/Command/GenerateProductCommand.php +++ b/src/ProductBundle/Command/GenerateProductCommand.php @@ -55,8 +55,9 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): void { // find a better way to detect the Application folder - $bundle_dir = sprintf('%s/src/Sonata/ProductBundle', - $this->kernel->getProjectDir() + $bundle_dir = sprintf( + '%s/src/Sonata/ProductBundle', + $this->kernel->getProjectDir() ); if (!is_dir($bundle_dir)) { @@ -137,7 +138,8 @@ protected function execute(InputInterface $input, OutputInterface $output): void $service = $input->getArgument('service_id'); - $output->write(Mustache::renderString(<<write(Mustache::renderString( + <<1. Add this service definition @@ -176,7 +178,8 @@ class: App\Sonata\ProductBundle\Provider\{{ product }}ProductProvider CONFIG - , ['service' => $service, 'product' => $product] + , + ['service' => $service, 'product' => $product] )); } } diff --git a/src/ProductBundle/Controller/CollectionController.php b/src/ProductBundle/Controller/CollectionController.php index 58c96f1c4..4404299ca 100644 --- a/src/ProductBundle/Controller/CollectionController.php +++ b/src/ProductBundle/Controller/CollectionController.php @@ -45,11 +45,11 @@ class CollectionController extends Controller private $productSetManager; public function __construct( - SeoPage $sonataSeoPage = null, - CurrencyDetectorInterface $currencyDetector = null, - CollectionManagerInterface $collectionManagerInterface = null, - ProductSetManager $productSetManager = null - ) { + SeoPage $sonataSeoPage = null, + CurrencyDetectorInterface $currencyDetector = null, + CollectionManagerInterface $collectionManagerInterface = null, + ProductSetManager $productSetManager = null + ) { $this->sonataSeoPage = $sonataSeoPage; $this->currencyDetector = $currencyDetector; $this->collectionManagerInterface = $collectionManagerInterface; diff --git a/src/ProductBundle/Controller/ProductController.php b/src/ProductBundle/Controller/ProductController.php index 30f7e587c..51e4c5e2d 100644 --- a/src/ProductBundle/Controller/ProductController.php +++ b/src/ProductBundle/Controller/ProductController.php @@ -62,7 +62,8 @@ public function viewAction($productId, $slug) ]); if ($this->get('kernel')->isDebug()) { - $response->setContent(sprintf("\n\n%s\n\n", + $response->setContent(sprintf( + "\n\n%s\n\n", $this->get('sonata.product.pool')->getProductCode($product), $product->getId(), $action, @@ -87,7 +88,8 @@ public function renderFormBasketElementAction(FormView $formView, BasketElementI ]); if ($this->get('kernel')->isDebug()) { - $response->setContent(sprintf("\n\n%s\n\n", + $response->setContent(sprintf( + "\n\n%s\n\n", $basketElement->getProductCode(), $basketElement->getProductId(), $action, @@ -159,7 +161,8 @@ public function renderFinalReviewBasketElementAction(BasketElementInterface $bas ]); if ($this->get('kernel')->isDebug()) { - $response->setContent(sprintf("\n\n%s\n\n", + $response->setContent(sprintf( + "\n\n%s\n\n", $basketElement->getProductCode(), $basketElement->getProductId(), $action, @@ -194,7 +197,8 @@ public function viewVariationsAction($productId, $slug) ]); if ($this->get('kernel')->isDebug()) { - $response->setContent(sprintf("\n\n%s\n\n", + $response->setContent(sprintf( + "\n\n%s\n\n", $this->get('sonata.product.pool')->getProductCode($product), $product->getId(), $action, @@ -262,7 +266,8 @@ public function variationToProductAction(Request $request, $productId, $slug) ]); if ($this->get('kernel')->isDebug() && !($response instanceof JsonResponse)) { - $response->setContent(sprintf("\n\n%s\n\n", + $response->setContent(sprintf( + "\n\n%s\n\n", $this->get('sonata.product.pool')->getProductCode($product), $product->getId(), $action, diff --git a/src/ProductBundle/Entity/BaseDelivery.php b/src/ProductBundle/Entity/BaseDelivery.php index ae3779668..c97fa47cb 100644 --- a/src/ProductBundle/Entity/BaseDelivery.php +++ b/src/ProductBundle/Entity/BaseDelivery.php @@ -64,7 +64,8 @@ abstract class BaseDelivery implements DeliveryInterface */ public function __toString() { - return sprintf('%s-%s%s', + return sprintf( + '%s-%s%s', $this->getCode(), $this->getCountryCode(), $this->getZone() ? sprintf('%s', $this->getZone()) : '' diff --git a/src/ProductBundle/Model/BaseProductProvider.php b/src/ProductBundle/Model/BaseProductProvider.php index 6b4f1a32f..a82e46b0c 100644 --- a/src/ProductBundle/Model/BaseProductProvider.php +++ b/src/ProductBundle/Model/BaseProductProvider.php @@ -736,7 +736,7 @@ public function defineAddBasketForm(ProductInterface $product, FormBuilder $form } else { $transformer = new QuantityTransformer(); $formBuilder->add( - $formBuilder->create('quantity', HiddenType::class, ['data' => 1]) + $formBuilder->create('quantity', HiddenType::class, ['data' => 1]) ->addModelTransformer($transformer) ); } diff --git a/tests/ProductBundle/Controller/CollectionControllerTest.php b/tests/ProductBundle/Controller/CollectionControllerTest.php index 1ab043ce8..b40a090d1 100644 --- a/tests/ProductBundle/Controller/CollectionControllerTest.php +++ b/tests/ProductBundle/Controller/CollectionControllerTest.php @@ -228,7 +228,7 @@ public function createCollectionController( ?CurrencyDetectorInterface $currencyDetector = null, ?CollectionManagerInterface $collectionManagerInterface = null, ?ProductSetManager $productSetManager = null - ): CollectionController { + ): CollectionController { if (!$sonataSeoPage) { $sonataSeoPage = new SeoPage('Collection page'); }