Code Duplication    Length = 20-25 lines in 6 locations

eZ/Publish/Core/Event/ContentService.php 6 locations

@@ 67-91 (lines=25) @@
64
        $this->eventDispatcher = $eventDispatcher;
65
    }
66
67
    public function createContent(
68
        ContentCreateStruct $contentCreateStruct,
69
        array $locationCreateStructs = []
70
    ): Content {
71
        $eventData = [
72
            $contentCreateStruct,
73
            $locationCreateStructs,
74
        ];
75
76
        $beforeEvent = new BeforeCreateContentEvent(...$eventData);
77
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_CREATE_CONTENT, $beforeEvent)->isPropagationStopped()) {
78
            return $beforeEvent->getContent();
79
        }
80
81
        $content = $beforeEvent->hasContent()
82
            ? $beforeEvent->getContent()
83
            : parent::createContent($contentCreateStruct, $locationCreateStructs);
84
85
        $this->eventDispatcher->dispatch(
86
            ContentEvents::CREATE_CONTENT,
87
            new CreateContentEvent($content, ...$eventData)
88
        );
89
90
        return $content;
91
    }
92
93
    public function updateContentMetadata(
94
        ContentInfo $contentInfo,
@@ 93-117 (lines=25) @@
90
        return $content;
91
    }
92
93
    public function updateContentMetadata(
94
        ContentInfo $contentInfo,
95
        ContentMetadataUpdateStruct $contentMetadataUpdateStruct
96
    ): Content {
97
        $eventData = [
98
            $contentInfo,
99
            $contentMetadataUpdateStruct,
100
        ];
101
102
        $beforeEvent = new BeforeUpdateContentMetadataEvent(...$eventData);
103
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, $beforeEvent)->isPropagationStopped()) {
104
            return $beforeEvent->getContent();
105
        }
106
107
        $content = $beforeEvent->hasContent()
108
            ? $beforeEvent->getContent()
109
            : parent::updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
110
111
        $this->eventDispatcher->dispatch(
112
            ContentEvents::UPDATE_CONTENT_METADATA,
113
            new UpdateContentMetadataEvent($content, ...$eventData)
114
        );
115
116
        return $content;
117
    }
118
119
    public function deleteContent(ContentInfo $contentInfo): array
120
    {
@@ 119-138 (lines=20) @@
116
        return $content;
117
    }
118
119
    public function deleteContent(ContentInfo $contentInfo): array
120
    {
121
        $eventData = [$contentInfo];
122
123
        $beforeEvent = new BeforeDeleteContentEvent(...$eventData);
124
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_DELETE_CONTENT, $beforeEvent)->isPropagationStopped()) {
125
            return $beforeEvent->getLocations();
126
        }
127
128
        $locations = $beforeEvent->hasLocations()
129
            ? $beforeEvent->getLocations()
130
            : parent::deleteContent($contentInfo);
131
132
        $this->eventDispatcher->dispatch(
133
            ContentEvents::DELETE_CONTENT,
134
            new DeleteContentEvent($locations, ...$eventData)
135
        );
136
137
        return $locations;
138
    }
139
140
    public function createContentDraft(
141
        ContentInfo $contentInfo,
@@ 168-192 (lines=25) @@
165
        return $contentDraft;
166
    }
167
168
    public function updateContent(
169
        VersionInfo $versionInfo,
170
        ContentUpdateStruct $contentUpdateStruct
171
    ): Content {
172
        $eventData = [
173
            $versionInfo,
174
            $contentUpdateStruct,
175
        ];
176
177
        $beforeEvent = new BeforeUpdateContentEvent(...$eventData);
178
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_UPDATE_CONTENT, $beforeEvent)->isPropagationStopped()) {
179
            return $beforeEvent->getContent();
180
        }
181
182
        $content = $beforeEvent->hasContent()
183
            ? $beforeEvent->getContent()
184
            : parent::updateContent($versionInfo, $contentUpdateStruct);
185
186
        $this->eventDispatcher->dispatch(
187
            ContentEvents::UPDATE_CONTENT,
188
            new UpdateContentEvent($content, ...$eventData)
189
        );
190
191
        return $content;
192
    }
193
194
    public function publishVersion(VersionInfo $versionInfo): Content
195
    {
@@ 194-213 (lines=20) @@
191
        return $content;
192
    }
193
194
    public function publishVersion(VersionInfo $versionInfo): Content
195
    {
196
        $eventData = [$versionInfo];
197
198
        $beforeEvent = new BeforePublishVersionEvent(...$eventData);
199
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_PUBLISH_VERSION, $beforeEvent)->isPropagationStopped()) {
200
            return $beforeEvent->getContent();
201
        }
202
203
        $content = $beforeEvent->hasContent()
204
            ? $beforeEvent->getContent()
205
            : parent::publishVersion($versionInfo);
206
207
        $this->eventDispatcher->dispatch(
208
            ContentEvents::PUBLISH_VERSION,
209
            new PublishVersionEvent($content, ...$eventData)
210
        );
211
212
        return $content;
213
    }
214
215
    public function deleteVersion(VersionInfo $versionInfo): void
216
    {
@@ 260-284 (lines=25) @@
257
        return $content;
258
    }
259
260
    public function addRelation(
261
        VersionInfo $sourceVersion,
262
        ContentInfo $destinationContent
263
    ): Relation {
264
        $eventData = [
265
            $sourceVersion,
266
            $destinationContent,
267
        ];
268
269
        $beforeEvent = new BeforeAddRelationEvent(...$eventData);
270
        if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_ADD_RELATION, $beforeEvent)->isPropagationStopped()) {
271
            return $beforeEvent->getRelation();
272
        }
273
274
        $relation = $beforeEvent->hasRelation()
275
            ? $beforeEvent->getRelation()
276
            : parent::addRelation($sourceVersion, $destinationContent);
277
278
        $this->eventDispatcher->dispatch(
279
            ContentEvents::ADD_RELATION,
280
            new AddRelationEvent($relation, ...$eventData)
281
        );
282
283
        return $relation;
284
    }
285
286
    public function deleteRelation(
287
        VersionInfo $sourceVersion,