Skip to content

Commit

Permalink
CI Fixes and Changes
Browse files Browse the repository at this point in the history
* Adding PHPMD
* Removing Phive config
* Fixing phpstan issue
* Minor refactoring for better code quality
  • Loading branch information
floriankraemer committed Mar 17, 2024
1 parent 163a448 commit 8745c0b
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 135 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -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/*'
Expand Down
53 changes: 0 additions & 53 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 0 additions & 32 deletions phive.xml

This file was deleted.

7 changes: 7 additions & 0 deletions phpmd.baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\Design\CouplingBetweenObjects" file="src/AuthenticationService.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Authenticator/JwtAuthenticator.php"/>
<violation rule="PHPMD\Rule\UnusedFormalParameter" file="src/Identifier/Ldap/ExtensionAdapter.php"/>
<violation rule="PHPMD\Rule\UnusedFormalParameter" file="src/Identity/Identity.php"/>
</phpmd-baseline>
22 changes: 22 additions & 0 deletions phpmd.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
PHPMD Rules
</description>

<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/design.xml">
</rule>
<rule ref="rulesets/naming.xml">
<exclude name="LongVariable"/>
<exclude name="LongClassName"/>
</rule>
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
23 changes: 14 additions & 9 deletions src/Authenticator/HttpDigestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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)];
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Identifier/Ldap/ExtensionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/Middleware/AuthenticationErrorHandlerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8745c0b

Please sign in to comment.