Dependency   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 28
c 1
b 0
f 0
dl 0
loc 101
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 3
A duration() 0 3 1
A startTime() 0 3 1
A command() 0 3 1
A type() 0 3 1
A isSuccessful() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of slick/telemetry package
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
 * Dependency
19
 *
20
 * @package Slick\Telemetry\Model
21
 */
22
final class Dependency implements Trackable
23
{
24
    use TrackableMethods;
25
26
    private string $type;
27
    private ?string $command;
28
    private ?int $startTime;
29
    /**
30
     * @var float|int|null
31
     */
32
    private $duration;
33
    private ?bool $successful;
34
35
    /**
36
     * Creates a Dependency
37
     *
38
     * @param string $message
39
     * @param string $type
40
     * @param string|null $command
41
     * @param int|null $startTime
42
     * @param float|null $duration
43
     * @param bool|null $successful
44
     * @param iterable|null $context
45
     */
46
    public function __construct(
47
        string $message,
48
        string $type,
49
        ?string $command = null,
50
        ?int $startTime = null,
51
        float $duration = 0,
52
        bool $successful = true,
53
        iterable $context = []
54
    ) {
55
        $this->message = $message;
56
        $this->type = $type ?: time();
57
        $this->command = $command;
58
        $this->startTime = $startTime;
59
        $this->duration = $duration;
60
        $this->successful = $successful;
61
        $this->label = Trackable::LABEL_DEPENDENCY;
62
        $this->context = array_merge($context, [
0 ignored issues
show
Bug introduced by
It seems like $context can also be of type iterable; however, parameter $arrays of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        $this->context = array_merge(/** @scrutinizer ignore-type */ $context, [
Loading history...
63
            'label' => Trackable::LABEL_DEPENDENCY,
64
            'type' => $type,
65
            'command' => $command,
66
            'startTime' => $startTime,
67
            'duration' => $duration,
68
            'isSuccessful' => $successful
69
        ]);
70
        if (!$successful) {
71
            $this->logLevel = LogLevel::WARNING;
72
        }
73
    }
74
75
    /**
76
     * type
77
     *
78
     * @return string
79
     */
80
    public function type(): string
81
    {
82
        return $this->type;
83
    }
84
85
    /**
86
     * command
87
     *
88
     * @return string|null
89
     */
90
    public function command(): ?string
91
    {
92
        return $this->command;
93
    }
94
95
    /**
96
     * Command start timestamp
97
     *
98
     * @return int
99
     */
100
    public function startTime(): int
101
    {
102
        return $this->startTime;
103
    }
104
105
    /**
106
     * Command/dependency execution duration
107
     *
108
     * @return float
109
     */
110
    public function duration(): float
111
    {
112
        return $this->duration;
113
    }
114
115
    /**
116
     * successful
117
     *
118
     * @return bool
119
     */
120
    public function isSuccessful(): ?bool
121
    {
122
        return $this->successful;
123
    }
124
}
125