Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CodelyTV/php-coding_style-codely
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.9.0
Choose a base ref
...
head repository: CodelyTV/php-coding_style-codely
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 11 commits
  • 9 files changed
  • 1 contributor

Commits on Oct 23, 2023

  1. feat: improve config

    rgomezcasas committed Oct 23, 2023

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    c96ae9b View commit details
  2. ci: add github workflow

    rgomezcasas committed Oct 23, 2023

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    6aa1ff9 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    499e330 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    fabc639 View commit details
  5. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2d350ba View commit details
  6. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    34e9050 View commit details
  7. feat: simplify api

    rgomezcasas committed Oct 23, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    9178d43 View commit details
  8. feat: indent arrays

    rgomezcasas committed Oct 23, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    2e00fde View commit details

Commits on Oct 24, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    7e6fde0 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    ffd9d00 View commit details

Commits on Aug 5, 2024

  1. feat: add spaces between union types

    rgomezcasas committed Aug 5, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    rgomezcasas Rafa Gómez
    Copy the full SHA
    41d7e6b View commit details
Showing with 231 additions and 73 deletions.
  1. +1 −0 .github/FUNDING.yml
  2. +33 −0 .github/workflows/ci.yml
  3. +74 −0 README.md
  4. +8 −1 composer.json
  5. +12 −0 ecs.php
  6. +0 −8 src/CodelyRules.php
  7. +11 −0 src/CodingStyle.php
  8. +71 −64 src/coding_style.php
  9. +21 −0 src/coding_style_aligned.php
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: https://bit.ly/CodelyTvPro
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2']

name: PHP ${{ matrix.php-versions }}

steps:
- uses: actions/checkout@v4

- name: 🐘 Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2

- name: ⬇️ Install dependencies
run: composer install

- name: 🏮 Lint
run: ./vendor/bin/ecs check
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<p align="center">
<a href="https://codely.com">
<img src="https://user-images.githubusercontent.com/10558907/170513882-a09eee57-7765-4ca4-b2dd-3c2e061fdad0.png" width="300px" height="92px"/>
</a>
</p>

<h1 align="center">
✍️ Codely's Easy Coding Standards configuration
</h1>

<p align="center">
<a href="https://github.com/CodelyTV"><img src="https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square" alt="Codely Open Source"/></a>
<a href="https://pro.codely.com"><img src="https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square" alt="CodelyTV Courses"/></a>
</p>

<p align="center">
Opinionated linting configuration considering modern PHP best practices and providing consistency. 👌
<br />
<br />
Take a look, play and have fun with this.
<a href="https://github.com/CodelyTV/php-coding_style-codely/stargazers">Stars are welcome 😊</a>
</p>

## 👀 How to use

