Code Duplication    Length = 22-26 lines in 2 locations

src/Entities/Definitions/AbstractStructureDefinition.php 1 location

@@ 129-154 (lines=26) @@
126
     *
127
     * @return \AppserverIo\Doppelgaenger\Entities\Lists\AssertionList
128
     */
129
    public function getInvariants($nonPrivateOnly = false)
130
    {
131
        // We have to clone it here, otherwise we might have weird side effects, of having the "add()" operation
132
        // persistent on $this->ancestralInvariants
133
        $invariants = clone $this->ancestralInvariants;
134
        $invariants->add($this->invariantConditions);
135
136
        // If we need to we will filter all the non private conditions from the lists
137
        if ($nonPrivateOnly === true) {
138
            // we might want to filter invariants based on their visibility
139
            $invariantListIterator = $invariants->getIterator();
140
            foreach ($invariantListIterator as $invariantList) {
141
                // iterate all invariant lists
142
                $invariantIterator = $invariantList->getIterator();
143
                foreach ($invariantIterator as $key => $invariant) {
144
                    // iterate the actual invariants
145
                    if ($invariant->isPrivateContext()) {
146
                        $invariantList->delete($key);
147
                    }
148
                }
149
            }
150
        }
151
152
        // Return what is left
153
        return $invariants;
154
    }
155
156
    /**
157
     * Getter method for attribute $name

src/Entities/Definitions/TraitDefinition.php 1 location

@@ 131-152 (lines=22) @@
128
     *
129
     * @return \AppserverIo\Doppelgaenger\Entities\Lists\AssertionList
130
     */
131
    public function getInvariants($nonPrivateOnly = false)
132
    {
133
        // We have to clone it here, otherwise we might have weird side effects, of having the "add()" operation
134
        // persistent on $this->ancestralInvariants
135
        $invariants = clone $this->invariantConditions;
136
137
        // If we need to we will filter all the non private conditions from the lists
138
        if ($nonPrivateOnly === true) {
139
            $invariantListIterator = $invariants->getIterator();
140
            foreach ($invariantListIterator as $invariantList) {
141
                $invariantIterator = $invariantList->getIterator();
142
                foreach ($invariantIterator as $key => $invariant) {
143
                    if ($invariant->isPrivateContext()) {
144
                        $invariantList->delete($key);
145
                    }
146
                }
147
            }
148
        }
149
150
        // Return what is left
151
        return $invariants;
152
    }
153
154
    /**
155
     * Getter method for attribute $invariantConditions