Passed
Push — master ( 5e9dce...cb103f )
by Aleksei
02:54
created

CachedCount   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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\Data\Reader\Cache;
6
7
use Countable;
8
9
final class CachedCount
10
{
11
    private ?int $count = null;
12
    private ?Countable $collection;
13
14 17
    public function __construct(Countable $collection)
15
    {
16 17
        $this->collection = $collection;
17
    }
18
19
    /**
20
     * @psalm-internal Yiisoft\Yii\Cycle\Data\Reader
21
     */
22 1
    public function getCount(): int
23
    {
24 1
        return $this->count ?? $this->cacheCount();
25
    }
26
27 1
    private function cacheCount(): int
28
    {
29
        /** @psalm-suppress PossiblyNullReference */
30 1
        $this->count = $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

30
        /** @scrutinizer ignore-call */ 
31
        $this->count = $this->collection->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...
31 1
        $this->collection = null;
32 1
        return $this->count;
33
    }
34
}
35