Skip to content

Commit ee97de9

Browse files
committed
Fix all statics tests
1 parent 1f9d651 commit ee97de9

19 files changed

+81
-79
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
22
"name": "micro/plugin-http-logger",
33
"description": "Micro Framework: ROuter actions logger",
4+
"license": "MIT",
45
"type": "micro-plugin",
6+
"authors": [
7+
{
8+
"name": "Stanislau Komar",
9+
"email": "kost@micro-php.net"
10+
}
11+
],
512
"require": {
613
"micro/http-core": "^1",
714
"micro/plugin-logger-core": "^1"
@@ -14,7 +21,6 @@
1421
"phpunit/phpunit": "^9.5",
1522
"vimeo/psalm": "^5.2"
1623
},
17-
"license": "MIT",
1824
"autoload": {
1925
"psr-4": {
2026
"Micro\\Plugin\\Http\\": "src/"
@@ -26,12 +32,6 @@
2632
},
2733
"sort-packages": true
2834
},
29-
"authors": [
30-
{
31-
"name": "Stanislau Komar",
32-
"email": "kost@micro-php.net"
33-
}
34-
],
3535
"scripts": {
3636
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
3737
"php-cs-fix": "./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",

psalm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
<UnnecessaryVarAnnotation>
2020
<errorLevel type="suppress">
21-
<file name="src/HttpCorePlugin.php"/>
21+
<file name="src/PluginHttpLogger.php"/>
2222
</errorLevel>
2323
</UnnecessaryVarAnnotation>
2424

2525
<MissingConstructor>
2626
<errorLevel type="suppress">
27-
<file name="src/HttpCorePlugin.php"/>
27+
<file name="src/PluginHttpLogger.php"/>
2828
</errorLevel>
2929
</MissingConstructor>
3030

3131
<ImplementedReturnTypeMismatch>
3232
<errorLevel type="suppress">
33-
<file name="src/HttpCorePlugin.php"/>
33+
<file name="src/PluginHttpLogger.php"/>
3434
</errorLevel>
3535
</ImplementedReturnTypeMismatch>
3636
</issueHandlers>

src/Business/Executor/HttpExecutorLoggerAwareDecorator.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
namespace Micro\Plugin\Http\Business\Executor;
1515

16-
use Micro\Plugin\Http\Business\Formatter\LogFormatterInterface;
17-
use Micro\Plugin\Http\Exception\HttpException;
16+
use Micro\Plugin\Http\Business\Logger\Formatter\LogFormatterInterface;
1817
use Psr\Log\LoggerInterface;
1918
use Symfony\Component\HttpFoundation\Request;
2019
use Symfony\Component\HttpFoundation\Response;
@@ -42,24 +41,19 @@ public function execute(Request $request, bool $flush = true): Response
4241
$exception = null;
4342
try {
4443
$response = $this->decorated->execute($request, $flush);
45-
} catch (HttpException $httpException) {
46-
$exception = $httpException;
4744
} catch (\Throwable $throwable) {
4845
$exception = $throwable;
46+
$this->loggerError->critical(
47+
$this->logErrorFormatter->format($request, $response, $exception)
48+
);
49+
50+
throw $exception;
4951
} finally {
5052
$this->loggerAccess->info(
5153
$this->logAccessFormatter->format($request, $response, $exception)
5254
);
53-
54-
if ($exception) {
55-
$this->loggerError->critical(
56-
$this->logErrorFormatter->format($request, $response, $exception)
57-
);
58-
59-
throw $exception;
60-
}
61-
62-
return $response;
6355
}
56+
57+
return $response;
6458
}
6559
}

src/Business/Executor/HttpExecutorLoggerAwareDecoratorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Micro\Plugin\Http\Business\Executor;
1515

16-
use Micro\Plugin\Http\Business\Formatter\LogFormatterFactoryInterface;
16+
use Micro\Plugin\Http\Business\Logger\Formatter\LogFormatterFactoryInterface;
1717
use Micro\Plugin\Http\PluginHttpLoggerConfigurationInterface;
1818
use Micro\Plugin\Logger\LoggerFacadeInterface;
1919

