PublicScope   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Comment\Scope;
6
7
use Cycle\ORM\Select\ConstrainInterface;
8
use Cycle\ORM\Select\QueryBuilder;
9
10
/**
11
 * Not deleted
12
 * Public with condition
13
 * Sorted
14
 */
15
class PublicScope implements ConstrainInterface
16
{
17
    private ?array $publicOrCondition;
18
19 1
    public function __construct(?array $publicOrCondition = null)
20
    {
21 1
        $this->publicOrCondition = $publicOrCondition;
22 1
    }
23
24 1
    public function apply(QueryBuilder $query): void
25
    {
26
        // public or...
27 1
        if ($this->publicOrCondition !== null) {
28
            $query->where([
29
                '@or' => [
30
                    ['public' => true],
31
                    $this->publicOrCondition,
32
                ],
33
            ]);
34
        } else {
35 1
            $query->andWhere('public', '=', true);
36
        }
37
        // sort
38 1
        $query->orderBy('published_at', 'DESC');
39 1
    }
40
}
41