Completed
Push — develop ( 673784...7db882 )
by Nate
09:23
created

ResponseLoggerHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 4
dl 0
loc 32
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/restful/license
6
 * @link       https://www.flipboxfactory.com/software/restful/
7
 */
8
9
namespace flipbox\craft\restful\events;
10
11
use Craft;
12
use yii\base\Event;
13
use yii\log\Logger;
14
use yii\web\Response;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class ResponseLoggerHandler
21
{
22
    /**
23
     * @var int
24
     */
25
    public static $level = Logger::LEVEL_WARNING;
26
27
    /**
28
     * @var string
29
     */
30
    public static $category = 'application';
31
32
    /**
33
     * @param Event $event
34
     */
35
    public static function handle(Event $event)
36
    {
37
        /** @var Response $response */
38
        $response = $event->sender;
39
40
        Craft::getLogger()->log(
41
            sprintf(
42
                "Status Code = %s \n\n" .
43
                "Body = %s",
44
                $response->getStatusCode(),
45
                $response->content
46
            ),
47
            $event->data['level'] ?? static::$level,
48
            $event->data['category'] ?? static::$category
49
        );
50
    }
51
}
52