Passed
Push — master ( 9eb36d...479891 )
by Artem
01:50
created

HasMeta   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMeta() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Prozorov\Repositories\Traits;
6
7
use Prozorov\Repositories\Query;
8
9
trait HasMeta
10
{
11
    /**
12
     * Calculate meta information
13
     * 
14
     * @access	protected
15
     * @param	Query	$query
16
     * @return	array|null
17
     */
18 2
    protected function getMeta(Query $query): ?array
19
    {
20 2
        if ($query->isWithMeta()) {
21
            $meta = [
22 1
                'offset' => $query->getOffset(),
23 1
                'limit' => $query->getLimit(),
24
            ];
25
26 1
            if ($query->isCountTotal()) {
27 1
                $meta['total'] = $this->count($query->getWhere() ?? []);
0 ignored issues
show
Bug introduced by
It seems like count() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
                /** @scrutinizer ignore-call */ 
28
                $meta['total'] = $this->count($query->getWhere() ?? []);
Loading history...
28
            }
29
        }
30
31 2
        return $meta ?? null;
32
    }
33
}
34