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

HasMeta::getMeta()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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