Code Duplication    Length = 22-25 lines in 2 locations

Moss/Storage/Query/Relation/ManyTroughRelation.php 1 location

@@ 149-173 (lines=25) @@
146
     * @return array|\ArrayAccess
147
     * @throws RelationException
148
     */
149
    public function delete(&$result)
150
    {
151
        $container = $this->accessor->getPropertyValue($result, $this->definition->container());
152
        if (empty($container)) {
153
            return $result;
154
        }
155
156
        foreach ($container as $entity) {
157
            $mediator = [];
158
159
            foreach ($this->definition->localKeys() as $local => $foreign) {
160
                $mediator[$foreign] = $this->accessor->getPropertyValue($result, $local);
161
            }
162
163
            foreach ($this->definition->foreignKeys() as $foreign => $local) {
164
                $mediator[$foreign] = $this->accessor->getPropertyValue($entity, $local);
165
            }
166
167
            $this->storage->delete($mediator, $this->definition->mediator())->execute();
168
169
        }
170
        $this->accessor->setPropertyValue($result, $this->definition->container(), $container);
171
172
        return $result;
173
    }
174
}
175

Moss/Storage/Query/Relation/OneTroughRelation.php 1 location

@@ 124-145 (lines=22) @@
121
     *
122
     * @return array|\ArrayAccess
123
     */
124
    public function delete(&$result)
125
    {
126
        $entity = $this->accessor->getPropertyValue($result, $this->definition->container());
127
        if (empty($entity)) {
128
            return $result;
129
        }
130
131
        $mediator = [];
132
133
        foreach ($this->definition->localKeys() as $entityField => $mediatorField) {
134
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($result, $entityField);
135
        }
136
137
        foreach ($this->definition->foreignKeys() as $mediatorField => $entityField) {
138
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($entity, $entityField);
139
        }
140
141
        $this->storage->delete($mediator, $this->definition->mediator())->execute();
142
        $this->accessor->setPropertyValue($result, $this->definition->container(), $entity);
143
144
        return $result;
145
    }
146
}
147