Passed
Push — master ( 5b5712...bd91f9 )
by Stanislau
01:18 queued 13s
created

RequestBodyFormat::getVarValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 35
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 34
c 1
b 1
f 0
dl 0
loc 41
ccs 35
cts 35
cp 1
rs 9.376
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
19
/**
20
 * @author Stanislau Komar <[email protected]>
21
 */
22
class RequestBodyFormat extends AbstractFormat
23
{
24 35
    protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
25
    {
26 35
        $type = (string) $request->headers->get('Content-Type');
27
28 35
        return match ($type) {
29 35
            'application/EDI-X12', 'application/javascript', 'application/EDIFACT', 'application/xhtml+xml' => sprintf('~%s Content~', $this->getTypeFrontName($type)),
30 35
            'application/zip' => '~ZIP Binary~',
31 35
            'application/x-shockwave-flash' => '~FLASH Binary~',
32 35
            'application/pdf' => '~PDF Binary~',
33 35
            'application/ogg' => 'OGG Binary',
34 35
            'audio/mpeg',
35 35
            'audio/x-ms-wma',
36 35
            'audio/vnd.rn-realaudio',
37 35
            'audio/x-wav' => sprintf('~Audio %s content~', $this->getTypeFrontName($type)),
38
39 35
            'application/vnd.oasis.opendocument.text',
40 35
            'application/vnd.oasis.opendocument.spreadsheet',
41 35
            'application/vnd.oasis.opendocument.presentation',
42 35
            'application/vnd.oasis.opendocument.graphics',
43 35
            'application/vnd.ms-excel',
44 35
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
45 35
            'application/vnd.ms-powerpoint',
46 35
            'application/vnd.openxmlformats-officedocument.presentationml.presentation',
47 35
            'application/msword',
48 35
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
49 35
            'application/vnd.mozilla.xul+xml' => sprintf('~VND %s~', $this->getTypeFrontName($type)),
50
51 35
            'video/mpeg',
52 35
            'video/mp4',
53 35
            'video/quicktime',
54 35
            'video/x-ms-wmv',
55 35
            'video/x-msvideo',
56 35
            'video/x-flv',
57 35
            'video/webm' => sprintf('~Video %s~', $this->getTypeFrontName($type)),
58
59 35
            'multipart/form-data',
60 35
            'multipart/mixed',
61 35
            'multipart/alternative',
62 35
            'multipart/related' => sprintf('~Multipart %s~', $this->getTypeFrontName($type)),
63
64 35
            default => $request->getContent(),
65 35
        };
66
    }
67
68 35
    protected function getVarName(): string
69
    {
70 35
        return 'request_body';
71
    }
72
73 30
    private function getTypeFrontName(string $type): string
74
    {
75 30
        $exploded = explode('/', $type);
76
77 30
        return mb_convert_case(array_pop($exploded), \MB_CASE_TITLE);
78
    }
79
}
80