reformat code

This commit is contained in:
Daniel Seifert 2024-12-24 00:05:56 +01:00
parent aa5b095b6e
commit b50624a0be
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
5 changed files with 86 additions and 7 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
vendor
.php-cs-fixer.cache
composer.lock

34
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,34 @@
<?php
$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
;
$header = <<<EOF
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
For the full copyright and license information, please view
the LICENSE file that was distributed with this source code.
https://www.d3data.de
@copyright (C) D3 Data Development (Inh. Thomas Dartsch)
@author D3 Data Development - Max Buhe, Daniel Seifert <info@shopmodule.com>
@link https://www.oxidmodule.com
EOF;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP80Migration' => true,
'@PSR12' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'header' => $header,
'location' => 'after_open',
'separate' => 'both',
],
'php_unit_test_class_requires_covers' => true,
'doctrine_annotation_indentation' => true,
])
->setFinder($finder)
;

View File

@ -20,11 +20,22 @@
}
],
"require": {
"guzzlehttp/guzzle": "^7.0"
"php": "^8.0",
"guzzlehttp/guzzle": "^7.9"
},
"require-dev": {
"php": "^8.2",
"friendsofphp/php-cs-fixer": "^3.65",
"phpstan/phpstan": "^2.0"
},
"autoload": {
"psr-4": {
"D3\\SensitiveMessageFormatter\\": "src/"
}
},
"scripts": {
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
}
}

7
phpstan.neon Normal file
View File

@ -0,0 +1,7 @@
parameters:
paths:
- src
level: 10
phpVersion: 80000
ignoreErrors:
- identifier: class.extendsFinalByPhpDoc

View File

@ -1,5 +1,20 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Max Buhe, Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\SensitiveMessageFormatter;
use GuzzleHttp\MessageFormatter;
@ -9,6 +24,11 @@ use Throwable;
class sensitiveMessageFormatter extends MessageFormatter
{
/**
* @param string|null $template
* @param string[] $anonymizations
* @param string|null $replaceChar
*/
public function __construct(
?string $template = self::CLF,
protected array $anonymizations = [],
@ -19,15 +39,20 @@ class sensitiveMessageFormatter extends MessageFormatter
parent::__construct($template);
}
/**
* @param string[] $search
* @return void
*/
protected function createReplacements(array $search = []): void
{
$replacements = [];
$this->replaceChar = $this->replaceChar ?? '*';
$this->replaceChar ??= '*';
array_map(
function ($search) use (&$replacements) {
$replacements[$search] = str_repeat($this->replaceChar, strlen($search));
$replacements[urlencode($search)] = str_repeat($this->replaceChar, strlen($search));
$replacements[$search] = str_repeat($this->replaceChar ?? '*', strlen($search));
$replacements[urlencode($search)] = str_repeat($this->replaceChar ?? '*', strlen($search));
},
$search
);
@ -39,8 +64,7 @@ class sensitiveMessageFormatter extends MessageFormatter
RequestInterface $request,
ResponseInterface $response = null,
Throwable $error = null
): string
{
): string {
$result = parent::format($request, $response, $error);
if (count($this->anonymizations)) {
@ -53,4 +77,4 @@ class sensitiveMessageFormatter extends MessageFormatter
return $result;
}
}
}