Passed
Push — master ( d62147...276eed )
by Alexander
02:12
created

CachedCount::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\DataReader\Cache;
6
7
use Countable;
8
9
final class CachedCount
10
{
11
    private ?int $count = null;
12
    private ?Countable $collection;
13
    public function __construct(Countable $collection)
14
    {
15
        $this->collection = $collection;
16
    }
17
    public function getCount(): int
18
    {
19
        if ($this->count === null) {
20
            $this->count = (int) $this->collection->count();
0 ignored issues
show
Bug introduced by
The method count() does not exist on null. ( Ignorable by Annotation )

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

20
            $this->count = (int) $this->collection->/** @scrutinizer ignore-call */ count();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
            $this->collection = null;
22
        }
23
        return $this->count;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->count could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
24
    }
25
}
26