From 51dc1c7885b9e3f6a6fbac672e8ea470b3b7cdd7 Mon Sep 17 00:00:00 2001 From: Ilyes512 Date: Thu, 25 Mar 2021 13:23:41 +0100 Subject: [PATCH] Initial commit --- .devcontainer/Dockerfile | 23 ++++ .devcontainer/devcontainer.json | 23 ++++ .devcontainer/docker-compose.yml | 18 +++ .editorconfig | 18 +++ .env | 1 + .gitattributes | 17 +++ .gitignore | 7 ++ .vsls.json | 4 + LICENSE | 21 ++++ README.md | 69 +++++++++++ Taskfile.yml | 79 ++++++++++++ composer.json | 37 ++++++ ecs.php | 17 +++ signet-ecs.php | 204 +++++++++++++++++++++++++++++++ 14 files changed, 538 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .editorconfig create mode 100644 .env create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .vsls.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Taskfile.yml create mode 100644 composer.json create mode 100644 ecs.php create mode 100644 signet-ecs.php diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..ab854cf --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,23 @@ +ARG IMAGE_TAG_PHP_VSCODE=vscode-latest +FROM ilyes512/php80-fpm:$IMAGE_TAG_PHP_VSCODE + +ARG USERNAME=code +ARG USER_UID=1000 +ARG USER_GID=$USER_UID +ARG WORKSPACE_PATH=/workspace + +RUN groupadd --gid "$USER_GID" "$USERNAME" \ + && useradd --uid "$USER_UID" --gid "$USER_GID" --create-home "$USERNAME" \ + && mkdir -p \ + "$WORKSPACE_PATH" \ + "/home/$USERNAME/.vscode-server/extensions" \ + && chown -R "$USER_UID":"$USER_GID" \ + "$WORKSPACE_PATH" \ + "/home/$USERNAME/.vscode-server" \ + && echo "$USERNAME" ALL=\(root\) NOPASSWD:ALL > "/etc/sudoers.d/$USERNAME" \ + && chmod 0440 "/etc/sudoers.d/$USERNAME" + +USER $USERNAME +WORKDIR $WORKSPACE_PATH + +CMD ["docker-cmd.sh"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..880a426 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +{ + "name": "ECS Signet", + "remoteUser": "code", + "dockerComposeFile": ["docker-compose.yml"], + "service": "php", + "workspaceFolder": "/workspace", + "settings": { + "terminal.integrated.shell.linux": "bash", + "dotfiles.repository": "signet-connectivity/dotfiles", + "dotfiles.targetPath": "~/dotfiles", + "dotfiles.installCommand": "~/dotfiles/install.sh" + }, + // "shutdownAction": "none", + "extensions": [ + "bmewburn.vscode-intelephense-client", + "redhat.vscode-yaml", + "esbenp.prettier-vscode", + "mehedidracula.php-namespace-resolver", + "editorconfig.editorconfig", + "mhutchie.git-graph", + "ms-vsliveshare.vsliveshare" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..e8f2d3f --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + php: + image: signet/ecs/php/vscode:latest + entrypoint: ["sh", "-c", "trap : 15 ; sleep 9999d & wait"] + build: + context: ../. + dockerfile: .devcontainer/Dockerfile + args: + IMAGE_TAG_PHP_VSCODE: ${IMAGE_TAG_PHP_VSCODE:-vscode-latest} + volumes: + - $HOME/.ssh/known_hosts:/home/code/.ssh/known_hosts:ro + # - $HOME/auth.json:/root/auth.json:ro + - ../.:/workspace:delegated + - vscode-extensions:/home/code/.vscode-server/extensions + +volumes: + vscode-extensions: diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..46d48db --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 + +[*.j2] +insert_final_newline = false diff --git a/.env b/.env new file mode 100644 index 0000000..9563b7a --- /dev/null +++ b/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=ecs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a065f72 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.gitlab-ci.yml export-ignore +/ecs.php export-ignore +/Taskfile.yml export-ignore +/.env export-ignore +/docs export-ignore +/.vscode export-ignore +/.devcontainer export-ignore +/.vsls.json export-ignore +/.dockerignore export-ignore +/auth.json export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31e7c97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +!.env +/coverage +/composer.lock +/vendor +/.phplint-cache +/.DS_Store +/auth.json diff --git a/.vsls.json b/.vsls.json new file mode 100644 index 0000000..d3dd21a --- /dev/null +++ b/.vsls.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/vsls", + "gitignore": "none" +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ba0c4e0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Signet B.V. + +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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a5fe14 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# signet/ecs + +An ECS Signet codestyle package. + +## Installation + +You can install the package via composer: + +```bash +composer require signet/ecs +``` + +**NOTE**: +You might need to set the minimum stability to dev to allow usage of `dev-master`. This is currently needed for (better) +PHP 8 support. Add the following keys to the root of your projects `composer.json`-file (prior to installing the +`signet\ecs` package): + +```json +{ + "minimum-stability": "dev", + "prefer-stable": true +} +``` + +## Usage + +Add a `ecs.php` file to the root of your project (if it doesn't exist) with the below contents + +`ecs.php`: +```php +import(__DIR__ . '/vendor/signet/ecs/signet-ecs.php'); + + $services = $containerConfigurator->services(); + + // $services->set(...); + + $parameters = $containerConfigurator->parameters(); + + $parameters->set(Option::PATHS, [ + __DIR__ . '/src', + __DIR__ . '/config', + __DIR__ . '/tests', + __DIR__ . '/ecs.php', + ]); +}; +``` + +If you already got an existing ecs.php and you want to use the `signet-ecs` style you can add the following line: + +```php +// ... + $containerConfigurator->import(__DIR__ . '/vendor/signet/ecs/signet-ecs.php'); +// ... +``` + +**NOTE**: +`signet-ecs` applies the same fixers as the preconfigured ecs `PSR-12` set (see [SetList::PSR_12](https://github.com/symplify/easy-coding-standard/blob/master/src/ValueObject/Set/SetList.php#L19)). + +## Links + +[Configuration example](https://github.com/symplify/easy-coding-standard#configuration) diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..61550e2 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,79 @@ +version: "3" + +dotenv: ['.env'] + +silent: true + +######################################################################################################################## +# +# TOC +# +######################################################################################################################## +# +# 1. COMPOSER +# 2. MISCELLANEOUS +# +######################################################################################################################## + +tasks: + ###################################################################################################################### + # + # 1. COMPOSER + # + ###################################################################################################################### + + c:update: + desc: Run composer update + cmds: + - task: c:exec + vars: + SUBCMD: update + + c:install: + desc: Run composer install + cmds: + - task: c:exec + vars: + SUBCMD: install + + c:exec: + preconditions: + - sh: test '{{.SUBCMD}}' = 'install' -o '{{.SUBCMD}}' = 'update' + msg: SUBCMD value needs to be either 'install' or 'update' + cmds: + - docker volume create php_composer_cache + - docker run + --interactive + --tty + --rm + --volume "$(pwd)":/var/www + --volume php_composer_cache:/home/composer/.composer + --entrypoint '' + -e COMPOSER_HOME=/home/composer/.composer + ilyes512/php80-fpm:builder-latest + composer {{.SUBCMD}} + --no-progress + --prefer-dist + --ignore-platform-reqs + + ###################################################################################################################### + # + # 2. MISCELLANEOUS + # + ###################################################################################################################### + + dc:down: + desc: Cleanup Devcontainer including volumes + cmds: + - docker-compose + -f .devcontainer/docker-compose.yml + down --volumes + + cleanup: + desc: Cleanup generated files and vendor files + cmds: + - rm -rf + vendor + composer.lock + .phplint-cache + && printf "%s\n" "Successfully removed vendor/generated files..." diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b813477 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "signet/ecs", + "type": "library", + "description": "An ECS Signet code style package.", + "keywords": [ + "package", + "ecs" + ], + "license": "MIT", + "require": { + "php": ">=8.0", + "slevomat/coding-standard": "dev-master", + "symplify/easy-coding-standard": "^9.2.1" + }, + "require-dev": { + "overtrue/phplint": "^2.1.0" + }, + "scripts": { + "check-style": "XDEBUG_MODE=off ecs check", + "fix-style": "XDEBUG_MODE=off ecs check --fix", + "lint": "XDEBUG_MODE=off phplint --exclude=vendor .", + "check-all": [ + "composer lint", + "composer check-style" + ] + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..bf82c2f --- /dev/null +++ b/ecs.php @@ -0,0 +1,17 @@ +import(__DIR__ . '/signet-ecs.php'); + + $containerConfigurator + ->parameters() + ->set(Option::PATHS, [ + __DIR__ . '/ecs.php', + __DIR__ . '/signet-ecs.php', + ]); +}; diff --git a/signet-ecs.php b/signet-ecs.php new file mode 100644 index 0000000..40a7ffe --- /dev/null +++ b/signet-ecs.php @@ -0,0 +1,204 @@ +services(); + + // PSR-2 + $services->set(EncodingFixer::class); + $services->set(FullOpeningTagFixer::class); + $services->set(BlankLineAfterNamespaceFixer::class); + $services->set(BracesFixer::class); + $services->set(ClassDefinitionFixer::class); + $services->set(ConstantCaseFixer::class); + $services->set(ElseifFixer::class); + $services->set(FunctionDeclarationFixer::class); + $services->set(IndentationTypeFixer::class); + $services->set(LineEndingFixer::class); + $services->set(LowercaseKeywordsFixer::class); + $services->set(MethodArgumentSpaceFixer::class) + ->call('configure', [ + [ + 'ensure_fully_multiline' => true, + ], + ]); + $services->set(NoBreakCommentFixer::class); + $services->set(NoClosingTagFixer::class); + $services->set(NoSpacesAfterFunctionNameFixer::class); + $services->set(NoSpacesInsideParenthesisFixer::class); + $services->set(NoTrailingWhitespaceFixer::class); + $services->set(NoTrailingWhitespaceInCommentFixer::class); + $services->set(SingleBlankLineAtEofFixer::class); + $services->set(SingleClassElementPerStatementFixer::class) + ->call('configure', [ + [ + 'elements' => ['property'], + ], + ]); + // $services->set(SingleImportPerStatementFixer::class); // Disabled for PSR-12 compliance + $services->set(SingleLineAfterImportsFixer::class); + $services->set(SwitchCaseSemicolonToColonFixer::class); + $services->set(SwitchCaseSpaceFixer::class); + $services->set(VisibilityRequiredFixer::class); + + // PSR-12 + $services->set(LowercaseCastFixer::class); + $services->set(ShortScalarCastFixer::class); + $services->set(BlankLineAfterOpeningTagFixer::class); + $services->set(NoLeadingImportSlashFixer::class); + $services->set(OrderedImportsFixer::class) + ->call('configure', [ + [ + 'importsOrder' => ['class', 'function', 'const'], + ], + ]); + $services->set(DeclareEqualNormalizeFixer::class) + ->call('configure', [ + [ + 'space' => 'none', + ], + ]); + $services->set(NewWithBracesFixer::class); + $services->set(BracesFixer::class) + ->call('configure', [ + [ + 'allow_single_line_closure' => false, + 'position_after_functions_and_oop_constructs' => 'next', + 'position_after_control_structures' => 'same', + 'position_after_anonymous_constructs' => 'same', + ], + ]); + $services->set(NoBlankLinesAfterClassOpeningFixer::class); + $services->set(VisibilityRequiredFixer::class) + ->call('configure', [ + [ + 'elements' => ['const', 'method', 'property'], + ], + ]); + // $services->set(BinaryOperatorSpacesFixer::class); // See custom section + $services->set(TernaryOperatorSpacesFixer::class); + $services->set(UnaryOperatorSpacesFixer::class); + $services->set(ReturnTypeDeclarationFixer::class); + $services->set(NoTrailingWhitespaceFixer::class); + $services->set(ConcatSpaceFixer::class) + ->call('configure', [ + [ + 'spacing' => 'one', + ], + ]); + $services->set(NoSinglelineWhitespaceBeforeSemicolonsFixer::class); + $services->set(NoWhitespaceBeforeCommaInArrayFixer::class); + $services->set(WhitespaceAfterCommaInArrayFixer::class); + + // Custom + $services->set(FileHeaderSniff::class); + $services->set(TraitUseDeclarationSniff::class); + $services->set(DisallowLongArraySyntaxSniff::class); + $services->set(DeclareStrictTypesFixer::class); + $services->set(UnusedUsesSniff::class); + $services->set(UseFromSameNamespaceSniff::class); + $services->set(OptimizedFunctionsWithoutUnpackingSniff::class); + $services->set(DeadCatchSniff::class); + $services->set(RequireTrailingCommaInCallSniff::class); + $services->set(RequireTrailingCommaInDeclarationSniff::class); + $services->set(RequireConstructorPropertyPromotionSniff::class); + $services->set(AlphabeticallySortedUsesSniff::class); + $services->set(ClassConstantVisibilitySniff::class); + $services->set(TrailingArrayCommaSniff::class); + $services->set(ArrayIndentSniff::class); + $services->set(ClassMemberSpacingSniff::class); + $services->set(CastSpacingSniff::class); + $services->set(SpaceAfterCastSniff::class); + $services->set(LineLengthSniff::class) + ->property('absoluteLineLimit', 120); + $services->set(FunctionSpacingSniff::class) + ->property('spacing', 1) + ->property('spacingBeforeFirst', 0) + ->property('spacingAfterLast', 0); + $services->set(PropertySpacingSniff::class) + ->property('minLinesCountBeforeWithComment', 1) + ->property('maxLinesCountBeforeWithComment', 1) + ->property('minLinesCountBeforeWithoutComment', 0) + ->property('maxLinesCountBeforeWithoutComment', 1); + $services->set(ConstantSpacingSniff::class) + ->property('minLinesCountBeforeWithComment', 1) + ->property('maxLinesCountBeforeWithComment', 1) + ->property('minLinesCountBeforeWithoutComment', 0) + ->property('maxLinesCountBeforeWithoutComment', 1); + $services->set(EmptyLinesAroundClassBracesSniff::class) + ->property('linesCountAfterOpeningBrace', 0) + ->property('linesCountBeforeClosingBrace', 0); + $services->set(BinaryOperatorSpacesFixer::class) + ->call('configure', [ + [ + 'default' => BinaryOperatorSpacesFixer::SINGLE_SPACE, + 'operators' => ['|' => null], + ], + ]); +};