From 8745c0b781a30b730d625f50dfa37fac2adf1c22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Kr=C3=A4mer?=
<4996022+floriankraemer@users.noreply.github.com>
Date: Sun, 17 Mar 2024 01:53:11 +0100
Subject: [PATCH] CI Fixes and Changes
* Adding PHPMD
* Removing Phive config
* Fixing phpstan issue
* Minor refactoring for better code quality
---
.github/workflows/ci.yml | 4 +-
.scrutinizer.yml | 34 ------------
.travis.yml | 53 -------------------
composer.json | 5 +-
phive.xml | 32 -----------
phpmd.baseline.xml | 7 +++
phpmd.xml.dist | 22 ++++++++
src/Authenticator/HttpDigestAuthenticator.php | 23 ++++----
src/Identifier/Ldap/ExtensionAdapter.php | 1 +
.../AuthenticationErrorHandlerMiddleware.php | 10 ++--
10 files changed, 56 insertions(+), 135 deletions(-)
delete mode 100644 .travis.yml
delete mode 100644 phive.xml
create mode 100644 phpmd.baseline.xml
create mode 100644 phpmd.xml.dist
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 15012a35..e1271730 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -43,7 +43,9 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- slug: phauthentic/authentication
+ slug: burzum/authentication
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
validation:
name: Coding Standard & Static Analysis
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index 84c5a647..8132c011 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,43 +1,9 @@
build:
nodes:
- tests-php74:
- environment:
- php:
- version: '8.0'
- ini:
- phar.readonly: 'Off'
- pecl_extensions:
- - xdebug
- tests:
- override:
- -
- command: 'XDEBUG_MODE=coverage ./bin/phpunit --coverage-clover=coverage.xml'
- coverage:
- file: 'coverage.xml'
- format: 'php-clover'
- tests-php80:
- environment:
- php:
- version: '8.3'
- ini:
- phar.readonly: 'Off'
- pecl_extensions:
- - xdebug
- tests:
- override:
- -
- command: 'XDEBUG_MODE=coverage ./bin/phpunit --coverage-clover=coverage.xml'
- coverage:
- file: 'coverage.xml'
- format: 'php-clover'
validation:
tests:
override:
- php-scrutinizer-run --enable-security-analysis
- -
- command: './bin/phpcs'
- -
- command: './bin/phpstan'
filter:
excluded_paths:
- 'tests/*'
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index be0113a0..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,53 +0,0 @@
-language: php
-
-php:
- - 7.4
- - 8.0
- - 8.1
- - 8.2
- - 8.3
-
-sudo: false
-
-env:
- matrix:
- - DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test'
- - DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test'
- - DB=sqlite db_dsn='sqlite:///:memory:'
- global:
- - DEFAULT=1
-
-matrix:
- fast_finish: true
- include:
- - php: 7.4
- env: PHPCS=1 DEFAULT=0
- - php: 7.4
- env: PHPSTAN=1 DEFAULT=0
- - php: 7.4
- env: PREFER_LOWEST=1
-
-before_install:
- - echo 'extension = ldap.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-
-install:
- - if [[ $PREFER_LOWEST != '1' ]]; then composer install --prefer-dist --no-interaction; fi
- - if [[ $PREFER_LOWEST == '1' ]]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
-
-before_script:
- - if [[ $DB == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- - if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
- - if [[ $PHPSTAN == 1 ]]; then composer require --dev phpstan/phpstan:"^0.9"; fi
-
-script:
- - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.0 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
- - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
-
- - if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/; fi
- - if [[ $PHPSTAN == 1 ]]; then vendor/bin/phpstan analyse -l 4 src; fi
-
-after_success:
- - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi
-
-notifications:
- email: false
diff --git a/composer.json b/composer.json
index 578e43a8..1d9630aa 100644
--- a/composer.json
+++ b/composer.json
@@ -22,6 +22,7 @@
"firebase/php-jwt": "6.*",
"misantron/dbunit": "dev-master",
"nyholm/psr7": "^1.8",
+ "phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.9"
@@ -56,7 +57,9 @@
"cs-check": "phpcs --colors -p src/ tests/",
"cs-fix": "phpcbf --colors src/ tests/",
"test": "phpunit",
- "test-coverage": "phpunit --coverage-clover=clover.xml"
+ "test-coverage": "phpunit --coverage-clover=clover.xml",
+ "phpmd": "bin/phpmd src/ text phpmd.xml.dist",
+ "phpmd-baseline": "bin/phpmd --generate-baseline --baseline-file phpmd.baseline.xml src/ text phpmd.xml.dist"
},
"config": {
"sort-packages": true,
diff --git a/phive.xml b/phive.xml
deleted file mode 100644
index 4af75b17..00000000
--- a/phive.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/phpmd.baseline.xml b/phpmd.baseline.xml
new file mode 100644
index 00000000..ca6062fe
--- /dev/null
+++ b/phpmd.baseline.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/phpmd.xml.dist b/phpmd.xml.dist
new file mode 100644
index 00000000..e5cedd32
--- /dev/null
+++ b/phpmd.xml.dist
@@ -0,0 +1,22 @@
+
+
+
+ PHPMD Rules
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Authenticator/HttpDigestAuthenticator.php b/src/Authenticator/HttpDigestAuthenticator.php
index 0e7bc107..e8e5118c 100644
--- a/src/Authenticator/HttpDigestAuthenticator.php
+++ b/src/Authenticator/HttpDigestAuthenticator.php
@@ -285,6 +285,16 @@ protected function getDigestOptions(ServerRequestInterface $request): array
];
}
+ protected function formatOptions(string $key, mixed $value): string
+ {
+ if (is_bool($value)) {
+ $value = $value ? 'true' : 'false';
+ return sprintf('%s=%s', $key, $value);
+ }
+
+ return sprintf('%s="%s"', $key, $value);
+ }
+
/**
* Generate the login headers
*
@@ -300,17 +310,12 @@ protected function loginHeaders(ServerRequestInterface $request): array
$options['stale'] = true;
}
- $opts = [];
- foreach ($options as $k => $v) {
- if (is_bool($v)) {
- $v = $v ? 'true' : 'false';
- $opts[] = sprintf('%s=%s', $k, $v);
- } else {
- $opts[] = sprintf('%s="%s"', $k, $v);
- }
+ $formattedOptions = [];
+ foreach ($options as $key => $value) {
+ $formattedOptions[] = $this->formatOptions($key, $value);
}
- return ['WWW-Authenticate' => 'Digest ' . implode(',', $opts)];
+ return ['WWW-Authenticate' => 'Digest ' . implode(',', $formattedOptions)];
}
/**
diff --git a/src/Identifier/Ldap/ExtensionAdapter.php b/src/Identifier/Ldap/ExtensionAdapter.php
index 8c07e266..be71e49d 100644
--- a/src/Identifier/Ldap/ExtensionAdapter.php
+++ b/src/Identifier/Ldap/ExtensionAdapter.php
@@ -130,6 +130,7 @@ public function setOption(int $option, $value)
*/
public function getOption($option)
{
+ $returnValue = null;
$this->setErrorHandler();
ldap_get_option($this->getConnection(), $option, $returnValue);
$this->unsetErrorHandler();
diff --git a/src/Middleware/AuthenticationErrorHandlerMiddleware.php b/src/Middleware/AuthenticationErrorHandlerMiddleware.php
index 086c027c..2fdc1521 100644
--- a/src/Middleware/AuthenticationErrorHandlerMiddleware.php
+++ b/src/Middleware/AuthenticationErrorHandlerMiddleware.php
@@ -72,20 +72,20 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
/**
* Creates an unauthorized response.
*
- * @param \Phauthentic\Authentication\Authenticator\Exception\UnauthorizedException $e Exception.
+ * @param \Phauthentic\Authentication\Authenticator\Exception\UnauthorizedException $exception Exception.
* @return \Psr\Http\Message\ResponseInterface
*/
- protected function createUnauthorizedResponse(UnauthorizedException $e): ResponseInterface
+ protected function createUnauthorizedResponse(UnauthorizedException $exception): ResponseInterface
{
$body = $this->streamFactory->createStream();
- $body->write($e->getBody());
+ $body->write($exception->getBody());
$response = $this
->responseFactory
- ->createResponse($e->getCode())
+ ->createResponse($exception->getCode())
->withBody($body);
- foreach ($e->getHeaders() as $header => $value) {
+ foreach ($exception->getHeaders() as $header => $value) {
$response = $response->withHeader($header, $value);
}