View   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 60
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A execute() 0 18 2
1
<?php
2
/**
3
 * File: View.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\ICatalogue\Controller\Catalogue;
10
11
use Magento\Framework\App\Action\Action;
12
use Magento\Framework\App\Action\Context;
13
use Magento\Framework\Exception\NotFoundException;
14
use Magento\Framework\View\Result\Page;
15
use Magento\Framework\View\Result\PageFactory;
16
use MSlwk\ICatalogue\Model\CatalogueFactory;
17
use MSlwk\ICatalogue\Model\Catalogue;
18
use MSlwk\ICatalogue\Model\ResourceModel\Catalogue as CatalogueResource;
19
20
/**
21
 * Class View
22
 *
23
 * @package MSlwk\ICatalogue\Controller\Catalogue
24
 */
25
class View extends Action
26
{
27
    /**
28
     * @var CatalogueFactory
29
     */
30
    protected $catalogueFactory;
31
32
    /**
33
     * @var CatalogueResource
34
     */
35
    protected $catalogueResource;
36
37
    /**
38
     * @var PageFactory
39
     */
40
    protected $resultPageFactory;
41
42
    /**
43
     * View constructor.
44
     *
45
     * @param CatalogueFactory $catalogueFactory
46
     * @param CatalogueResource $catalogueResource
47
     * @param PageFactory $pageFactory
48
     * @param Context $context
49
     */
50
    public function __construct(
51
        CatalogueFactory $catalogueFactory,
52
        CatalogueResource $catalogueResource,
53
        PageFactory $pageFactory,
54
        Context $context
55
    ) {
56
        $this->catalogueFactory = $catalogueFactory;
57
        $this->catalogueResource = $catalogueResource;
58
        $this->resultPageFactory = $pageFactory;
59
        parent::__construct($context);
60
    }
61
62
    /**
63
     * @return Page
64
     * @throws NotFoundException
65
     */
66
    public function execute()
67
    {
68
        /** @var Catalogue $catalogue */
69
        $catalogue = $this->catalogueFactory->create();
70
71
        $id = $this->getRequest()->getParam('id');
72
        $this->catalogueResource->load($catalogue, $id);
73
        if (!$catalogue->getId()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $catalogue->getId() of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
74
            throw new NotFoundException(__('The requested catalogue doesn\'t exist'));
75
        }
76
77
        $resultPage = $this->resultPageFactory->create();
78
79
        $resultPage->getConfig()->getTitle()->set(__($catalogue->getTitle()));
80
        $resultPage->getConfig()->setDescription(__($catalogue->getTitle() . ' - iCatalogue'));
81
82
        return $resultPage;
83
    }
84
}
85