Skip to content

Commit

Permalink
copy
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 14, 2024
1 parent 8e5880c commit b68824a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
id: 111
title: "How to Migrate From PHP_CodeSniffer to ECS in 7 Steps"
perex: |
Last year, I helped [Shopsys Coding Standards](https://github.com/shopsys/coding-standards) and [LMC PHP Coding Standard](https://github.com/lmc-eu/php-coding-standard) to migrate from PHP_CodeSniffer to ECS.
Last year, I helped [Shopsys CS](https://github.com/shopsys/coding-standards) and [LMC CS](https://github.com/lmc-eu/php-coding-standard) to migrate from PHP_CodeSniffer to ECS.
There are a few simple A → B changes, but one has to know about them or will get stuck.
There are **a few simple A → B changes**, but one has to know about them or will get stuck.
**Do you also use PHP_CodeSniffer and give it EasyCodingStandard a try**? Today we look at how to migrate step by step.
Do you also use PHP_CodeSniffer and give it ECS a try? Today we look at how to migrate step by step.
updated_since: "January 2023"
updated_message: |
Updated with ECS 12 and `ECSConfig::configure()` simple way to work with configs.
---

ECS is a tool build on Symfony components that [combines PHP_CodeSniffer and PHP CS Fixer](/blog/2017/05/03/combine-power-of-php-code-sniffer-and-php-cs-fixer-in-3-lines/). It's easy to use from scratch:
ECS is a PHP CLI tool that [combines PHP_CodeSniffer and PHP CS Fixer](/blog/2017/05/03/combine-power-of-php-code-sniffer-and-php-cs-fixer-in-3-lines/). It's easy to use from scratch:

```bash
composer require symplify/easy-coding-standard --dev
```

ECS uses simple config:
ECS uses simple PHP config format:

```php
// ecs.php
Expand All @@ -38,7 +36,9 @@ And runs as CLI command:
vendor/bin/ecs
```

But what if you already have PHP_CodeSniffer on your project and want to switch?
<br>

Do you already have PHP_CodeSniffer on your project and want to switch? Let's jump right into it:

## 1. From String Codes to Autocompleted Classes

Expand Down Expand Up @@ -98,7 +98,7 @@ use PHP_CodeSniffer\Standards\Squiz\Sniffs\Strings\DoubleQuoteUsageSniff;
return ECSConfig::configure()
->withSkip([
DoubleQuoteUsageSniff::class => [
__DIR__ . '/packages/framework/src/Component/Constraints/EmailValidator.php',
__DIR__ . '/src/Component/Constraints/EmailValidator.php',

// or whole directory
__DIR__ . '/packages/framework/src/Component',
Expand Down Expand Up @@ -178,14 +178,16 @@ return ECSConfig::configure()

These names are looked for in the root directory by PHP_CodeSniffer:

```bash
- .phpcs.xml
- phpcs.xml
- .phpcs.xml.dist
- phpcs.xml.dist
```
- `.phpcs.xml`
- `phpcs.xml`
- `.phpcs.xml.dist`
- `phpcs.xml.dist`

<br>

**And by ECS just plain `ecs.php` PHP file**
**In ECS we use single `ecs.php` file**

<br>

What about non-default locations or names?

Expand Down
4 changes: 4 additions & 0 deletions resources/views/layout/layout_base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/yaml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/diff.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/xml.min.js"></script>

<script>
document.addEventListener('DOMContentLoaded', (event) => {
Expand All @@ -62,6 +63,9 @@
document.querySelectorAll('pre code.language-diff').forEach((block) => {
hljs.highlightBlock(block);
});
document.querySelectorAll('pre code.language-xml').forEach((block) => {
hljs.highlightBlock(block);
});
});
</script>
</head>
Expand Down

0 comments on commit b68824a

Please sign in to comment.