HasProceduresTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 71
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A addProcedure() 0 4 1
A getProcedures() 0 4 1
getCollection() 0 1 ?
A hasProcedure() 0 4 1
A getProcedure() 0 4 1
A removeProcedure() 0 4 1
A listProcedures() 0 6 2
A setProcedures() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Tidal/WampWatch package.
5
 *   (c) 2016 Timo Michna <timomichna/yahoo.de>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Tidal\WampWatch\Model\Property\Collection;
13
14
use Tidal\WampWatch\Model\Contract;
15
use Tidal\WampWatch\Model\Contract\Property\ObjectCollectionInterface;
16
17
/**
18
 * Class HasProceduresTrait.
19
 *
20
 * Important! Classes using this trait have to also use trait
21
 * Tidal\WampWatch\Model\Behavior\Property\HasCollectionsTrait
22
 * for this trait to work;
23
 */
24
trait HasProceduresTrait
25
{
26
    protected static $proceduresPropertyName = 'procedures';
27
28
    /**
29
     * @var ObjectCollectionInterface
30
     */
31
    private $procedures;
32
33
    public function addProcedure(Contract\ProcedureInterface $procedure)
34
    {
35
        $this->getProcedures()->set($procedure->getUri(), $procedure);
36
    }
37
38
    /**
39
     * @return ObjectCollectionInterface
40
     */
41
    private function getProcedures()
42
    {
43
        return $this->getCollection(static::$proceduresPropertyName);
44
    }
45
46
    /**
47
     * @param string $name
48
     *
49
     * @return ObjectCollectionInterface
50
     */
51
    abstract protected function getCollection($name);
52
53
    public function hasProcedure($uri)
54
    {
55
        return $this->getProcedures()->has($uri);
56
    }
57
58
    /**
59
     * @param string $uri
60
     *
61
     * @return Contract\ProcedureInterface
62
     */
63
    public function getProcedure($uri)
64
    {
65
        return $this->getProcedures()->get($uri);
66
    }
67
68
    /**
69
     * @param string $uri
70
     */
71
    public function removeProcedure($uri)
72
    {
73
        $this->getProcedures()->offsetUnset($uri);
74
    }
75
76
    /**
77
     * @return \Generator
78
     */
79
    public function listProcedures()
80
    {
81
        foreach ($this->getProcedures()->getIterator() as $uri => $procedure) {
82
            yield $uri => $procedure;
83
        }
84
    }
85
86
    /**
87
     * @param ObjectCollectionInterface $procedures
88
     */
89
    private function setProcedures(ObjectCollectionInterface $procedures)
90
    {
91
        $this->initCollection(static::$proceduresPropertyName, $procedures);
0 ignored issues
show
Bug introduced by
It seems like initCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
92
        $procedures->setObjectConstrain(Contract\ProcedureInterface::class);
93
    }
94
}
95