Skip to content

Commit

Permalink
Merge pull request #6 from Ilyes512/version-2
Browse files Browse the repository at this point in the history
Version-2
  • Loading branch information
Ilyes512 authored Jul 29, 2024
2 parents e7d7984 + 40f125e commit 9ea0b25
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 446 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ COMPOSE_PROJECT_NAME=code-style
REGISTRY_HOST=ghcr.io
REGISTRY_PATH=ilyes512

IMAGE_REGISTRY_PHP=${REGISTRY_HOST}/${REGISTRY_PATH}/php83-fpm
IMAGE_REGISTRY_PHP=${REGISTRY_HOST}/${REGISTRY_PATH}/php83
IMAGE_TAG_PHP_VSCODE=vscode-1.0.0
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/.gitignore export-ignore
/.vsls.json export-ignore
/auth.json export-ignore
/ecs-local.php export-ignore
/phpstan.neon export-igore
/phpstan.dist.neon export-ignore
/Taskfile.dist.yml export-ignore
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/.phplint.cache
/auth.json
Taskfile.yml
docs.html
/temp
198 changes: 198 additions & 0 deletions Ilyes512CodingStandard/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Ilyes512CodingStandard"
xsi:noNamespaceSchemaLocation="../vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<description>ilyes512/code-style ruleset</description>

<arg value="s"/><!-- Show sniff codes in all reports -->
<arg value="p"/><!-- Show progress of the run -->
<arg name="colors"/><!-- Use colors in output -->
<arg name="extensions" value="php"/>

<!-- PSR1 START -->
<rule ref="Generic.PHP.DisallowAlternativePHPTags"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
<severity>0</severity>
</rule>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Squiz.Classes.ValidClassName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<!-- PSR1 END -->

<!-- PSR1-EXTRA START -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols"/>
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="PSR1.Methods.CamelCapsMethodName"/>
<!-- PSR1-EXTRA END -->

<!-- PSR12 START -->
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>
<rule ref="PSR2.Files.EndFileNewline"/>
<rule ref="PSR2.Files.ClosingTag"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
<severity>0</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
<severity>0</severity>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<severity>0</severity>
</rule>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="ignoreIndentationTokens" type="array">
<element value="T_COMMENT"/>
<element value="T_DOC_COMMENT_OPEN_TAG"/>
</property>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.PHP.LowerCaseType"/>
<rule ref="PSR2.Classes.ClassDeclaration"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<type>error</type>
<message>Method name "%s" must not be prefixed with an underscore to indicate visibility</message>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<rule ref="Squiz.Functions.FunctionDeclaration"/>
<rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="PSR2.Methods.FunctionCallSignature"/>
<rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
<severity>0</severity>
</rule>
<rule ref="PSR2.Methods.FunctionCallSignature.OpeningIndent">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.LowercaseDeclaration"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<!-- exclude this message as it is already checked in Generic.PHP.LowerCaseKeyword -->
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
<severity>0</severity>
</rule>
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
<rule ref="PSR2.ControlStructures.SwitchDeclaration"/>
<!-- exclude these messages as they are already checked by PSR2.ControlStructures.ControlStructureSpacing -->
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<!-- PSR12 END -->

<!-- PSR12-EXTRA START -->
<rule ref="PSR12.Keywords.ShortFormTypeKeywords"/>
<rule ref="PSR12.Files.ImportStatement"/>
<rule ref="PSR12.Files.DeclareStatement"/>
<rule ref="PSR12.Classes.ClosingBrace"/>
<rule ref="PSR12.Classes.OpeningBraceSpace"/>
<rule ref="PSR12.Traits.UseDeclaration"/>
<rule ref="PSR12.Properties.ConstantVisibility"/>
<rule ref="PSR12.Functions.ReturnTypeDeclaration"/>
<rule ref="PSR12.Functions.NullableTypeDeclaration"/>
<rule ref="PSR12.ControlStructures.ControlStructureSpacing"/>
<rule ref="PSR12.ControlStructures.BooleanOperatorPlacement"/>
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<rule ref="PSR12.Operators.OperatorSpacing"/>
<rule ref="PSR12.Functions.ReturnTypeDeclaration"/>
<rule ref="PSR12.Classes.AnonClassDeclaration"/>
<!-- PSR12-EXTRA END -->

<!-- CUSTOM STRING RULES START -->
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
<!-- CUSTOM STRING RULES END -->

<!-- CUSTOM TRAILING COMMA RULES START -->
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<!-- CUSTOM TRAILING COMMA RULES END -->

