Completed
Push — develop ( b48d9b...a124ab )
by Paul
02:06
created

ClassLikeTrait::hasMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Model\PropertyTrait;
4
5
use Doctrine\Common\Collections\Collection;
6
use PhpUnitGen\Model\ModelInterface\FunctionModelInterface;
7
8
/**
9
 * Trait ClassLikeTrait.
10
 *
11
 * @author     Paul Thébaud <[email protected]>.
12
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
13
 * @license    https://opensource.org/licenses/MIT The MIT license.
14
 * @link       https://github.com/paul-thebaud/phpunit-generator
15
 * @since      Class available since Release 2.0.0.
16
 */
17
trait ClassLikeTrait
18
{
19
    /**
20
     * @var FunctionModelInterface[]|Collection $functions Class functions.
21
     */
22
    protected $functions;
23
24
    /**
25
     * @param FunctionModelInterface $function The function to add on this parent.
26
     */
27
    public function addFunction(FunctionModelInterface $function): void
28
    {
29
        $this->functions->add($function);
30
    }
31
32
    /**
33
     * @return FunctionModelInterface[]|Collection All the functions contained in this parent.
34
     */
35
    public function getFunctions(): Collection
36
    {
37
        return $this->functions;
38
    }
39
40
    /**
41
     * Check if a function exists.
42
     *
43
     * @param string $name The function name.
44
     *
45
     * @return bool True if it exists.
46
     */
47
    public function hasMethod(string $name): bool
48
    {
49
        return $this->functions->exists(function (FunctionModelInterface $function) use ($name) {
50
            return $function->getName() === $name;
51
        });
52
    }
53
54
    /**
55
     * @return int The number of testable (not abstract) function in this parent.
56
     */
57
    public function countNotAbstractFunctions(): int
58
    {
59
        return $this->functions->filter(function (FunctionModelInterface $function) {
60
            return ! $function->isAbstract();
61
        })->count();
62
    }
63
}
64