Stopwatch::stop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 2
eloc 3
c 2
b 1
f 1
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright (c) 2024 TEQneers GmbH & Co. KG
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE.md file that was distributed with this source code.
10
 *
11
 * @see https://github.com/teqneers/phpunit-stopwatch
12
 */
13
14
namespace TQ\Testing\Extension\Stopwatch;
15
16
final class Stopwatch
17
{
18
    private static ?TimingCollector $collector = null;
19
20
    /**
21
     * @psalm-suppress UnusedConstructor
22
     */
23
    private function __construct()
24
    {
25
        // static class
26
    }
27
28 28
    public static function init(TimingCollector $collector): void
29
    {
30 28
        self::$collector = $collector;
31
    }
32
33 23
    public static function start(string $name): void
34
    {
35
        // ignore if already started
36 23
        if (!self::$collector || self::$collector->isStarted($name)) {
37 2
            return;
38
        }
39
40 23
        self::$collector->start($name);
41
    }
42
43 17
    public static function stop(string $name, bool $force = false): void
44
    {
45 17
        if (!self::$collector) {
46
            return;
47
        }
48
49 17
        self::$collector->stop($name, $force);
50
    }
51
}
52