8
0
Dieser Commit ist enthalten in:
Daniel Seifert 2024-12-24 00:05:56 +01:00
Ursprung aa5b095b6e
Commit b50624a0be
Signiert von: DanielS
GPG-Schlüssel-ID: 6A513E13AEE66170
5 geänderte Dateien mit 86 neuen und 7 gelöschten Zeilen

3
.gitignore vendored Normale Datei
Datei anzeigen

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

34
.php-cs-fixer.php Normale Datei
Datei anzeigen

@ -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)
;

Datei anzeigen

@ -20,11 +20,22 @@
} }
], ],
"require": { "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": { "autoload": {
"psr-4": { "psr-4": {
"D3\\SensitiveMessageFormatter\\": "src/" "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 Normale Datei
Datei anzeigen

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

Datei anzeigen

@ -1,5 +1,20 @@
<?php <?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; namespace D3\SensitiveMessageFormatter;
use GuzzleHttp\MessageFormatter; use GuzzleHttp\MessageFormatter;
@ -9,6 +24,11 @@ use Throwable;
class sensitiveMessageFormatter extends MessageFormatter class sensitiveMessageFormatter extends MessageFormatter
{ {
/**
* @param string|null $template
* @param string[] $anonymizations
* @param string|null $replaceChar
*/
public function __construct( public function __construct(
?string $template = self::CLF, ?string $template = self::CLF,
protected array $anonymizations = [], protected array $anonymizations = [],
@ -19,15 +39,20 @@ class sensitiveMessageFormatter extends MessageFormatter
parent::__construct($template); parent::__construct($template);
} }
/**
* @param string[] $search
* @return void
*/
protected function createReplacements(array $search = []): void protected function createReplacements(array $search = []): void
{ {
$replacements = []; $replacements = [];
$this->replaceChar = $this->replaceChar ?? '*';
$this->replaceChar ??= '*';
array_map( array_map(
function ($search) use (&$replacements) { function ($search) use (&$replacements) {
$replacements[$search] = str_repeat($this->replaceChar, strlen($search)); $replacements[$search] = str_repeat($this->replaceChar ?? '*', strlen($search));
$replacements[urlencode($search)] = str_repeat($this->replaceChar, strlen($search)); $replacements[urlencode($search)] = str_repeat($this->replaceChar ?? '*', strlen($search));
}, },
$search $search
); );
@ -39,8 +64,7 @@ class sensitiveMessageFormatter extends MessageFormatter
RequestInterface $request, RequestInterface $request,
ResponseInterface $response = null, ResponseInterface $response = null,
Throwable $error = null Throwable $error = null
): string ): string {
{
$result = parent::format($request, $response, $error); $result = parent::format($request, $response, $error);
if (count($this->anonymizations)) { if (count($this->anonymizations)) {