Easy Coding Standard configurations for Craft CMS projects.

Related tags

Miscellaneous ecs
Overview

Easy Coding Standard config for Craft CMs

This package provides Easy Coding Standard configurations for Craft CMS plugins and projects.

In general, we follow the PSR-12 coding style guide, with a couple alterations:

  • Multi-line function argument rules aren’t enforced. (¶4.4)
  • Spaces after the function keyword aren’t enforced. (¶7)
  • Visibility is not enforced for constants, for Craft 3 projects.

To install, run the following commands within your plugin or project:

composer config minimum-stability dev
composer config prefer-stable true
composer require craftcms/ecs:dev-main --dev

Then add an ecs.php file to the root of your plugin or project:

<?php

declare(strict_types=1);

use craft\ecs\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::PARALLEL, true);
    $parameters->set(Option::PATHS, [
        __DIR__ . '/src',
        __FILE__,
    ]);

    $containerConfigurator->import(SetList::CRAFT_CMS_3); // for Craft 3 projects
    $containerConfigurator->import(SetList::CRAFT_CMS_4); // for Craft 4 projects
};

Adjust the PATHS value to include all source/test code locations, and remove the appropriate SetList option, depending on whether this is for Craft 3 or Craft 4.

With that in place, you can check your plugin/project’s code with the following command:

vendor/bin/ecs check

And to automatically fix it as well, pass the --fix argument:

vendor/bin/ecs check --fix

You might also want to define check-cs and fix-cs scripts in composer.json:

{
  "...": "...",
  "scripts": {
    "check-cs": "ecs check --ansi",
    "fix-cs": "ecs check --ansi --fix"
  }
}

Then you could execute ECS using composer run-script:

composer run-script check-cs
composer run-script fix-cs
You might also like...
This shell script and PHP file create a browseable HTML site from the Zig standard library source.
This shell script and PHP file create a browseable HTML site from the Zig standard library source.

Browseable Zig standard library This shell script and PHP file create a browseable HTML site from the Zig standard library source. The idea is to inve

Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions.

PHPCheckstyle Overview PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the inpu

Igbinary is a drop in replacement for the standard php serializer.

igbinary Igbinary is a drop in replacement for the standard php serializer. Instead of the time and space consuming textual representation used by PHP

A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.
A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.

select2entity-bundle Introduction This is a Symfony bundle which enables the popular Select2 component to be used as a drop-in replacement for a stand

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol

log2ck This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol. If you can write regular rules, other st

Pattern Lab Standard Edition for Twig

Pattern Lab Standard Edition for Twig The Standard Edition for Twig gives developers and designers a clean and stable base from which to develop a Twi

Automate aggregation tools to standard alerts from SAP PI/PO (CBMA) for internal support team
Automate aggregation tools to standard alerts from SAP PI/PO (CBMA) for internal support team

✅ PiAlert PiAlert is system for automating the work of SAP PI/PO support team via aggregation of alerts (CBMA messages). Language support: English Рус

Comments
  • Update to use new config format

    Update to use new config format

    Description

    ECS has been updated to use a new config format: https://tomasvotruba.com/blog/new-in-ecs-simpler-config/

    This PR updates the dependencies and code to adhere to the changes.

    opened by nfourtythree 0
Owner
Craft CMS
A content-first CMS that aims to make life enjoyable for developers and content managers alike.
Craft CMS
WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

Awesome Motive, Inc. 7 Nov 29, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
Magento 1.x Coding Standard

Magento Extension Quality Program Coding Standard ⚠️ Versions 3.0.0 and above of the MEQP Coding Standard are for Magento 1.x code only. To check Mage

Magento 224 Nov 29, 2022
Magento Coding Standard

Magento Coding Standard A set of Magento rules for PHP_CodeSniffer tool. Installation within a Magento 2 site To use within your Magento 2 project you

Magento 290 Dec 31, 2022
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
Utility that helps you switch git configurations with ease.

git-profile Utility that helps you switch git configurations with ease Preface It is possible that you have multiple git configurations. For example:

Zeeshan Ahmad 240 Jul 18, 2022
This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project

psr-container-doctrine: Doctrine Factories for PSR-11 Containers Doctrine factories for PSR-11 containers. This package provides a set of factories to

Roave, LLC 84 Dec 14, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023