Passed
Pull Request — master (#19)
by Rustam
02:33
created

Target::filterMessages()   C

Complexity

Conditions 13
Paths 25

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 13

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 30
ccs 19
cts 19
cp 1
rs 6.6166
cc 13
nc 25
nop 1
crap 13

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Profiler;
6
7
/**
8
 * Target is the base class for all profiling target classes.
9
 *
10
 * A profile target object will filter the messages stored by {@see Profiler} according
11
 * to its {@see categories} and {@see except} properties.
12
 *
13
 * For more details and usage information on Target,
14
 * see the [guide article on profiling & targets](guide:runtime-profiling).
15
 */
16
abstract class Target
17
{
18
    use MessageFilterTrait;
19
    /**
20
     * @var bool whether to enable this log target. Defaults to true.
21
     */
22
    public bool $enabled = true;
23
24
    /**
25
     * Processes the given log messages.
26
     *
27
     * This method will filter the given messages with {@see levels} and {@see categories}.
28
     * And if requested, it will also export the filtering result to specific medium (e.g. email).
29
     *
30
     * @param array $messages profiling messages to be processed. See {@see Profiler::$messages} for the structure
31
     * of each message.
32
     */
33 5
    public function collect(array $messages): void
34
    {
35 5
        if (!$this->enabled) {
36 1
            return;
37
        }
38
39 5
        $messages = $this->filterMessages($messages);
40
41 5
        if (count($messages) > 0) {
42 4
            $this->export($messages);
43
        }
44 5
    }
45
46
    /**
47
     * Exports profiling messages to a specific destination.
48
     *
49
     * Child classes must implement this method.
50
     *
51
     * @param Message[] $messages profiling messages to be exported.
52
     */
53
    abstract public function export(array $messages);
54
}
55