Code Duplication    Length = 23-25 lines in 2 locations

Bundle/BusinessEntityBundle/EventSubscriber/BusinessEntitySubscriber.php 2 locations

@@ 175-199 (lines=25) @@
172
            $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
173
            //find all BT that can represent the businessEntity
174
            $businessTemplates = $em->getRepository('VictoireBusinessPageBundle:BusinessTemplate')->findPagePatternByBusinessEntity($businessEntity);
175
            foreach ($businessTemplates as $businessTemplate) {
176
                // Generate a viewReference for each BT translation
177
                foreach ($businessTemplate->getTranslations() as $translation) {
178
                    $businessTemplate->setCurrentLocale($translation->getLocale());
179
180
                    if ($page = $em->getRepository(
181
                        'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage'
182
                    )->findPageByBusinessEntityAndPattern($businessTemplate, $entity, $businessEntity)
183
                    ) {
184
                        //if it's a BP we update the BP
185
                        $this->businessPageBuilder->updatePageParametersByEntity($page, $entity);
186
                    } else {
187
                        $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
188
                            $businessTemplate,
189
                            $entity,
190
                            $em
191
                        );
192
                    }
193
                    if ($this->businessPageHelper->isEntityAllowed($businessTemplate, $entity, $em)) {
194
                        //update the reference
195
                        $event = new ViewReferenceEvent($page);
196
                        $this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event);
197
                    }
198
                }
199
            }
200
        }
201
202
        foreach ($this->flushedBusinessTemplates as $entity) {
@@ 209-231 (lines=23) @@
206
            //find all entities
207
            $entities = $this->businessPageHelper->getEntitiesAllowed($entity, $em);
208
            // Generate a viewReference for each BT translation
209
            foreach ($entity->getTranslations() as $translation) {
210
                $entity->setCurrentLocale($translation->getLocale());
211
                foreach ($entities as $be) {
212
                    if ($this->businessPageHelper->isEntityAllowed($entity, $be, $em)) {
213
                        if ($page = $em->getRepository(
214
                            'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage'
215
                        )->findPageByBusinessEntityAndPattern($entity, $be, $businessEntity)
216
                        ) {
217
                            //rebuild page if its a BP
218
                            $this->businessPageBuilder->updatePageParametersByEntity($page, $be);
219
                        } else {
220
                            $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
221
                                $entity,
222
                                $be,
223
                                $em
224
                            );
225
                        }
226
                        // update reference
227
                        $event = new ViewReferenceEvent($page);
228
                        $this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event);
229
                    }
230
                }
231
            }
232
        }
233
        $this->flushedBusinessEntities->clear();
234
        $this->flushedBusinessTemplates->clear();