PagesController::display()   B
last analyzed

Complexity

Conditions 7
Paths 25

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 21
nc 25
nop 0
dl 0
loc 36
ccs 0
cts 29
cp 0
crap 56
rs 8.6506
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Static content controller.
5
 *
6
 * This file will render views from views/pages/
7
 *
8
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
9
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10
 *
11
 * Licensed under The MIT License
12
 * For full copyright and license information, please see the LICENSE.txt
13
 * Redistributions of files must retain the above copyright notice.
14
 *
15
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
16
 * @license   https://opensource.org/licenses/mit-license.php MIT License
17
 *
18
 * @see      https://www.phpmyadmin.net/
19
 */
20
21
namespace App\Controller;
22
23
use Cake\Core\Configure;
24
use Cake\Http\Exception\NotFoundException;
25
use Cake\Utility\Inflector;
26
use Cake\View\Exception\MissingViewException;
27
28
use function count;
29
use function func_get_args;
30
use function implode;
31
32
/**
33
 * Static content controller.
34
 *
35
 * Override this controller by placing a copy in controllers directory of an application
36
 *
37
 * @see    http://book.cakephp.org/2.0/en/controllers/pages-controller.html
38
 */
39
class PagesController extends AppController
40
{
41
    /**
42
     * Controller name.
43
     *
44
     * @var string
45
     */
46
    public $name = 'Pages';
47
48
    /**
49
     * Displays a view.
50
     *
51
     * @throws NotFoundException when the view file could not be found
52
     *                           or MissingViewException in debug mode.
53
     * @return mixed A Response of nothing
54
     */
55
    public function display()
56
    {
57
        $path = func_get_args();
58
59
        $count = count($path);
60
        if (! $count) {
61
            return $this->redirect('/');
62
        }
63
64
        $page = $subpage = $title_for_layout = null;
65
        if (! empty($path[0])) {
66
            $page = $path[0];
67
        }
68
69
        if (! empty($path[1])) {
70
            $subpage = $path[1];
71
        }
72
73
        if (! empty($path[$count - 1])) {
74
            $title_for_layout = Inflector::humanize($path[$count - 1]);
75
        }
76
77
        $this->set([
78
            'page' => $page,
79
            'subpage' => $subpage,
80
            'title_for_layout' => $title_for_layout,
81
        ]);
82
83
        try {
84
            $this->render(implode('/', $path));
85
        } catch (MissingViewException $e) {
86
            if (Configure::read('debug')) {
87
                throw $e;
88
            }
89
90
            throw new NotFoundException();
91
        }
92
    }
93
}
94