Passed
Push — master ( 6af672...0107a4 )
by Peter
07:37
created

Page::addCustomAssets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 57
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 2
eloc 38
c 4
b 0
f 0
nc 2
nop 1
dl 0
loc 57
rs 9.312

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
8
use AbterPhp\Framework\Assets\AssetManager;
9
use AbterPhp\Framework\Config\EnvReader;
10
use AbterPhp\Framework\Constant\Session;
11
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
12
use AbterPhp\Framework\I18n\ITranslator;
13
use AbterPhp\Framework\Session\FlashService;
14
use AbterPhp\Website\Domain\Entities\Page as Entity;
15
use AbterPhp\Website\Form\Factory\Page as FormFactory;
16
use AbterPhp\Website\Orm\PageRepo as Repo;
17
use League\Flysystem\FilesystemException;
18
use Opulence\Events\Dispatchers\IEventDispatcher;
19
use Opulence\Routing\Urls\UrlGenerator;
20
use Opulence\Sessions\ISession;
21
use Psr\Log\LoggerInterface;
22
23
/**
24
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
25
 */
26
class Page extends FormAbstract
27
{
28
    const ENTITY_PLURAL   = 'pages';
29
    const ENTITY_SINGULAR = 'page';
30
31
    const ENTITY_TITLE_SINGULAR = 'website:page';
32
    const ENTITY_TITLE_PLURAL   = 'website:pages';
33
34
    const ROUTING_PATH = 'pages';
35
36
    /** @var AssetManager */
37
    protected $assetManager;
38
39
    /** @var EnvReader */
40
    protected $envReader;
41
42
    /** @var string */
43
    protected $resource = 'pages';
44
45
    /**
46
     * Page constructor.
47
     *
48
     * @param FlashService     $flashService
49
     * @param ITranslator      $translator
50
     * @param UrlGenerator     $urlGenerator
51
     * @param LoggerInterface  $logger
52
     * @param Repo             $repo
53
     * @param ISession         $session
54
     * @param FormFactory      $formFactory
55
     * @param IEventDispatcher $eventDispatcher
56
     * @param AssetManager     $assetManager
57
     * @param EnvReader        $envReader
58
     */
59
    public function __construct(
60
        FlashService $flashService,
61
        ITranslator $translator,
62
        UrlGenerator $urlGenerator,
63
        LoggerInterface $logger,
64
        Repo $repo,
65
        ISession $session,
66
        FormFactory $formFactory,
67
        IEventDispatcher $eventDispatcher,
68
        AssetManager $assetManager,
69
        EnvReader $envReader
70
    ) {
71
        parent::__construct(
72
            $flashService,
73
            $translator,
74
            $urlGenerator,
75
            $logger,
76
            $repo,
77
            $session,
78
            $formFactory,
79
            $eventDispatcher
80
        );
81
82
        $this->assetManager = $assetManager;
83
        $this->envReader    = $envReader;
84
    }
85
86
    /**
87
     * @param string $entityId
88
     *
89
     * @return Entity
90
     */
91
    protected function createEntity(string $entityId): IStringerEntity
92
    {
93
        return new Entity((string)$entityId, '', '', '', '', '', false);
94
    }
95
96
    /**
97
     * @param IStringerEntity|null $entity
98
     *
99
     * @throws FilesystemException
100
     */
101
    protected function addCustomAssets(?IStringerEntity $entity = null)
102
    {
103
        parent::addCustomAssets($entity);
104
105
        if (!($entity instanceof Entity)) {
106
            return;
107
        }
108
109
        $styles = $this->getResourceName(static::RESOURCE_DEFAULT);
110
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
111
112
        // Feature is disabled in favor of the base64 plugin
113
        //$editorFileUploadPath = Routes::getApiBasePath() . '/editor-file-upload';
114
        //$this->assetManager->addJsVar('clientId', $this->envReader->get(AdminEnv::EDITOR_CLIENT_ID));
115
        //$this->assetManager->addJsVar('editorFileUploadPath', $this->envReader->get(AdminEnv::EDITOR_CLIENT_ID));
116
117
        $editorLang = $this->session->get(Session::LANGUAGE_IDENTIFIER);
118
        $this->assetManager->addJsVar($footer, 'editorLang', $editorLang);
119
120
        $this->assetManager->addCss($styles, '/admin-assets/vendor/trumbowyg/ui/trumbowyg.css');
121
        $this->assetManager->addCss($styles, '/admin-assets/vendor/trumbowyg/plugins/table/ui/trumbowyg.table.css');
122
        $this->assetManager->addCss(
123
            $styles,
124
            '/admin-assets/vendor/trumbowyg/plugins/specialchars/ui/trumbowyg.specialchars.css'
125
        );
126
        $this->assetManager->addCss($styles, '/admin-assets/css/trumbowyg.css');
127
128
        $this->assetManager->addJs($footer, '/admin-assets/vendor/jquery/jquery-resizable.js');
129
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/trumbowyg.js');
130
        $this->assetManager->addJs($footer, "/admin-assets/vendor/trumbowyg/langs/${editorLang}.js");
131
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/base64/trumbowyg.base64.js');
132
        $this->assetManager->addJs(
133
            $footer,
134
            '/admin-assets/vendor/trumbowyg/plugins/cleanpaste/trumbowyg.cleanpaste.js'
135
        );
136
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/history/trumbowyg.history.js');
137
        $this->assetManager->addJs(
138
            $footer,
139
            '/admin-assets/vendor/trumbowyg/plugins/preformatted/trumbowyg.preformatted.js'
140
        );
141
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/resizimg/trumbowyg.resizimg.js');
142
        $this->assetManager->addJs(
143
            $footer,
144
            '/admin-assets/vendor/trumbowyg/plugins/specialchars/trumbowyg.specialchars.js'
145
        );
146
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/table/trumbowyg.table.js');
147
        // Feature is disabled in favor of the base64 plugin
148
        //$this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/upload/trumbowyg.upload.js');
149
        $this->assetManager->addJs($footer, '/admin-assets/js/editor.js');
150
        $this->assetManager->addJs($footer, '/admin-assets/js/countable-textarea.js');
151
        $this->assetManager->addJs($footer, '/admin-assets/js/hideable-container.js');
152
        $this->assetManager->addJs($footer, '/admin-assets/js/layout-or-id.js');
153
        $this->assetManager->addJs($footer, '/admin-assets/js/identifier.js');
154
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
155
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
156
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
157
        $this->assetManager->addJs($footer, '/admin-assets/js/page.js');
158
    }
159
}
160