Having   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A having() 0 6 1
A toString() 0 9 2
A addCondition() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
use Puzzle\QueryBuilder\Condition;
9
use Puzzle\QueryBuilder\Conditions;
10
use Puzzle\QueryBuilder\Traits\EscaperAware;
11
use Puzzle\QueryBuilder\Escaper;
12
13
class Having implements Snippet
14
{
15
    use
16
        EscaperAware;
17
18
    private
19
        $condition;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $condition.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
20
21 29
    public function __construct()
22
    {
23 29
        $this->condition = new Conditions\NullCondition();
24 29
    }
25
26 7
    public function having(Condition $condition): self
27
    {
28 7
        $this->addCondition($condition);
29
30 7
        return $this;
31
    }
32
33 25
    public function toString(): string
34
    {
35 25
        if($this->condition->isEmpty())
36
        {
37 21
            return '';
38
        }
39
40 4
        return sprintf('HAVING %s', $this->condition->toString($this->escaper));
41
    }
42
43 7
    private function addCondition(Condition $condition): void
44
    {
45 7
        $this->condition = $this->condition->and($condition);
0 ignored issues
show
Documentation Bug introduced by
The method and does not exist on object<Puzzle\QueryBuild...nditions\NullCondition>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
46 7
    }
47
}
48