diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa004b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor +.php-cs-fixer.cache +composer.lock diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..8ba90c2 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,34 @@ +in(__DIR__) +; + +$header = << +@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) +; \ No newline at end of file diff --git a/composer.json b/composer.json index 34ac3bf..6e17baa 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..f927928 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + paths: + - src + level: 10 + phpVersion: 80000 + ignoreErrors: + - identifier: class.extendsFinalByPhpDoc \ No newline at end of file diff --git a/src/sensitiveMessageFormatter.php b/src/sensitiveMessageFormatter.php index 761e449..e779309 100644 --- a/src/sensitiveMessageFormatter.php +++ b/src/sensitiveMessageFormatter.php @@ -1,5 +1,20 @@ + * @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; } -} \ No newline at end of file +}