Timer::report()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 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