Having::addCondition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Muffin\Queries\Snippets;
4
5
use Muffin\Snippet;
6
use Muffin\Condition;
7
use Muffin\Conditions;
8
use Muffin\Traits\EscaperAware;
9
use Muffin\Escaper;
10
11
class Having implements Snippet
12
{
13
    use
14
        EscaperAware;
15
16
    private
17
        $condition;
18
19 29
    public function __construct()
20
    {
21 29
        $this->condition = new Conditions\NullCondition();
22 29
    }
23
24 7
    public function having(Condition $condition)
0 ignored issues
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
25
    {
26 7
        $this->addCondition($condition);
27
28 7
        return $this;
29
    }
30
31 25
    public function toString()
32
    {
33 25
        if($this->condition->isEmpty())
34 25
        {
35 21
            return '';
36
        }
37
38 4
        return sprintf('HAVING %s', $this->condition->toString($this->escaper));
39
    }
40
41 7
    private function addCondition(Condition $condition)
42
    {
43 7
        $this->condition = $this->condition->and($condition);
0 ignored issues
show
Documentation Bug introduced by
The method and does not exist on object<Muffin\Conditions\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...
44 7
    }
45
}
46