trayto-com/php-coding-standards

Common coding-standard utils, tools and rules used across our PHP projects in trayto.com

v0.1.0 2020-09-29 12:33 UTC

This package is auto-updated.

Last update: 2024-04-29 04:28:12 UTC


README

Common coding-standard utils, tools and rules used across our PHP projects in trayto.com

symplify/easy-coding-standard (ECS) is used under the hood. Follow configuration instructions there. Phar version is used so there should be no conflicts with projects dependencies.

Parallel Lint is available as well.

Further reading:

Installation instructions

composer require --dev trayto-com/php-coding-standards

Usage

You can use ECS directly in CLI but we do recommend to customise default rules:

vendor/bin/ecs check src tests --config vendor/trayto-com/php-coding-standards/definitions/ecs-default.php

Run PHP Parallel Lint:

vendor/bin/parallel-lint --exclude temp --exclude vendor .

Hint: do run linter before any other Standards check or Tests to fail fast in case of typo in your code

Customise ECS rules and custom usage

Recommended is to create your own configuration for project and define cache folder for EasyCodingStandard as well.

Create php file in your project root, for example ecs.php:

<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $configurator): void {
    // make sure you import correct file
	$configurator->import(__DIR__ . '/vendor/trayto-com/php-coding-standards/definitions/ecs-default.php');

	$services = $configurator->services();
	// ... customise your services

	$parameters = $configurator->parameters();
	// .. customise your parameters

	$parameters->set(
		Option::CACHE_DIRECTORY,
		__DIR__ . '/temp/ecs'
	);
};