Completed
Push — master ( 9b6067...64e7c9 )
by Nicolas
03:06
created

EntryController   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 594
Duplicated Lines 11.45 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
wmc 56
lcom 1
cbo 13
dl 68
loc 594
rs 6.5957
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
B searchFormAction() 0 20 5
B addEntryFormAction() 0 36 4
A addEntryViaBookmarkletAction() 0 18 2
A addEntryAction() 0 4 1
A showAllAction() 0 4 1
A showUnreadAction() 0 9 3
A showArchiveAction() 0 4 1
A showStarredAction() 0 4 1
A viewAction() 0 9 1
B reloadAction() 0 24 2
A toggleArchiveAction() 21 21 2
B editEntryAction() 25 25 3
B deleteEntryAction() 0 32 2
A shareAction() 0 16 2
A deleteShareAction() 0 14 1
A shareEntryAction() 0 11 2
A showUntaggedEntriesAction() 0 4 1
A toggleStarAction() 22 22 2
B updateEntry() 0 25 4
C showEntries() 0 63 12
A checkUserAction() 0 6 3
A checkIfEntryAlreadyExists() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EntryController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EntryController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Wallabag\CoreBundle\Controller;
4
5
use Pagerfanta\Adapter\DoctrineORMAdapter;
6
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12
use Wallabag\CoreBundle\Entity\Entry;
13
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
14
use Wallabag\CoreBundle\Event\EntrySavedEvent;
15
use Wallabag\CoreBundle\Form\Type\EditEntryType;
16
use Wallabag\CoreBundle\Form\Type\EntryFilterType;
17
use Wallabag\CoreBundle\Form\Type\NewEntryType;
18
use Wallabag\CoreBundle\Form\Type\SearchEntryType;
19
20
class EntryController extends Controller
21
{
22
    /**
23
     * @param Request $request
24
     * @param int     $page
25
     *
26
     * @Route("/search/{page}", name="search", defaults={"page" = 1})
27
     *
28
     * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
29
     * because this controller is also called inside the layout template without any page as argument
30
     *
31
     * @return \Symfony\Component\HttpFoundation\Response
32
     */
33
    public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
34
    {
35
        // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
36
        if (null === $currentRoute && $request->query->has('currentRoute')) {
37
            $currentRoute = $request->query->get('currentRoute');
38
        }
39
40
        $form = $this->createForm(SearchEntryType::class);
41
42
        $form->handleRequest($request);
43
44
        if ($form->isSubmitted() && $form->isValid()) {
45
            return $this->showEntries('search', $request, $page);
46
        }
47
48
        return $this->render('WallabagCoreBundle:Entry:search_form.html.twig', [
49
            'form' => $form->createView(),
50
            'currentRoute' => $currentRoute,
51
        ]);
52
    }
53
54
    /**
55
     * @param Request $request
56
     *
57
     * @Route("/new-entry", name="new_entry")
58
     *
59
     * @return \Symfony\Component\HttpFoundation\Response
60
     */
61
    public function addEntryFormAction(Request $request)
62
    {
63
        $entry = new Entry($this->getUser());
0 ignored issues
show
Documentation introduced by
$this->getUser() is of type null|object, but the function expects a object<Wallabag\UserBundle\Entity\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
65
        $form = $this->createForm(NewEntryType::class, $entry);
66
67
        $form->handleRequest($request);
68
69
        if ($form->isSubmitted() && $form->isValid()) {
70
            $existingEntry = $this->checkIfEntryAlreadyExists($entry);
71
72
            if (false !== $existingEntry) {
73
                $this->get('session')->getFlashBag()->add(
74
                    'notice',
75
                    $this->get('translator')->trans('flashes.entry.notice.entry_already_saved', ['%date%' => $existingEntry->getCreatedAt()->format('d-m-Y')])
76
                );
77
78
                return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
79
            }
80
81
            $this->updateEntry($entry);
82
83
            $em = $this->getDoctrine()->getManager();
84
            $em->persist($entry);
85
            $em->flush();
86
87
            // entry saved, dispatch event about it!
88
            $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
89
90
            return $this->redirect($this->generateUrl('homepage'));
91
        }
92
93
        return $this->render('WallabagCoreBundle:Entry:new_form.html.twig', [
94
            'form' => $form->createView(),
95
        ]);
96
    }
97
98
    /**
99
     * @param Request $request
100
     *
101
     * @Route("/bookmarklet", name="bookmarklet")
102
     *
103
     * @return \Symfony\Component\HttpFoundation\Response
104
     */
105
    public function addEntryViaBookmarkletAction(Request $request)
106
    {
107
        $entry = new Entry($this->getUser());
0 ignored issues
show
Documentation introduced by
$this->getUser() is of type null|object, but the function expects a object<Wallabag\UserBundle\Entity\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
        $entry->setUrl($request->get('url'));
109
110
        if (false === $this->checkIfEntryAlreadyExists($entry)) {
111
            $this->updateEntry($entry);
112
113
            $em = $this->getDoctrine()->getManager();
114
            $em->persist($entry);
115
            $em->flush();
116
117
            // entry saved, dispatch event about it!
118
            $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
119
        }
120
121
        return $this->redirect($this->generateUrl('homepage'));
122
    }
123
124
    /**
125
     * @Route("/new", name="new")
126
     *
127
     * @return \Symfony\Component\HttpFoundation\Response
128
     */
129
    public function addEntryAction()
130
    {
131
        return $this->render('WallabagCoreBundle:Entry:new.html.twig');
132
    }
133
134
    /**
135
     * Edit an entry content.
136
     *
137
     * @param Request $request
138
     * @param Entry   $entry
139
     *
140
     * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit")
141
     *
142
     * @return \Symfony\Component\HttpFoundation\Response
143
     */
144 View Code Duplication
    public function editEntryAction(Request $request, Entry $entry)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
    {
146
        $this->checkUserAction($entry);
147
148
        $form = $this->createForm(EditEntryType::class, $entry);
149
150
        $form->handleRequest($request);
151
152
        if ($form->isSubmitted() && $form->isValid()) {
153
            $em = $this->getDoctrine()->getManager();
154
            $em->persist($entry);
155
            $em->flush();
156
157
            $this->get('session')->getFlashBag()->add(
158
                'notice',
159
                'flashes.entry.notice.entry_updated'
160
            );
161
162
            return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
163
        }
164
165
        return $this->render('WallabagCoreBundle:Entry:edit.html.twig', [
166
            'form' => $form->createView(),
167
        ]);
168
    }
169
170
    /**
171
     * Shows all entries for current user.
172
     *
173
     * @param Request $request
174
     * @param int     $page
175
     *
176
     * @Route("/all/list/{page}", name="all", defaults={"page" = "1"})
177
     *
178
     * @return \Symfony\Component\HttpFoundation\Response
179
     */
180
    public function showAllAction(Request $request, $page)
181
    {
182
        return $this->showEntries('all', $request, $page);
183
    }
184
185
    /**
186
     * Shows unread entries for current user.
187
     *
188
     * @param Request $request
189
     * @param int     $page
190
     *
191
     * @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"})
192
     *
193
     * @return \Symfony\Component\HttpFoundation\Response
194
     */
195
    public function showUnreadAction(Request $request, $page)
196
    {
197
        // load the quickstart if no entry in database
198
        if (1 === (int) $page && 0 === $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId())) {
199
            return $this->redirect($this->generateUrl('quickstart'));
200
        }
201
202
        return $this->showEntries('unread', $request, $page);
203
    }
