From 691adc00a6d48e3cab652a90413af5055613c908 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 21 Sep 2020 14:59:34 +0200 Subject: [PATCH] Follow and validate against PSR-12 This prevents unnecessary merge conflicts in future. Also code follows a simple formatting rule set and is easier to read. --- .github/workflows/ci.yaml | 23 ++++++++ composer.json | 3 +- composer.lock | 53 ++++++++++++++++++- phpcs.xml.dist | 14 +++++ src/Configuration/Settings.php | 5 +- .../AutoGrantSelfVerification.php | 3 +- .../AutoGrantBusinessVerification.php | 3 +- src/Example/Includes/ExampleSettings.php | 1 + .../RenderCustomVerificationLinks.php | 1 + .../RenderVerificationButtons.php | 1 + src/Verification/Issuer.php | 4 +- src/Verification/Link.php | 5 +- tests/Unit/Configuration/SettingsTest.php | 1 + tests/Unit/Verification/LinkTest.php | 1 + 14 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b6a2d8e..1dff57a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,6 +29,29 @@ jobs: - name: PHP lint run: "find *.php src tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" + check-cgl: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Check CGL + run: ./vendor/bin/phpcs + tests: runs-on: ubuntu-latest steps: diff --git a/composer.json b/composer.json index 74feae4..521aaa8 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.3", - "phpspec/prophecy-phpunit": "^2.0" + "phpspec/prophecy-phpunit": "^2.0", + "squizlabs/php_codesniffer": "^3.5" } } diff --git a/composer.lock b/composer.lock index cb78ab4..4290183 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b9cf8f698cb3698b7ded4c56e55e8421", + "content-hash": "20a8d4087070dc229b18c15160e7bf79", "packages": [ { "name": "guzzlehttp/guzzle", @@ -2481,6 +2481,57 @@ ], "time": "2020-06-26T12:18:43+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.6", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e97627871a7eab2f70e59166072a6b767d5834e0", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2020-08-10T04:50:15+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.18.1", diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..e39aa23 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,14 @@ + + + This project coding standard + + src/ + tests/ + + + + + + + + diff --git a/src/Configuration/Settings.php b/src/Configuration/Settings.php index 7a86518..43cb133 100644 --- a/src/Configuration/Settings.php +++ b/src/Configuration/Settings.php @@ -1,4 +1,5 @@ apiKey = $apiKey; $this->verifierID = $verifierID; $this->user_secret = $user_secret; - $this->APIUrl = is_null($domain) ? 'https://www.skilldisplay.eu' : 'https://' . $domain; - $this->mySkillDisplayUrl = is_null($domain) ? 'https://my.skilldisplay.eu' : 'https://my.' . $domain; + $this->APIUrl = (is_null($domain)) ? 'https://www.skilldisplay.eu' : 'https://' . $domain; + $this->mySkillDisplayUrl = (is_null($domain)) ? 'https://my.skilldisplay.eu' : 'https://my.' . $domain; } } diff --git a/src/Example/APIKeyRequired/AutoGrantSelfVerification.php b/src/Example/APIKeyRequired/AutoGrantSelfVerification.php index 59c1b77..3b08af4 100644 --- a/src/Example/APIKeyRequired/AutoGrantSelfVerification.php +++ b/src/Example/APIKeyRequired/AutoGrantSelfVerification.php @@ -1,4 +1,5 @@ issueVerification(193,'--skilldisplay-user-email--', VERIFICATION_SELF); +$myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_SELF); diff --git a/src/Example/FullSettingsRequired/AutoGrantBusinessVerification.php b/src/Example/FullSettingsRequired/AutoGrantBusinessVerification.php index 755263d..9cb1a04 100644 --- a/src/Example/FullSettingsRequired/AutoGrantBusinessVerification.php +++ b/src/Example/FullSettingsRequired/AutoGrantBusinessVerification.php @@ -1,4 +1,5 @@ outputResponse($myVerificationTool->issueVerification(193,'--skilldisplay-user-email--', VERIFICATION_BUSINESS)); +$myVerificationTool->outputResponse($myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_BUSINESS)); diff --git a/src/Example/Includes/ExampleSettings.php b/src/Example/Includes/ExampleSettings.php index 64b6be0..81858de 100644 --- a/src/Example/Includes/ExampleSettings.php +++ b/src/Example/Includes/ExampleSettings.php @@ -1,4 +1,5 @@ skillID; @@ -109,7 +110,7 @@ class Link * @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION * @return string SVG Button to a Verification that a user can click, he/she will see the Verification interface and can choose a verifier */ - public function getVerificationButton(string $vtype, ?int $skillID = null) : string + public function getVerificationButton(string $vtype, ?int $skillID = null): string { switch ($vtype) { case VERIFICATION_EDUCATIONAL: diff --git a/tests/Unit/Configuration/SettingsTest.php b/tests/Unit/Configuration/SettingsTest.php index c06f1ce..e63ed4a 100644 --- a/tests/Unit/Configuration/SettingsTest.php +++ b/tests/Unit/Configuration/SettingsTest.php @@ -1,4 +1,5 @@