From 209308a96587c449ad3d0dbdc17725592d15a82c Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Mon, 2 Dec 2024 04:29:17 +0100 Subject: [PATCH] [Add] VS Code tasks configuration for Tests, GitHub Workflows and CodeStyle, [Change] Add verbose flag back to PHP Code Sniffer examples & useage, [Change] Dont run Coveralis / Scruntinizer GitHub Workflow Steps in ACT environment, [Add] PHP Coding Standards Fixer configuration --- .devcontainer/docker/Dockerfile | 30 +++++++++++++++++++++++++++++- .gitignore | 5 ++++- .php-cs-fixer.dist.php | 29 +++++++++++++++++++++++++++++ .vscode/tasks.json | 11 ++++++++++- CONTRIBUTING.md | 2 +- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 .php-cs-fixer.dist.php diff --git a/.devcontainer/docker/Dockerfile b/.devcontainer/docker/Dockerfile index 19feca8b..a199e678 100644 --- a/.devcontainer/docker/Dockerfile +++ b/.devcontainer/docker/Dockerfile @@ -1,9 +1,27 @@ +########################## Base ########################### +# Create & configure the base for this DevContainer image # +########################################################### + # Define the DevContainer template to be used as the base ARG PHP=8.3 ARG DISTRO=bullseye FROM mcr.microsoft.com/vscode/devcontainers/php:$PHP-$DISTRO +# Add global Composer /bin to PATH for vscode +USER vscode + +RUN echo "export PATH=\$(XDEBUG_MODE=off composer global config bin-dir --absolute --quiet):\$PATH" >> ~/.bashrc + +# Add global Composer /bin to PATH for root +USER root + +RUN echo "export PATH=\$(XDEBUG_MODE=off composer global config bin-dir --absolute --quiet):\$PATH" >> ~/.bashrc + +##################### Dependencies ##################### +# Add any dependencies required to develop the project # +######################################################## + # Update the registry once RUN apt-get update @@ -12,5 +30,15 @@ RUN apt-get install -y libbz2-dev \ && docker-php-ext-configure bz2 \ && docker-php-ext-install bz2 + +###################### Tools ###################### +# Install tools that are required for development # +################################################### + # Install act -RUN curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash -s -- -b /usr/local/bin \ No newline at end of file +RUN curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash -s -- -b /usr/local/bin + +# Install PHP Code Sniffer Fixer +USER vscode + +RUN composer global require friendsofphp/php-cs-fixer \ No newline at end of file diff --git a/.gitignore b/.gitignore index cbdaa31d..fa960e0b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ composer.phar .phpunit.result.cache coverage/ build/logs/* -!build/logs/.gitkeep \ No newline at end of file +!build/logs/.gitkeep + +# PHP Code Sniffer Fixer +.php-cs-fixer.cache \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..8c41ac9b --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,29 @@ +in([ + __DIR__.'/src', + __DIR__.'/tests', + ]) +; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR2' => true, + + /* Imports / use */ + 'no_unused_imports' => true, + 'no_unneeded_import_alias' => true, + 'no_leading_import_slash' => true, + 'ordered_imports' => true, + + /* Comments */ + 'single_line_comment_style' => true, + + /* Blank lines */ + 'no_extra_blank_lines' => [ + 'tokens' => ['curly_brace_block'] + ] + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 940f105a..6d2abf0c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -24,7 +24,16 @@ "--ignore=bootstrap", "--report=checkstyle", "--report-file=build/logs/checkstyle.xml", - "--standard=build/config/phpcs.xml" + "--standard=build/config/phpcs.xml", + "-v" + ] + }, + { + "label": "PHP Coding Standards Fixer", + "type": "shell", + "command": "php-cs-fixer", + "args": [ + "fix" ] }, { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7fbd7c13..c5040426 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Contributions are **welcome** and will be fully **credited**. - Use the following commands to check your code before committing it: ```sh -$ vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml +$ vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v $ vendor/bin/phpmd src,tests xml build/config/phpmd.xml ```