NewsController::indexAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CmsBundle\Controller\Front;
14
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
18
use WellCommerce\Bundle\CmsBundle\Entity\News;
19
use WellCommerce\Bundle\CoreBundle\Controller\Front\AbstractFrontController;
20
use WellCommerce\Component\Breadcrumb\Model\Breadcrumb;
21
22
/**
23
 * Class NewsController
24
 *
25
 * @author  Adam Piotrowski <[email protected]>
26
 */
27
class NewsController extends AbstractFrontController
28
{
29
    public function indexAction(Request $request): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        $this->getBreadcrumbProvider()->add(new Breadcrumb([
32
            'label' => $this->trans('news.heading.index'),
33
        ]));
34
        
35
        return $this->displayTemplate('index');
36
    }
37
    
38
    public function viewAction(News $news): Response
39
    {
40
        $this->getBreadcrumbProvider()->add(new Breadcrumb([
41
            'url'   => $this->getRouterHelper()->generateUrl('front.news.index'),
42
            'label' => $this->trans('news.heading.index'),
43
        ]));
44
        
45
        $this->getBreadcrumbProvider()->add(new Breadcrumb([
46
            'label' => $news->translate()->getTopic(),
47
        ]));
48
        
49
        $this->getMetadataHelper()->setMetadata($news->translate()->getMeta());
50
        
51
        return $this->displayTemplate('view', [
52
            'news' => $news,
53
        ]);
54
    }
55
    
56
    protected function findOr404(Request $request, array $criteria = [])
57
    {
58
        // check whether request contains ID attribute
59
        if (!$request->attributes->has('id')) {
60
            throw new \LogicException('Request does not have "id" attribute set.');
61
        }
62
        
63
        $criteria['id'] = $request->attributes->get('id');
64
        
65
        if (null === $resource = $this->getManager()->getRepository()->findOneBy($criteria)) {
66
            throw new NotFoundHttpException(sprintf('Resource not found'));
67
        }
68
        
69
        return $resource;
70
    }
71
}
72