Skip to content

Commit

Permalink
Update coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Jun 21, 2023
1 parent 18d839a commit e071f90
Show file tree
Hide file tree
Showing 26 changed files with 490 additions and 177 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.php]
indent_size = 4

[*.js]
indent_size = 4

[{*.vue,*.json,*.html5,*.xlf,*.twig}]
indent_size = 2
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.composer-require-checker.json export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitlab-ci.yml export-ignore
.gitignore export-ignore
.phpcq.lock export-ignore
.phpcq.yaml.dist export-ignore
phpcs.xml.dist export-ignore
psalm.xml export-ignore
23 changes: 23 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2

updates:
- commit-message:
include: "scope"
prefix: "composer"
directory: "/"
open-pull-requests-limit: 0
package-ecosystem: "composer"
schedule:
interval: "weekly"
versioning-strategy: "increase"

- commit-message:
include: "scope"
prefix: "github-actions"
directory: "/"
open-pull-requests-limit: 10
package-ecosystem: "github-actions"
schedule:
interval: "weekly"
77 changes: 77 additions & 0 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Code Quality Diagnostics

on:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

name: PHP ${{ matrix.php }}

strategy:
fail-fast: false
matrix:
include:
- php: 8.1
output: '-o default'
phpcq_install: 'update'
- php: 8.2
output: '-o default'
phpcq_install: 'update'

steps:
- name: Pull source
uses: actions/checkout@v3

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Cache composer cache directory
uses: actions/cache@v3
env:
cache-name: composer-cache-dir
with:
path: ~/.cache/composer
key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}

- name: Install composer dependencies
run: composer install

- name: Cache vendor directory
uses: actions/cache@v3
env:
cache-name: vendor
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-
- name: Install phpcq toolchain
run: ./vendor/bin/phpcq ${{ matrix.phpcq_install }} -v

- name: Cache phpcq directory
uses: actions/cache@v3
env:
cache-name: phpcq
with:
path: .phpcq
key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/.phpcq.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-
- name: Run tests
run: ./vendor/bin/phpcq run -v ${{ matrix.output }}

- name: Upload build directory to artifact
uses: actions/upload-artifact@v3
if: ${{ success() }} || ${{ failure() }}
with:
name: phpcq-builds-php-${{ matrix.php }}
path: .phpcq/build/
23 changes: 8 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# OS
.DS_Store
Thumbs.db

# IDEs
.buildpath
.project
.settings/
.build/
.idea/
nbproject/

# Composer
/vendor/
composer.phar
composer.lock
/vendor
composer.lock

# PHPCQ and related tools
/.phpcq
.phpcq.yaml
.phpcs-cache
.phpunit.result.cache
1 change: 1 addition & 0 deletions .phpcq.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"plugins":{"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.12.0","url":"https://github.com/vimeo/psalm/releases/download/5.12.0/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.12.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"4.6.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.6.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.1.0 || ~8.2.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.6.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.13.0","url":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar.asc"},"phpcbf":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.31.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.31.0/composer-normalize.phar","requirements":{"php":{"php":"~8.0.0 || ~8.1.0 || ~8.2.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.31.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]}
100 changes: 100 additions & 0 deletions .phpcq.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
phpcq:
repositories:
- https://phpcq.github.io/repository/repository.json
directories:
- src
artifact: .phpcq/build

plugins:
psalm:
version: ^1.0
signed: false
composer-require-checker:
version: ^1.0
signed: false
phpmd:
version: ^1.0
signed: false
requirements:
phpmd:
signed: false
phpcpd:
version: ^1.1
signed: false
phploc:
version: ^1.0
signed: false
phpcs:
version: ^1.0
signed: false
composer-normalize:
version: ^1.0
signed: false

trusted-keys:
# composer-require-checker
- 033E5F8D801A2F8D
# [email protected]
- 4AA394086372C20A
# psalm
- 8A03EA3B385DBAA1
- 12CE0F1D262429A5
# [email protected]
- D2CCAC42F6295E7D
# PHP_CodeSniffer
- 31C7E470E2138192
# Composer normalize
- C00543248C87FB13
# phpmd
- A4E55EA12C7C085C

