SoapPanel::logSoapRequest()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 1
dl 0
loc 13
ccs 0
cts 10
cp 0
crap 20
rs 9.8333
c 0
b 0
f 0
1
<?php
2
namespace bedezign\yii2\audit\panels;
3
4
use Yii;
5
use bedezign\yii2\audit\models\AuditError;
6
use bedezign\yii2\audit\components\panels\DataStoragePanel;
7
use yii\data\ArrayDataProvider;
8
9
/**
10
 * Class CurlPanel
11
 * @package bedezign\yii2\audit\src\panels
12
 */
13
class SoapPanel extends DataStoragePanel
14
{
15
    public function getName()
16
    {
17
        return Yii::t('audit', 'SOAP');
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getLabel()
24
    {
25
        return $this->getName() . ' <small>(' . count($this->data) . ')</small>';
26
    }
27
28
    /**
29
     * Receives a bunch of information about a SOAP request and logs it.
30
     * If you are unable to use the modules' SoapClient class you can call this function manually to log the data.
31
     *
32
     * @param array $data
33
     */
34
    public function logSoapRequest($data)
35
    {
36
        $this->module->registerPanel($this);
37
38
        if (!is_array($this->data))
39
            $this->data = [];
40
41
        if (isset($data['error'])) {
42
            $error = $this->module->exception($data['error']);
43
            $data['error'] = [$data['error']->faultcode, $error ? $error->id : null];
44
        }
45
        $this->data[] = array_filter($data);
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function save()
52
    {
53
        return $this->data;
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function getDetail()
60
    {
61
        $dataProvider = new ArrayDataProvider();
62
        $dataProvider->allModels = $this->data;
63
64
        return Yii::$app->view->render('panels/soap/index', [
65
            'panel'        => $this,
66
            'dataProvider' => $dataProvider,
67
        ]);
68
    }
69
}