TrackableMethods   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 2
b 0
f 0
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A label() 0 3 1
A context() 0 3 1
A message() 0 3 1
A withContext() 0 5 1
A logLevel() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Telemetry
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Telemetry\Model;
13
14
use Psr\Log\LogLevel;
15
use Slick\Telemetry\Trackable;
16
17
/**
18
 * TrackableMethods trait
19
 *
20
 * @package Slick\Telemetry\Model
21
 */
22
trait TrackableMethods
23
{
24
    protected string $message;
25
    protected iterable $context;
26
    protected string $logLevel = LogLevel::INFO;
27
    protected string $label = Trackable::LABEL_MISC;
28
29
    /**
30
     * A brief log message
31
     *
32
     * @return string
33
     */
34
    public function message(): string
35
    {
36
        return $this->message;
37
    }
38
39
    /**
40
     * A list of key/value pairs defining trackable context
41
     *
42
     * @return iterable
43
     */
44
    public function context(): iterable
45
    {
46
        return $this->context;
47
    }
48
49
    /**
50
     * Returns a new object with provided context
51
     *
52
     * @param iterable $context
53
     * @return Trackable
54
     */
55
    public function withContext(iterable $context): Trackable
56
    {
57
        $clone = clone $this;
58
        $clone->context = $context;
59
        return $clone;
60
    }
61
62
    /**
63
     * Trackable log level
64
     *
65
     * @return string
66
     */
67
    public function logLevel(): string
68
    {
69
        return $this->logLevel;
70
    }
71
72
    /**
73
     * type
74
     *
75
     * @return string
76
     */
77
    public function label(): string
78
    {
79
        return $this->label;
80
    }
81
}
82