Timer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A report() 0 6 1
1
<?php
2
namespace Bookdown\Bookdown\Service;
3
4
use Psr\Log\LoggerInterface;
5
6
class Timer
7
{
8
    protected $start;
9
10 3
    public function __construct(LoggerInterface $logger)
11
    {
12 3
        $this->logger = $logger;
0 ignored issues
show
Bug introduced by
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13 3
        $this->start = microtime(true);
14 3
    }
15
16 1
    public function report()
17
    {
18 1
        $seconds = microtime(true) - $this->start;
19 1
        $seconds = trim(sprintf("%10.2f", $seconds));
20 1
        $this->logger->info("Completed in {$seconds} seconds.");
21 1
    }
22
}
23