Completed
Push — master ( 555845...a5fea9 )
by WEBEWEB
11:15
created

WikiController::getWikiPages()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 1
nc 1
nop 0

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
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Controller;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use WBW\Bundle\BootstrapBundle\Model\WikiPage;
17
use WBW\Bundle\SyntaxHighlighterBundle\API\SyntaxHighlighterConfig;
18
use WBW\Bundle\SyntaxHighlighterBundle\API\SyntaxHighlighterDefaults;
19
use WBW\Bundle\SyntaxHighlighterBundle\Provider\SyntaxHighlighterStringsProvider;
20
21
/**
22
 * Wiki controller.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\BootstrapBundle\Controller
26
 */
27
class WikiController extends AbstractBootstrapController {
28
29
    /**
30
     * Get the Syntax Highlighter config.
31
     *
32
     * @return SyntaxHighlighterConfig Returns the SyntaxHighlighter config.
33
     */
34
    protected function getSyntaxHighlighterConfig() {
35
36
        // Get the SyntaxHighlighter strings provider.
37
        $provider = $this->get(SyntaxHighlighterStringsProvider::SERVICE_NAME);
38
39
        // Initialize the SyntaxHighlighter config.
40
        $config = new SyntaxHighlighterConfig();
41
        $config->setStrings($provider->getSyntaxHighlighterStrings());
42
43
        // Return the SyntaxHighlighter config.
44
        return $config;
45
    }
46
47
    /**
48
     * Get the Syntax Highlighter defaults.
49
     *
50
     * @return SyntaxHighlighterDefaults Returns the SyntaxHighlighter defaults.
51
     */
52
    protected function getSyntaxHighlighterDefaults() {
53
54
        // Initialize the SyntaxHighlighter defaults.
55
        $defaults = new SyntaxHighlighterDefaults();
56
57
        // Return the SyntaxHighlighter defaults.
58
        return $defaults;
59
    }
60
61
    /**
62
     * Get the wiki pages.
63
     *
64
     * @return WikiPage[] Returns the wiki pages.
65
     */
66
    public static function getWikiPages() {
67
68
        // Initialize the table of contents.
69
        $tableContents = [];
70
71
        // Twig extensions > Code
72
        $tableContents[] = new WikiPage("twig-extension", "code", "basic-block", "Basic block");
73
        $tableContents[] = new WikiPage("twig-extension", "code", "inline", "Inline");
74
        $tableContents[] = new WikiPage("twig-extension", "code", "sample-output", "Sample output");
75
        $tableContents[] = new WikiPage("twig-extension", "code", "user-input", "User input");
76
        $tableContents[] = new WikiPage("twig-extension", "code", "variable", "Variable");
77
78
        // Twig extensions > Component
79
        $tableContents[] = new WikiPage("twig-extension", "component", "alert", "Alert");
80
        $tableContents[] = new WikiPage("twig-extension", "component", "badge", "Badge");
81
        $tableContents[] = new WikiPage("twig-extension", "component", "button", "Button");
82
        $tableContents[] = new WikiPage("twig-extension", "component", "glyphicon", "Glyphicon");
83
        $tableContents[] = new WikiPage("twig-extension", "component", "label", "Label");
84
        $tableContents[] = new WikiPage("twig-extension", "component", "progress-bar", "Progress bar");
85
86
        // Twig extensions > Form
87
        $tableContents[] = new WikiPage("twig-extension", "form", "button", "Button");
88
89
        // Twig extensions > Grid
90
        $tableContents[] = new WikiPage("twig-extension", "grid", "grid", "Grid");
91
92
        // Twig extensions > Image
93
        $tableContents[] = new WikiPage("twig-extension", "image", "base64", "Base 64");
94
95
        // Twig extensions > Plugin
96
        $tableContents[] = new WikiPage("twig-extension", "plugin", "font-awesome", "Font Awesome");
97
        $tableContents[] = new WikiPage("twig-extension", "plugin", "jquery-inputmask", "jQuery InputMask");
98
        $tableContents[] = new WikiPage("twig-extension", "plugin", "material-design-iconic-font", "Material Design Iconic Font");
99
        $tableContents[] = new WikiPage("twig-extension", "plugin", "meteocons", "Meteocons");
100
101
        // Twig extensions > Table
102
        $tableContents[] = new WikiPage("twig-extension", "table", "button", "Button");
103
104
        // Twig extensions > Typography
105
        $tableContents[] = new WikiPage("twig-extension", "typography", "bold", "Bold");
106
        $tableContents[] = new WikiPage("twig-extension", "typography", "deleted", "Deleted");
107
        $tableContents[] = new WikiPage("twig-extension", "typography", "heading", "Heading");
108
        $tableContents[] = new WikiPage("twig-extension", "typography", "inserted", "Inserted");
109
        $tableContents[] = new WikiPage("twig-extension", "typography", "italic", "Italic");
110
        $tableContents[] = new WikiPage("twig-extension", "typography", "marked", "Marked");
111
        $tableContents[] = new WikiPage("twig-extension", "typography", "small", "Small");
112
        $tableContents[] = new WikiPage("twig-extension", "typography", "strikethrough", "Strikethrough");
113
        $tableContents[] = new WikiPage("twig-extension", "typography", "underlined", "Underlined");
114
115
        // Twig extensions > Utility
116
        $tableContents[] = new WikiPage("twig-extension", "utility", "role-label", "Role label");
117
118
        // Return the table of contents.
119
        return $tableContents;
120
    }
121
122
    /**
123
     * Displays a wiki page.
124
     *
125
     * @param Request $request The request.
126
     * @param string $category The category.
127
     * @param string $package The parent.
128
     * @param string $page The page.
129
     * @return Response Returns the response.
130
     */
131
    public function indexAction(Request $request, $category, $package, $page) {
1 ignored issue
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...
132
133
        // Initialize.
134
        $wikiPages = self::getWikiPages();
135
        $wikiPage  = null;
136
137
        // Find the wiki page.
138
        foreach ($wikiPages as $current) {
139
            if ($category === $current->getCategory() && $package === $current->getPackage() && $page === $current->getPage()) {
140
                $wikiPage = $current;
141
                break;
142
            }
143
        }
144
145
        // Check if the wiki page exists.
146
        if (null === $wikiPage) {
147
148
            // Set the default wiki page.
149
            $wikiPage = $wikiPages[0];
150
151
            // Notify the user.
152
            $this->notifyDanger("The requested page was not found");
153
            $this->notifyInfo("You have been redirected to homepage");
154
        }
155
156
        // Set the template.
157
        $template = [
158
            "@",
159
            $wikiPage->getBundle(),
160
            "/Wiki/",
161
            $wikiPage->getCategory(),
162
            "/",
163
            $wikiPage->getPackage(),
164
            "/",
165
            $wikiPage->getPage(),
166
            ".html.twig",
167
        ];
168
169
        // Returns the response.
170
        return $this->render(implode("", $template), [
171
                "syntaxHighlighterConfig"   => $this->getSyntaxHighlighterConfig(),
172
                "syntaxHighlighterDefaults" => $this->getSyntaxHighlighterDefaults(),
173
                "wikiPage"                  => $wikiPage,
174
                "wikiPages"                 => $wikiPages,
175
        ]);
176
    }
177
178
}
179