Completed
Push — master ( c31c02...2a7bf5 )
by WEBEWEB
07:45
created

WikiController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 84
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getWikiViews() 0 38 2
A indexAction() 0 28 2
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\CoreBundle\Model\WikiView;
17
18
/**
19
 * Wiki controller.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Controller
23
 */
24
class WikiController extends AbstractWikiController {
25
26
    /**
27
     * Get the wiki views.
28
     *
29
     * @return WikiView[] Returns the wiki views.
30
     */
31
    public static function getWikiViews() {
32
33
        // Initialize the table of contents.
34
        $tableContents = [];
35
36
        // Twig extensions > CSS
37
        $tableContents[] = new WikiView("Twig-extension", "CSS", "button", "Button");
38
        $tableContents[] = new WikiView("twig-extension", "CSS", "code", "Code");
39
        $tableContents[] = new WikiView("Twig-extension", "CSS", "grid", "Grid");
40
        $tableContents[] = new WikiView("Twig-extension", "CSS", "image", "Image");
41
        $tableContents[] = new WikiView("Twig-extension", "CSS", "typography", "Typography");
42
43
        // Twig extensions > Component
44
        $tableContents[] = new WikiView("Twig-extension", "Component", "alert", "Alert");
45
        $tableContents[] = new WikiView("Twig-extension", "Component", "badge", "Badge");
46
        $tableContents[] = new WikiView("Twig-extension", "Component", "glyphicon", "Glyphicon");
47
        $tableContents[] = new WikiView("Twig-extension", "Component", "label", "Label");
48
        $tableContents[] = new WikiView("Twig-extension", "Component", "progress-bar", "Progress bar");
49
50
        // Twig extensions > Utility
51
        $tableContents[] = new WikiView("Twig-extension", "Utility", "form-button", "Form button");
52
        $tableContents[] = new WikiView("Twig-extension", "Utility", "role-label", "Role label");
53
        $tableContents[] = new WikiView("Twig-extension", "Utility", "table-button", "Table button");
54
55
        // Twig extensions > Plugin
56
        $tableContents[] = new WikiView("Twig-extension", "Plugin", "font-awesome", "Font Awesome");
57
        $tableContents[] = new WikiView("Twig-extension", "Plugin", "jquery-inputmask", "jQuery InputMask");
58
        $tableContents[] = new WikiView("Twig-extension", "Plugin", "material-design-iconic-font", "Material Design Iconic Font");
59
        $tableContents[] = new WikiView("Twig-extension", "Plugin", "meteocons", "Meteocons");
60
61
        // Handle each wiki view.
62
        foreach ($tableContents as $current) {
63
            $current->setBundle("Bootstrap");
64
        }
65
66
        // Return the table of contents.
67
        return $tableContents;
68
    }
69
70
    /**
71
     * Displays a wiki page.
72
     *
73
     * @param string $category The category.
74
     * @param string $package The parent.
75
     * @param string $page The page.
76
     * @return Response Returns the response.
77
     */
78
    public function indexAction($category, $package, $page) {
79
80
        // Get the wiki views.
81
        $wikiViews = self::getWikiViews();
82
83
        // Find and check the wiki view.
84
        $wikiView = WikiView::find($wikiViews, $category, $package, $page);
0 ignored issues
show
Documentation introduced by
$category is of type string, but the function expects a object<WBW\Bundle\CoreBundle\Model\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$package is of type string, but the function expects a object<WBW\Bundle\CoreBundle\Model\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$page is of type string, but the function expects a object<WBW\Bundle\CoreBundle\Model\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
        if (null === $wikiView) {
86
87
            // Set a default wiki view.
88
            $wikiView = $wikiViews[0];
89
90
            // Notify the user.
91
            $this->notifyDanger("The requested page was not found");
92
            $this->notifyInfo("You have been redirected to homepage");
93
        }
94
95
        // Returns the response.
96
        return $this->render($wikiView->getView(), [
97
                "wikiViews"                 => $wikiViews,
98
                "wikiView"                  => $wikiView,
99
                "syntaxHighlighterConfig"   => $this->getSyntaxHighlighterConfig(),
100
                "syntaxHighlighterDefaults" => $this->getSyntaxHighlighterDefaults(),
101
                "user"                      => $this->getSampleUser(),
102
                "userRoleColors"            => $this->getSampleUserRoleColors(),
103
                "userRoleTranslations"      => $this->getSampleUserRoleTranslations(),
104
        ]);
105
    }
106
107
}
108