Passed
Push — master ( d80e44...778f60 )
by Peter
02:18
created

AdminAbstract::prepareCustomAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Http\Controllers\Admin;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
use AbterPhp\Framework\Http\Controllers\ControllerAbstract;
9
use AbterPhp\Framework\I18n\ITranslator;
10
use AbterPhp\Framework\Session\FlashService;
11
use Opulence\Routing\Urls\UrlGenerator;
12
13
abstract class AdminAbstract extends ControllerAbstract
14
{
15
    const ENTITY_PLURAL   = '';
16
    const ENTITY_SINGULAR = '';
17
18
    const ENTITY_LOAD_FAILURE = 'message:load-failure';
19
20
    const URL_EDIT = '%s-edit';
21
22
    const RESOURCE_DEFAULT = '%s';
23
    const RESOURCE_HEADER  = '%s-header';
24
    const RESOURCE_FOOTER  = '%s-footer';
25
    const RESOURCE_TYPE    = 'void';
26
27
    /** @var ITranslator */
28
    protected $translator;
29
30
    /** @var UrlGenerator */
31
    protected $urlGenerator;
32
33
    /** @var string */
34
    protected $resource = '';
35
36
    /**
37
     * AdminAbstract constructor.
38
     *
39
     * @param FlashService $flashService
40
     * @param ITranslator  $translator
41
     * @param UrlGenerator $urlGenerator
42
     */
43
    public function __construct(
44
        FlashService $flashService,
45
        ITranslator $translator,
46
        UrlGenerator $urlGenerator
47
    ) {
48
        parent::__construct($flashService);
49
50
        $this->translator   = $translator;
51
        $this->urlGenerator = $urlGenerator;
52
    }
53
54
    /**
55
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
56
     *
57
     * @param IStringerEntity|null $entity
58
     */
59
    protected function addCustomAssets(?IStringerEntity $entity = null)
0 ignored issues
show
Unused Code introduced by
The parameter $entity is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

59
    protected function addCustomAssets(/** @scrutinizer ignore-unused */ ?IStringerEntity $entity = null)

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

Loading history...
60
    {
61
        $this->prepareCustomAssets();
62
    }
63
64
    protected function prepareCustomAssets()
65
    {
66
        $this->view->setVar('page', $this->getResourceName(static::RESOURCE_DEFAULT));
67
        $this->view->setVar('pageHeader', $this->getResourceName(static::RESOURCE_HEADER));
68
        $this->view->setVar('pageFooter', $this->getResourceName(static::RESOURCE_FOOTER));
69
        $this->view->setVar('pageType', $this->getResourceTypeName(static::RESOURCE_DEFAULT));
70
        $this->view->setVar('pageTypeHeader', $this->getResourceTypeName(static::RESOURCE_HEADER));
71
        $this->view->setVar('pageTypeFooter', $this->getResourceTypeName(static::RESOURCE_FOOTER));
72
    }
73
74
    /**
75
     * @param string $template
76
     *
77
     * @return string
78
     */
79
    protected function getResourceName(string $template)
80
    {
81
        return sprintf($template, static::ENTITY_SINGULAR);
82
    }
83
84
    /**
85
     * @param string $template
86
     *
87
     * @return string
88
     */
89
    protected function getResourceTypeName(string $template)
90
    {
91
        return sprintf($template, static::RESOURCE_TYPE);
92
    }
93
}
94