Passed
Push — master ( 459625...480a19 )
by Aleksei
01:50
created

CachedCount   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 8
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A cacheCount() 0 6 1
A getCount() 0 3 1
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
    /**
18
     * @psalm-internal Yiisoft\Yii\Cycle\DataReader
19
     */
20
    public function getCount(): int
21
    {
22
        return $this->count ?? $this->cacheCount();
23
    }
24
    private function cacheCount(): int
25
    {
26
        /** @psalm-suppress PossiblyNullReference */
27
        $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

27
        $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...
28
        $this->collection = null;
29
        return $this->count;
30
    }
31
}
32