204
205
    /**
206
     * Shows read entries for current user.
207
     *
208
     * @param Request $request
209
     * @param int     $page
210
     *
211
     * @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"})
212
     *
213
     * @return \Symfony\Component\HttpFoundation\Response
214
     */
215
    public function showArchiveAction(Request $request, $page)
216
    {
217
        return $this->showEntries('archive', $request, $page);
218
    }
219
220
    /**
221
     * Shows starred entries for current user.
222
     *
223
     * @param Request $request
224
     * @param int     $page
225
     *
226
     * @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"})
227
     *
228
     * @return \Symfony\Component\HttpFoundation\Response
229
     */
230
    public function showStarredAction(Request $request, $page)
231
    {
232
        return $this->showEntries('starred', $request, $page);
233
    }
234
235
    /**
236
     * Shows entry content.
237
     *
238
     * @param Entry $entry
239
     *
240
     * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
241
     *
242
     * @return \Symfony\Component\HttpFoundation\Response
243
     */
244
    public function viewAction(Entry $entry)
245
    {
246
        $this->checkUserAction($entry);
247
248
        return $this->render(
249
            'WallabagCoreBundle:Entry:entry.html.twig',
250
            ['entry' => $entry]
251
        );
252
    }
253
254
    /**
255
     * Reload an entry.
256
     * Refetch content from the website and make it readable again.
257
     *
258
     * @param Entry $entry
259
     *
260
     * @Route("/reload/{id}", requirements={"id" = "\d+"}, name="reload_entry")
261
     *
262
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
263
     */
