Code Duplication    Length = 64-64 lines in 2 locations

src/Tidal/WampWatch/Model/Property/Collection/HasRealmsTrait.php 1 location

@@ 25-88 (lines=64) @@
22
 * Tidal\WampWatch\Model\Behavior\Property\HasCollectionsTrait
23
 * for this trait to work;
24
 */
25
trait HasRealmsTrait
26
{
27
    protected $realmsPropertyName = 'realms';
28
29
    /**
30
     * @var ObjectCollectionInterface
31
     */
32
    private $realms;
33
34
    public function addRealm(Contract\RealmInterface $realm)
35
    {
36
        $this->getRealms()->set($realm->getName(), $realm);
37
    }
38
39
    /**
40
     * @return ObjectCollectionInterface
41
     */
42
    private function getRealms()
43
    {
44
        return $this->getCollection($this->realmsPropertyName);
45
    }
46
47
    public function hasRealm($name)
48
    {
49
        return $this->getRealms()->has($name);
50
    }
51
52
    /**
53
     * @param $name
54
     *
55
     * @return Contract\RealmInterface
56
     */
57
    public function getRealm($name)
58
    {
59
        return $this->getRealms()->get($name);
60
    }
61
62
    /**
63
     * @param $name
64
     */
65
    public function removeRealm($name)
66
    {
67
        $this->getRealms()->offsetUnset($name);
68
    }
69
70
    /**
71
     * @return \Generator
72
     */
73
    public function listRealms()
74
    {
75
        foreach ($this->getRealms()->getIterator() as $name => $realm) {
76
            yield $name => $realm;
77
        }
78
    }
79
80
    /**
81
     * @param ObjectCollectionInterface $realms
82
     */
83
    private function setRealms(ObjectCollectionInterface $realms)
84
    {
85
        $this->initCollection($this->realmsPropertyName, $realms);
86
        $realms->setObjectConstrain(RealmInterface::class);
87
    }
88
}
89

src/Tidal/WampWatch/Model/Property/Collection/HasTopicsTrait.php 1 location

@@ 24-87 (lines=64) @@
21
 * Tidal\WampWatch\Model\Behavior\Property\HasCollectionsTrait
22
 * for this trait to work;
23
 */
24
trait HasTopicsTrait
25
{
26
    protected $topicsPropertyName = 'topics';
27
28
    /**
29
     * @var ObjectCollectionInterface
30
     */
31
    private $topics;
32
33
    public function addTopic(Contract\TopicInterface $topic)
34
    {
35
        $this->getTopics()->set($topic->getUri(), $topic);
36
    }
37
38
    /**
39
     * @return ObjectCollectionInterface
40
     */
41
    private function getTopics()
42
    {
43
        return $this->getCollection($this->topicsPropertyName);
44
    }
45
46
    public function hasTopic($uri)
47
    {
48
        return $this->getTopics()->has($uri);
49
    }
50
51
    /**
52
     * @param string $uri
53
     *
54
     * @return Contract\TopicInterface
55
     */
56
    public function getTopic($uri)
57
    {
58
        return $this->getTopics()->get($uri);
59
    }
60
61
    /**
62
     * @param string $uri
63
     */
64
    public function removeTopic($uri)
65
    {
66
        $this->getTopics()->offsetUnset($uri);
67
    }
68
69
    /**
70
     * @return \Generator
71
     */
72
    public function listTopics()
73
    {
74
        foreach ($this->getTopics()->getIterator() as $uri => $topic) {
75
            yield $uri => $topic;
76
        }
77
    }
78
79
    /**
80
     * @param ObjectCollectionInterface $topics
81
     */
82
    private function setTopics(ObjectCollectionInterface $topics)
83
    {
84
        $this->initCollection($this->topicsPropertyName, $topics);
85
        $topics->setObjectConstrain(Contract\TopicInterface::class);
86
    }
87
}
88