<!-- CUSTOM NAMESPACES RULES START -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="caseSensitive" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="searchAnnotations" value="true"/>
<!-- <property name="allowFallbackGlobalFunctions" value="false"/> -->
<!-- <property name="allowFallbackGlobalConstants" value="false"/> -->
<property name="allowPartialUses" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing">
<properties>
<property name="linesCountBetweenUseTypes" value="1"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<!-- CUSTOM NAMESPACES RULES END -->

<!-- CUSTOM TYPE HINTS RULES START -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>
<!-- CUSTOM TYPE HINTS RULES START -->
</ruleset>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 Ilyes Ahidar
Copyright 2024 Ilyes Ahidar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,55 @@ An ECS (Easy Coding Standards) codestyle package.
You can install the package via composer:

```bash
composer require --dev ilyes512/code-style
composer require --dev ilyes512/code-style:^2.0-dev
```

## Usage

Add a `ecs.php` file to the root of your project with the below contents.

`ecs.php`:
Add a `phpcs.xml` file to the root of your project. The below config example is for a Laravel project:

`phpcs.yml`:

```xml
<?xml version="1.0"?>
<ruleset>
<description>A Laravel project coding standard</description>

<arg name="extensions" value="php" />
<arg name="report" value="full"/>
<arg name="colors"/>
<arg value="s"/> <!-- Show sniff codes in report -->
<arg value="p"/> <!-- Show progress in report -->

<rule ref="Ilyes512CodingStandard"/>

<file>.</file>
<exclude-pattern>./vendor</exclude-pattern>
<exclude-pattern>./node_modules</exclude-pattern>
<exclude-pattern>./.phpstan.cache</exclude-pattern>
<exclude-pattern>./.phpunit.cache</exclude-pattern>
<exclude-pattern>./bootstrap/cache</exclude-pattern>
<exclude-pattern>./storage/framework</exclude-pattern>
<exclude-pattern>./resources/css</exclude-pattern>
<exclude-pattern>./resources/js</exclude-pattern>
<exclude-pattern>./coverage</exclude-pattern>
</ruleset>
```

```php
<?php
## Using the PHPCSStandards plugin

declare(strict_types=1);
The above config assumes you allowed installing the [PHP_CodeSniffer](https://github.com/PHPCSStandards/composer-installer) plugin. Composer will prompt you to install it when you install this package. If you didn't, you can allow it by adding the following to your composer.json:

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
```json
{
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
```

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/vendor/ilyes512/code-style/ecs.php');
## Annotated ruleset

$containerConfigurator
->parameters()
->set(
Option::PATHS,
[
__DIR__ . '/src',
__DIR__ . '/config',
__DIR__ . '/tests',
__DIR__ . '/ecs.php',
],
);
};
```
The [annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset).
44 changes: 17 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
{
"name": "ilyes512/code-style",
"type": "library",
"description": "An ECS (Easy Coding Standards) codestyle package.",
"type": "phpcodesniffer-standard",
"description": "An PHP_CodeSniffer codestyle package.",
"keywords": [
"package",
"easy coding standard",
"code style",
"ecs"
"phpcs",
"dev",
"code-style",
"codestyle"
],
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0",
"slevomat/coding-standard": "^8.0",
"symplify/easy-coding-standard": "^11.0"
"squizlabs/php_codesniffer": "^3.0"
},
"require-dev": {
"overtrue/phplint": "^9.0.4"
"extra": {
"branch-alias": {
"dev-main": "1.0-dev",
"dev-version-2": "2.0-dev"
}
},
"scripts": {
"lint": "XDEBUG_MODE=off phplint --exclude=vendor .",
"checkstyle": "XDEBUG_MODE=off ecs check --config=ecs-local.php",
"fixstyle": "@checkstyle --fix",
"checkall": [
"@lint",
"@checkstyle",
"composer outdated --direct",
"composer outdated --direct --minor-only --strict"
]
"docs": "phpcs --standard=PSR12 --generator=html > docs.html",
"listsniffs": "phpcs --standard=./Ilyes512CodingStandard/ruleset.xml -e"
},
"scripts-descriptions": {
"lint": "Check all php files for syntax errors.",
"checkstyle": "Report on code style violations (without fixing it).",
"fixstyle": "Fixes code style violations.",
"checkall": "Run all code checkers (lint, checkstyle, outdated, ...)."
},
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
}
"docs": "Generate the PSR12 documentation",
"listsniffs": "List all sniffs used by Ilyes512CodingStandard"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
17 changes: 0 additions & 17 deletions ecs-local.php

This file was deleted.

Loading

0 comments on commit 9ea0b25

Please sign in to comment.