detail.php ➔ formatDataString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 4
dl 0
loc 1
ccs 0
cts 0
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/* @var $panel yii\debug\panels\LogPanel */
3
4
use yii\helpers\Html;
5
use bedezign\yii2\audit\components\Helper;
6
use bedezign\yii2\audit\components\web\Helper as WebHelper;
7
8 3
if (!function_exists('formatDataString')) {
9
    function formatDataString($types, $data, $preformatted, &$tabs) { foreach ($types as $function => $title) { $result = Helper::$function($data); if ($result) { $tabs[] = ['label' => $title, 'content' => Html::tag('div', $result, $preformatted)]; break; }}}
10 3
}
11
12 3
$post    = empty($request['post']) ? false : $request['post'];
13 3
$headers = empty($request['headers']) ? false : $request['headers'];
14 3
$content = empty($request['content']) ? false : $request['content'];
15 3
$log     = empty($request['log']) ? false : $request['log'];
16 3
unset($request['post'], $request['content'], $request['headers'], $request['log']);
17
18 3
$preformatted = ['class' => 'well', 'style' => 'overflow: auto; white-space: pre'];
19 3
$formatter = \Yii::$app->formatter;
20
21
$tabs = [
22
    [
23 3
        'label' => \Yii::t('audit', 'Info'),
24 3
        'content' => $this->render('info_table', ['request' => $request]),
25
        'active' => true
26 3
    ]
27 3
];
28
29 3
if ($post) {
30
    $tabs[] = [
31
        'label' => \Yii::t('audit', 'POST'),
32
        'content' => Html::tag('div', $post, $preformatted)
33
    ];
34
    formatDataString(
35
        ['formatAsQuery' => \Yii::t('audit', 'POST - Query'), 'formatAsJSON' => \Yii::t('audit', 'POST - JSON'),
36
            'formatAsXML' => \Yii::t('audit', 'POST - XML'), 'formatAsHTML' => \Yii::t('audit', 'POST - HTML')],
37
        $post, $preformatted, $tabs
38
    );
39
}
40
41
if ($headers)
42 3
    $tabs[] = [
43 3
        'label' => \Yii::t('audit', 'Headers'),
44 3
        'content' => Html::tag('div', $formatter->asNtext(implode('', $headers)), ['class' => 'well'])
45 3
    ];
46
47 3
if ($content) {
48 3
    $tabs[] = [
49 3
        'label' => \Yii::t('audit', 'Content'),
50 3
        'content' => Html::tag('div', $formatter->asText($content), $preformatted)
51 3
    ];
52 3
    formatDataString(
53 3
        ['formatAsQuery' => \Yii::t('audit', 'Content - Query'), 'formatAsJSON' => \Yii::t('audit', 'Content - JSON'),
54 3
            'formatAsXML' => \Yii::t('audit', 'Content - XML'), 'formatAsHTML' => \Yii::t('audit', 'Content - HTML')],
55 3
        $content, $preformatted, $tabs
56 3
    );
57 3
}
58
59
if ($log)
60 3
    $tabs[] = [
61 3
        'label' => \Yii::t('audit', 'Log'),
62 3
        'content' => Html::tag('div', $formatter->asText($log), $preformatted)
63 3
    ];
64
65
66 3
echo Html::tag('h2', \Yii::t('audit', 'Request #{id}', ['id' => $index])),
67
        WebHelper::bootstrap('Tabs', 'widget', ['items' => $tabs]);
68