264
    public function reloadAction(Entry $entry)
265
    {
266
        $this->checkUserAction($entry);
267
268
        $this->updateEntry($entry, 'entry_reloaded');
269
270
        // if refreshing entry failed, don't save it
271
        if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
272
            $bag = $this->get('session')->getFlashBag();
273
            $bag->clear();
274
            $bag->add('notice', 'flashes.entry.notice.entry_reloaded_failed');
275
276
            return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
277
        }
278
279
        $em = $this->getDoctrine()->getManager();
280
        $em->persist($entry);
281
        $em->flush();
282
283
        // entry saved, dispatch event about it!
284
        $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
285
286
        return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
287
    }
288
289
    /**
290
     * Changes read status for an entry.
291
     *
292
     * @param Request $request
293
     * @param Entry   $entry
294
     *
295
     * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
296
     *
297
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
298
     */
299 View Code Duplication
    public function toggleArchiveAction(Request $request, Entry $entry)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
300
    {
301
        $this->checkUserAction($entry);
302
303
        $entry->toggleArchive();
304
        $this->getDoctrine()->getManager()->flush();
305
306
        $message = 'flashes.entry.notice.entry_unarchived';
307
        if ($entry->isArchived()) {
308
            $message = 'flashes.entry.notice.entry_archived';
309
        }
310
311
        $this->get('session')->getFlashBag()->add(
312
            'notice',
313
            $message
314
        );
315
316
        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
317
318
        return $this->redirect($redirectUrl);
319
    }
320
321
    /**
322
     * Changes starred status for an entry.
323
     *
324
     * @param Request $request
325
     * @param Entry   $entry
326
     *
327
     * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
328
     *
329
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
330
     */
331 View Code Duplication
    public function toggleStarAction(Request $request, Entry $entry)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
332
    {
333
        $this->checkUserAction($entry);
334
335
        $entry->toggleStar();
336
        $entry->updateStar($entry->isStarred());
337
        $this->getDoctrine()->getManager()->flush();
338
339
        $message = 'flashes.entry.notice.entry_unstarred';
340
        if ($entry->isStarred()) {
341
            $message = 'flashes.entry.notice.entry_starred';
342
        }
343
344
        $this->get('session')->getFlashBag()->add(
345
            'notice',
346
            $message
347
        );
348
349
        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
350
351
        return $this->redirect($redirectUrl);
352
    }
353
354
    /**
355
     * Deletes entry and redirect to the homepage or the last viewed page.
356
     *
357
     * @param Entry $entry
358
     *
359
     * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
360
     *
361
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
362
     */
363
    public function deleteEntryAction(Request $request, Entry $entry)
364
    {
365
        $this->checkUserAction($entry);
366
367
        // generates the view url for this entry to check for redirection later
368
        // to avoid redirecting to the deleted entry. Ugh.
369
        $url = $this->generateUrl(
370
            'view',
371
            ['id' => $entry->getId()],
372
            UrlGeneratorInterface::ABSOLUTE_PATH
373
        );
374
375
        // entry deleted, dispatch event about it!
376
        $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
377
378
        $em = $this->getDoctrine()->getManager();
379
        $em->remove($entry);
380
        $em->flush();
381
382
        $this->get('session')->getFlashBag()->add(
383
            'notice',
384
            'flashes.entry.notice.entry_deleted'
385
        );
386
387
        // don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
388
        $referer = $request->headers->get('referer');
389
        $to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null);
390
391
        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to);
392
393
        return $this->redirect($redirectUrl);
394
    }
395
396
    /**
397
     * Get public URL for entry (and generate it if necessary).
398
     *
399
     * @param Entry $entry
400
     *
401
     * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
402
     *
403
     * @return \Symfony\Component\HttpFoundation\Response
404
     */
405
    public function shareAction(Entry $entry)
406
    {
407
        $this->checkUserAction($entry);
408
409
        if (null === $entry->getUid()) {
410
            $entry->generateUid();
411
412
            $em = $this->getDoctrine()->getManager();
413
            $em->persist($entry);
414
            $em->flush();
415
        }
416
417
        return $this->redirect($this->generateUrl('share_entry', [
418
            'uid' => $entry->getUid(),
419
        ]));
420
    }
421
422
    /**
423
     * Disable public sharing for an entry.
424
     *
425
     * @param Entry $entry
426
     *
427
     * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share")
428
     *
429
     * @return \Symfony\Component\HttpFoundation\Response
430
     */
431
    public function deleteShareAction(Entry $entry)
