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
    /**
48
     * @param string $name
49
     *
50
     * @return ObjectCollectionInterface
51
     */
52
    abstract protected function getCollection($name);
53
54
    public function hasRealm($name)
55
    {
56
        return $this->getRealms()->has($name);
57
    }
58
59
    /**
60
     * @param $name
61
     *
62
     * @return Contract\RealmInterface
63
     */
64
    public function getRealm($name)
65
    {
66
        return $this->getRealms()->get($name);
67
    }
68
69
    /**
70
     * @param $name
71
     */
72
    public function removeRealm($name)
73
    {
74
        $this->getRealms()->offsetUnset($name);
75
    }
76
77
    /**
78
     * @return \Generator
79
     */
80
    public function listRealms()
81
    {
82
        foreach ($this->getRealms()->getIterator() as $name => $realm) {
83
            yield $name => $realm;
84
        }
85
    }
86
87
    /**
88
     * @param ObjectCollectionInterface $realms
89
     */
90
    private function setRealms(ObjectCollectionInterface $realms)
91
    {

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
    /**
47
     * @param string $name
48
     *
49
     * @return ObjectCollectionInterface
50
     */
51
    abstract protected function getCollection($name);
52
53
    public function hasTopic($uri)
54
    {
55
        return $this->getTopics()->has($uri);
56
    }
57
58
    /**
59
     * @param string $uri
60
     *
61
     * @return Contract\TopicInterface
62
     */
63
    public function getTopic($uri)
64
    {
65
        return $this->getTopics()->get($uri);
66
    }
67
68
    /**
69
     * @param string $uri
70
     */
71
    public function removeTopic($uri)
72
    {
73
        $this->getTopics()->offsetUnset($uri);
74
    }
75
76
    /**
77
     * @return \Generator
78
     */
79
    public function listTopics()
80
    {
81
        foreach ($this->getTopics()->getIterator() as $uri => $topic) {
82
            yield $uri => $topic;
83
        }
84
    }
85
86
    /**
87
     * @param ObjectCollectionInterface $topics
88
     */
89
    private function setTopics(ObjectCollectionInterface $topics)
90
    {