src/Business/Formatter/Format/AbstractFormat.php renamed to src/Business/Logger/Formatter/Format/AbstractFormat.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Business\Formatter\LogFormatterInterface;
17-
use Micro\Plugin\Http\Exception\HttpException;
16+
use Micro\Plugin\Http\Business\Logger\Formatter\LogFormatterInterface;
1817
use Symfony\Component\HttpFoundation\Request;
1918
use Symfony\Component\HttpFoundation\Response;
2019

@@ -28,7 +27,7 @@ public function __construct(
2827
) {
2928
}
3029

31-
public function format(Request $request, Response|null $response, ?HttpException $exception): string
30+
public function format(Request $request, Response|null $response, ?\Throwable $exception): string
3231
{
3332
$var = '{{'.$this->getVarName().'}}';
3433

@@ -43,7 +42,7 @@ public function format(Request $request, Response|null $response, ?HttpException
4342
);
4443
}
4544

46-
abstract protected function getVarValue(Request $request, Response $response, ?HttpException $exception): string;
45+
abstract protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string;
4746

4847
abstract protected function getVarName(): string;
4948
}

src/Business/Formatter/Format/HttpRefererFormat.php renamed to src/Business/Logger/Formatter/Format/HttpRefererFormat.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Exception\HttpException;
1716
use Symfony\Component\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Response;
1918

@@ -22,9 +21,9 @@
2221
*/
2322
class HttpRefererFormat extends AbstractFormat
2423
{
25-
protected function getVarValue(Request $request, Response|null $response, ?HttpException $exception): string
24+
protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
2625
{
27-
return $request->headers->get('referer');
26+
return (string) $request->headers->get('referer');
2827
}
2928

3029
protected function getVarName(): string

src/Business/Formatter/Format/IpFormat.php renamed to src/Business/Logger/Formatter/Format/IpFormat.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Exception\HttpException;
1716
use Symfony\Component\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Response;
1918

@@ -22,9 +21,9 @@
2221
*/
2322
class IpFormat extends AbstractFormat
2423
{
25-
protected function getVarValue(Request $request, Response|null $response, ?HttpException $exception): string
24+
protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
2625
{
27-
return $request->getClientIp();
26+
return (string) $request->getClientIp();
2827
}
2928

3029
protected function getVarName(): string

src/Business/Formatter/Format/MethodFormat.php renamed to src/Business/Logger/Formatter/Format/MethodFormat.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Exception\HttpException;
1716
use Symfony\Component\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Response;
1918

@@ -22,7 +21,7 @@
2221
*/
2322
class MethodFormat extends AbstractFormat
2423
{
25-
protected function getVarValue(Request $request, Response|null $response, ?HttpException $exception): string
24+
protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
2625
{
2726
return $request->getMethod();
2827
}

src/Business/Formatter/Format/RequestBodyFormat.php renamed to src/Business/Logger/Formatter/Format/RequestBodyFormat.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Exception\HttpException;
1716
use Symfony\Component\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Response;
1918

@@ -22,9 +21,9 @@
2221
*/
2322
class RequestBodyFormat extends AbstractFormat
2423
{
25-
protected function getVarValue(Request $request, Response|null $response, ?HttpException $exception): string
24+
protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
2625
{
27-
$type = $request->headers->get('Content-Type');
26+
$type = (string) $request->headers->get('Content-Type');
2827

2928
switch ($type) {
3029
case 'application/EDI-X12':
@@ -71,7 +70,7 @@ protected function getVarValue(Request $request, Response|null $response, ?HttpE
7170
case 'multipart/related':
7271
return sprintf('~Multipart %s~', $this->getTypeFrontName($type));
7372
default:
74-
return (string) $request->getContent();
73+
return $request->getContent();
7574
}
7675
}
7776

src/Business/Formatter/Format/RequestFormat.php renamed to src/Business/Logger/Formatter/Format/RequestFormat.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace Micro\Plugin\Http\Business\Formatter\Format;
14+
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
1515

16-
use Micro\Plugin\Http\Exception\HttpException;
1716
use Symfony\Component\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Response;
1918

@@ -22,7 +21,7 @@
2221
*/
2322
class RequestFormat extends AbstractFormat
2423
{
25-
protected function getVarValue(Request $request, Response|null $response, ?HttpException $exception): string
24+
protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
2625
{
2726
return $request->getRequestUri();
2827
}

0 commit comments

Comments
 (0)