432
    {
433
        $this->checkUserAction($entry);
434
435
        $entry->cleanUid();
436
437
        $em = $this->getDoctrine()->getManager();
438
        $em->persist($entry);
439
        $em->flush();
440
441
        return $this->redirect($this->generateUrl('view', [
442
            'id' => $entry->getId(),
443
        ]));
444
    }
445
446
    /**
447
     * Ability to view a content publicly.
448
     *
449
     * @param Entry $entry
450
     *
451
     * @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry")
452
     * @Cache(maxage="25200", smaxage="25200", public=true)
453
     *
454
     * @return \Symfony\Component\HttpFoundation\Response
455
     */
456
    public function shareEntryAction(Entry $entry)
457
    {
458
        if (!$this->get('craue_config')->get('share_public')) {
459
            throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
460
        }
461
462
        return $this->render(
463
            '@WallabagCore/themes/common/Entry/share.html.twig',
464
            ['entry' => $entry]
465
        );
466
    }
467
468
    /**
469
     * Shows untagged articles for current user.
470
     *
471
     * @param Request $request
472
     * @param int     $page
473
     *
474
     * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
475
     *
476
     * @return \Symfony\Component\HttpFoundation\Response
477
     */
478
    public function showUntaggedEntriesAction(Request $request, $page)
479
    {
480
        return $this->showEntries('untagged', $request, $page);
481
    }
482
483
    /**
484
     * Fetch content and update entry.
485
     * In case it fails, $entry->getContent will return an error message.
486
     *
487
     * @param Entry  $entry
488
     * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
489
     */
490
    private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
491
    {
492
        $message = 'flashes.entry.notice.' . $prefixMessage;
493
494
        try {
495
            $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
496
        } catch (\Exception $e) {
497
            $this->get('logger')->error('Error while saving an entry', [
498
                'exception' => $e,
499
                'entry' => $entry,
500
            ]);
501
502
            $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
503
        }
504
505
        if (empty($entry->getDomainName())) {
506
            $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
507
        }
508
509
        if (empty($entry->getTitle())) {
510
            $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
511
        }
512
513
        $this->get('session')->getFlashBag()->add('notice', $message);
514
    }
515
516
    /**
517
     * Global method to retrieve entries depending on the given type
518
     * It returns the response to be send.
519
     *
520
     * @param string  $type    Entries type: unread, starred or archive
521
     * @param Request $request
522
     * @param int     $page
523
     *
524
     * @return \Symfony\Component\HttpFoundation\Response
525
     */
526
    private function showEntries($type, Request $request, $page)
527
    {
528
        $repository = $this->get('wallabag_core.entry_repository');
529
        $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
530
        $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
531
532
        switch ($type) {
533
            case 'search':
534
                $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
535
536
                break;
537
            case 'untagged':
538
                $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
539
540
                break;
541
            case 'starred':
542
                $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
543
                break;
544
            case 'archive':
545
                $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
546
                break;
547
            case 'unread':
548
                $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
549
                break;
550
            case 'all':
551
                $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
552
                break;
553
            default:
554
                throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
555
        }
556
557
        $form = $this->createForm(EntryFilterType::class);
558
559
        if ($request->query->has($form->getName())) {
560
            // manually bind values from the request
561
            $form->submit($request->query->get($form->getName()));
562
563
            // build the query from the given form object
564
            $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
565
        }
566
567
        $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
568
569
        $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
570
571
        try {
572
            $entries->setCurrentPage($page);
573
        } catch (OutOfRangeCurrentPageException $e) {
574
            if ($page > 1) {
575
                return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
576
            }
577
        }
578
579
        return $this->render(
580
            'WallabagCoreBundle:Entry:entries.html.twig', [
581
                'form' => $form->createView(),
582
                'entries' => $entries,
583
                'currentPage' => $page,
584
                'searchTerm' => $searchTerm,
585
                'isFiltered' => $form->isSubmitted(),
586
            ]
587
        );
588
    }
589
590
    /**
591
     * Check if the logged user can manage the given entry.
592
     *
593
     * @param Entry $entry
594
     */
595
    private function checkUserAction(Entry $entry)
596
    {
597
        if (null === $this->getUser() || $this->getUser()->getId() !== $entry->getUser()->getId()) {
598
            throw $this->createAccessDeniedException('You can not access this entry.');
599
        }
600
    }
601
602
    /**
603
     * Check for existing entry, if it exists, redirect to it with a message.
604
     *
605
     * @param Entry $entry
606
     *
607
     * @return Entry|bool
608
     */
609
    private function checkIfEntryAlreadyExists(Entry $entry)
610
    {
611
        return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
612
    }
613
}
614