1. Install the dependency
```sh
composer require --dev codelytv/coding-style
```
2. Add it to your `ecs.php` file:
```php
use CodelyTv\CodingStyle;
use Symplify\EasyCodingStandard\Config\ECSConfig;
return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([__DIR__ . '/src',]);
$ecsConfig->sets([CodingStyle::DEFAULT]);
// Or this if you prefer to have the code aligned
// $ecsConfig->sets([CodingStyle::ALIGNED]);
};
```
3. Execute it:
```sh
./vendor/bin/ecs check
```
## 🤔 What it does
- Lints PHP using PSR-12
- Extends some config (you can see all the rules [here](src/coding_style.php))
- Use tabs to indent ([reason](https://www.youtube.com/watch?v=yD2T42zsP7c)). If you want to use spaces, you can add the
following line at the end of your `ecs.php`:
```php
use Symplify\EasyCodingStandard\ValueObject\Option;
$ecsConfig->indentation(Option::INDENTATION_SPACES);
```
## 📦 How to release a new version
Simply create a new [GitHub Release](https://github.com/CodelyTV/php-coding_style-codely/releases/new) following
semantic versioning.
## 👌 Codely Code Quality Standards
Publishing this package we are committing ourselves to the following code quality standards:
- 🤝 Respect **Semantic Versioning**: No breaking changes in patch or minor versions
- 🤏 No surprises in transitive dependencies: Use the **bare minimum dependencies** needed to meet the purpose
- 🎯 **One specific purpose** to meet without having to carry a bunch of unnecessary other utilities
- 📖 **Well documented Readme** showing how to install and use
- ⚖️ **License favoring Open Source** and collaboration
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -3,9 +3,16 @@
"description": "PHP Coding Style rules we use in Codely",
"type": "library",
"keywords": ["static analysis", "code style"],
"license": "AGPL-3.0-or-later",
"authors": [
{
"name": "Codely",
"homepage": "https://codely.com"
}
],
"autoload": {
"psr-4": {
"Codelytv\\CodingStyle\\": "src/"
"CodelyTv\\": "src/"
}
},
"require": {
12 changes: 12 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use CodelyTv\CodingStyle;
use Symplify\EasyCodingStandard\Config\ECSConfig;

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

$ecsConfig->sets([CodingStyle::DEFAULT]);
};
8 changes: 0 additions & 8 deletions src/CodelyRules.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/CodingStyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace CodelyTv;

final class CodingStyle
{
public const DEFAULT = __DIR__ . '/coding_style.php';
public const ALIGNED = __DIR__ . '/coding_style_aligned.php';
}
135 changes: 71 additions & 64 deletions src/coding_style.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer;
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
@@ -10,7 +12,6 @@
use PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ClassNotation\FinalClassFixer;
use PhpCsFixer\Fixer\ClassNotation\FinalPublicMethodForAbstractClassFixer;
use PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer;
use PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer;
use PhpCsFixer\Fixer\ClassNotation\NoUnneededFinalMethodFixer;
@@ -44,78 +45,84 @@
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer;
use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([SetList::PSR_12]);

return static function (ECSConfig $ecsConfig) : void {
$ecsConfig->sets([SetList::PSR_12]);
$ecsConfig->rules([
// Imports
NoUnusedImportsFixer::class,
FullyQualifiedStrictTypesFixer::class,
GlobalNamespaceImportFixer::class,
NoLeadingImportSlashFixer::class,
// Arrays
TrimArraySpacesFixer::class,
ArrayIndentationFixer::class,
// Blank lines
BlankLineAfterStrictTypesFixer::class,
NoBlankLinesAfterClassOpeningFixer::class,
// Spacing
SingleLineEmptyBodyFixer::class,
CastSpacesFixer::class,
TypeDeclarationSpacesFixer::class,
// Casing
ClassReferenceNameCasingFixer::class,
LowercaseStaticReferenceFixer::class,
MagicMethodCasingFixer::class,
NativeFunctionCasingFixer::class,
NativeFunctionTypeDeclarationCasingFixer::class,
// Architecture
FinalClassFixer::class,
ProtectedToPrivateFixer::class,
VisibilityRequiredFixer::class,
DateTimeImmutableFixer::class,
NoUselessElseFixer::class,
// Operator
AssignNullCoalescingToCoalesceEqualFixer::class,
NoUselessConcatOperatorFixer::class,
NoUselessNullsafeOperatorFixer::class,
ObjectOperatorWithoutWhitespaceFixer::class,
TernaryToElvisOperatorFixer::class,
TernaryToNullCoalescingFixer::class,
// Testing
PhpUnitConstructFixer::class,
PhpUnitDedicateAssertFixer::class,
PhpUnitDedicateAssertInternalTypeFixer::class,
PhpUnitExpectationFixer::class,
// Other
LineLengthFixer::class,
NoNullPropertyInitializationFixer::class,
NoUnneededFinalMethodFixer::class,
SelfAccessorFixer::class,
SelfStaticAccessorFixer::class,
NoUnneededControlParenthesesFixer::class,
NoUnneededCurlyBracesFixer::class,
SimplifiedIfReturnFixer::class,
TrailingCommaInMultilineFixer::class,
DeclareStrictTypesFixer::class,
StrictComparisonFixer::class,
SingleQuoteFixer::class,
StatementIndentationFixer::class,
]);

$ecsConfig->rules([
// Imports
NoUnusedImportsFixer::class,
FullyQualifiedStrictTypesFixer::class,
GlobalNamespaceImportFixer::class,
NoLeadingImportSlashFixer::class,
// Arrays
TrimArraySpacesFixer::class,
// Blank lines
BlankLineAfterStrictTypesFixer::class,
NoBlankLinesAfterClassOpeningFixer::class,
// Spacing
SingleLineEmptyBodyFixer::class,
CastSpacesFixer::class,
TypeDeclarationSpacesFixer::class,
TypesSpacesFixer::class,
// Casing
ClassReferenceNameCasingFixer::class,
LowercaseStaticReferenceFixer::class,
MagicMethodCasingFixer::class,
NativeFunctionCasingFixer::class,
NativeFunctionTypeDeclarationCasingFixer::class,
// Architecture
FinalClassFixer::class,
FinalPublicMethodForAbstractClassFixer::class,
ProtectedToPrivateFixer::class,
VisibilityRequiredFixer::class,
DateTimeImmutableFixer::class,
NoUselessElseFixer::class,
// Operator
AssignNullCoalescingToCoalesceEqualFixer::class,
NoUselessConcatOperatorFixer::class,
NoUselessNullsafeOperatorFixer::class,
ObjectOperatorWithoutWhitespaceFixer::class,
TernaryToElvisOperatorFixer::class,
TernaryToNullCoalescingFixer::class,
// Testing
PhpUnitConstructFixer::class,
PhpUnitDedicateAssertFixer::class,
PhpUnitDedicateAssertInternalTypeFixer::class,
PhpUnitExpectationFixer::class,
// Other
LineLengthFixer::class,
NoNullPropertyInitializationFixer::class,
NoUnneededFinalMethodFixer::class,
SelfAccessorFixer::class,
SelfStaticAccessorFixer::class,
NoUnneededControlParenthesesFixer::class,
NoUnneededCurlyBracesFixer::class,
SimplifiedIfReturnFixer::class,
TrailingCommaInMultilineFixer::class,
DeclareStrictTypesFixer::class,
StrictComparisonFixer::class,
SingleQuoteFixer::class,
StatementIndentationFixer::class,
]);
$ecsConfig->ruleWithConfiguration(TypesSpacesFixer::class, ['space' => 'single', 'space_multiple_catch' => 'single']);
$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, ['syntax' => 'short']);
$ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [LineLengthFixer::LINE_LENGTH => 120]);
$ecsConfig->ruleWithConfiguration(
YodaStyleFixer::class,
['equal' => false, 'identical' => false, 'less_and_greater' => false]
);
$ecsConfig->ruleWithConfiguration(PhpUnitMethodCasingFixer::class, ['case' => PhpUnitMethodCasingFixer::SNAKE_CASE]);
$ecsConfig->ruleWithConfiguration(OrderedTypesFixer::class, ['null_adjustment' => 'always_last']);

$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, ['syntax' => 'short']);
$ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [LineLengthFixer::LINE_LENGTH => 120]);
$ecsConfig->ruleWithConfiguration(YodaStyleFixer::class, ['equal' => false, 'identical' => false, 'less_and_greater' => false]);
$ecsConfig->ruleWithConfiguration(PhpUnitMethodCasingFixer::class, ['case' => PhpUnitMethodCasingFixer::SNAKE_CASE]);
$ecsConfig->ruleWithConfiguration(OrderedTypesFixer::class, ['null_adjustment' => 'always_last']);
$ecsConfig->indentation(Option::INDENTATION_TAB);
};
21 changes: 21 additions & 0 deletions src/coding_style_aligned.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->ruleWithConfiguration(
BinaryOperatorSpacesFixer::class,
[
'operators' =>
[
'=' => 'align',
'=>' => 'align',
],
]
);

$ecsConfig->sets([__DIR__ . '/coding_style.php']);
};