Code Duplication    Length = 35-37 lines in 3 locations

Core/Executor/ContentTypeGroupManager.php 1 location

@@ 119-155 (lines=37) @@
116
     * @param ContentTypeGroup|ContentTypeGroupCollection $object
117
     * @return bool
118
     */
119
    protected function setReferences($object, $step)
120
    {
121
        if (!array_key_exists('references', $step->dsl)) {
122
            return false;
123
        }
124
125
        if ($object instanceof ContentTypeGroupCollection) {
126
            if (count($object) > 1) {
127
                throw new \InvalidArgumentException('Content Type Group Manager does not support setting references for creating/updating of multiple Content Type Groups');
128
            }
129
            $object = reset($object);
130
        }
131
132
        foreach ($step->dsl['references'] as $reference) {
133
134
            switch ($reference['attribute']) {
135
                case 'content_type_group_id':
136
                case 'id':
137
                    $value = $object->id;
138
                    break;
139
                case 'content_type_group_identifier':
140
                case 'identifier':
141
                    $value = $object->identifier;
142
                    break;
143
                default:
144
                    throw new \InvalidArgumentException('Content Type Group Manager does not support setting references for attribute ' . $reference['attribute']);
145
            }
146
147
            $overwrite = false;
148
            if (isset($reference['overwrite'])) {
149
                $overwrite = $reference['overwrite'];
150
            }
151
            $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite);
152
        }
153
154
        return true;
155
    }
156
157
    /**
158
     * @param array $matchCondition

Core/Executor/RoleManager.php 1 location

@@ 164-199 (lines=36) @@
161
     * @throws \InvalidArgumentException When trying to assign a reference to an unsupported attribute
162
     * @return boolean
163
     */
164
    protected function setReferences($role, $step)
165
    {
166
        if (!array_key_exists('references', $step->dsl)) {
167
            return false;
168
        }
169
170
        if ($role instanceof RoleCollection) {
171
            if (count($role) > 1) {
172
                throw new \InvalidArgumentException('Role Manager does not support setting references for creating/updating of multiple roles');
173
            }
174
            $role = reset($role);
175
        }
176
177
        foreach ($step->dsl['references'] as $reference) {
178
            switch ($reference['attribute']) {
179
                case 'role_id':
180
                case 'id':
181
                    $value = $role->id;
182
                    break;
183
                case 'identifier':
184
                case 'role_identifier':
185
                    $value = $role->identifier;
186
                    break;
187
                default:
188
                    throw new \InvalidArgumentException('Role Manager does not support setting references for attribute ' . $reference['attribute']);
189
            }
190
191
            $overwrite = false;
192
            if (isset($reference['overwrite'])) {
193
                $overwrite = $reference['overwrite'];
194
            }
195
            $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite);
196
        }
197
198
        return true;
199
    }
200
201
    /**
202
     * @param array $matchCondition

Core/Executor/UserGroupManager.php 1 location

@@ 191-225 (lines=35) @@
188
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup|UserGroupCollection $userGroup
189
     * @return boolean
190
     */
191
    protected function setReferences($userGroup, $step)
192
    {
193
        if (!array_key_exists('references', $step->dsl)) {
194
            return false;
195
        }
196
197
        if ($userGroup instanceof UserGroupCollection) {
198
            if (count($userGroup) > 1) {
199
                throw new \InvalidArgumentException('UserGroup Manager does not support setting references for creating/updating of multiple groups');
200
            }
201
            $userGroup = reset($userGroup);
202
        }
203
204
        foreach ($step->dsl['references'] as $reference) {
205
206
            switch ($reference['attribute']) {
207
                case 'object_id':
208
                case 'content_id':
209
                case 'user_group_id':
210
                case 'id':
211
                    $value = $userGroup->id;
212
                    break;
213
                default:
214
                    throw new \InvalidArgumentException('User Group Manager does not support setting references for attribute ' . $reference['attribute']);
215
            }
216
217
            $overwrite = false;
218
            if (isset($reference['overwrite'])) {
219
                $overwrite = $reference['overwrite'];
220
            }
221
            $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite);
222
        }
223
224
        return true;
225
    }
226
227
    protected function setSection(Content $content, $sectionKey)
228
    {