RedirectTarget   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 43
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setTargets() 0 4 1
A getTargets() 0 4 1
A export() 0 9 2
A getTarget() 0 4 1
A getModule() 0 4 1
A getContextMessage() 0 4 1
1
<?php
2
/**
3
 * Health monitoring for Yii2 applications
4
 *
5
 * @link      https://github.com/hiqdev/yii2-monitoring
6
 * @package   yii2-monitoring
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\monitoring\targets;
12
13
use hiqdev\yii2\monitoring\Module;
14
use yii\log\Target;
15
16
/**
17
 * RedirectTarget redirects output to listed targets.
18
 */
19
class RedirectTarget extends \yii\log\Target
20
{
21
    protected $targets = [];
22
23
    public function setTargets($list)
24
    {
25
        $this->targets = $list;
26
    }
27
28
    public function getTargets()
29
    {
30
        return $this->targets;
31
    }
32
33
    public function export()
34
    {
35
        foreach ($this->getTargets() as $name) {
36
            $target = $this->getTarget($name);
37
            $target->messages = array_merge($target->messages, $this->messages);
38
            $target->export();
39
            $target->messages = [];
40
        }
41
    }
42
43
    /**
44
     * @param $name
45
     * @return Target
46
     */
47
    public function getTarget($name)
48
    {
49
        return $this->getModule()->getTarget($name);
50
    }
51
52
    public function getModule()
53
    {
54
        return Module::getInstance();
55
    }
56
57
    protected function getContextMessage()
58
    {
59
        return '';
60
    }
61
}
62