tasks:
fix:
- composer-normalize-fix
- phpcbf

verify:
- composer-require-checker
- composer-normalize

analyze:
- phploc
- phpcpd
- phpmd
- phpcs
- psalm

default:
- verify
- analyze

phpmd:
config:
ruleset:
- codesize
- controversial
- design
- naming
- unusedcode

composer-require-checker:
config:
config_file: '.composer-require-checker.json'

phpcs:
config: &phpcs-config
standard: ~
standard_paths:
- ./vendor/slevomat/coding-standard
- ./vendor/doctrine/coding-standard/lib

phpcbf:
plugin: phpcs
config:
<<: *phpcs-config
fix: true

composer-normalize-fix:
plugin: composer-normalize
config:
dry_run: false
40 changes: 25 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "hofff/contao-facebook-pixel",
"description": "Integrate Facebook Tracking Pixel in Contao",
"license": "LGPL-3.0-or-later",
"type": "contao-bundle",
"keywords": [
"contao",
"plugin",
Expand All @@ -9,14 +11,11 @@
"analytics",
"tracking"
],
"type": "contao-bundle",
"license": "LGPL-3.0-or-later",
"homepage": "https://www.hofff.com",
"authors": [
{
"name": "Nicky Hoff",
"homepage": "https://www.hofff.com",
"email": "[email protected]",
"homepage": "https://www.hofff.com",
"role": "Manager"
},
{
Expand All @@ -26,29 +25,40 @@
"role": "Developer"
}
],
"homepage": "https://www.hofff.com",
"require": {
"php": "^7.1",
"php": "^8.1",
"ext-pdo": "*",
"contao/core-bundle": "^4.4",
"contao/core-bundle": "^4.9",
"doctrine/dbal": "^2.13 || ^3.4",
"hofff/contao-consent-bridge": "^1.1",
"symfony/http-kernel": "^3.3 || ^4.0",
"symfony/config": "^3.3 || ^4.0",
"symfony/dependency-injection": "^3.3 || ^4.0",
"doctrine/dbal": "^2.5"
"symfony/config": "^4.4 || ^5.4",
"symfony/dependency-injection": "^4.4 || ^5.4",
"symfony/http-kernel": "^4.4 || ^5.4"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
"contao/manager-plugin": "^2.0",
"doctrine/coding-standard": "^12.0",
"phpcq/runner-bootstrap": "^1.0@dev"
},
"autoload": {
"psr-4": {
"Hofff\\Contao\\FacebookPixel\\": "src/"
}
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": true,
"contao/manager-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"contao-manager-plugin": "Hofff\\Contao\\FacebookPixel\\ContaoManager\\Plugin",
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
}
"dev-develop": "2.2.x-dev",
"dev-master": "2.1.x-dev"
},
"contao-manager-plugin": "Hofff\\Contao\\FacebookPixel\\ContaoManager\\Plugin"
}
}
32 changes: 32 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Required for the SlevomatCodingStandard which utilizes composer dependencies -->
<autoload>vendor/autoload.php</autoload>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<!-- Directories to be checked -->
<file>src</file>

<!-- Include full Doctrine Coding Standard -->
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
<exclude name="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed"/>
</rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="120"/>
</properties>
<exclude-pattern>languages/*</exclude-pattern>
</rule>
</ruleset>
21 changes: 21 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
hideExternalErrors="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config https://getpsalm.org/schema/config"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="src/Resources/contao"/>
</ignoreFiles>
</projectFiles>

<universalObjectCrates>
<class name="Contao\BackendTemplate"/>
<class name="Contao\FrontendTemplate"/>
<class name="Contao\Database\Result"/>
</universalObjectCrates>
</psalm>
Loading

0 comments on commit e071f90

Please sign in to comment.