Passed
Branch master (44bfae)
by giu
03:41
created

PagesController::display()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.0109

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 18
c 1
b 0
f 0
nc 14
nop 0
dl 0
loc 28
ccs 17
cts 18
cp 0.9444
crap 8.0109
rs 8.4444
1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11
 * @link      http://cakephp.org CakePHP(tm) Project
12
 * @since     0.2.9
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
namespace App\Controller;
16
17
use Cake\Core\Configure;
18
use Cake\Network\Exception\ForbiddenException;
19
use Cake\Network\Exception\NotFoundException;
20
use Cake\View\Exception\MissingTemplateException;
21
22
/**
23
 * Static content controller
24
 *
25
 * This controller will render views from Template/Pages/
26
 *
27
 * @link http://book.cakephp.org/3.0/en/controllers/pages-controller.html
28
 */
29
class PagesController extends AppController
30
{
31
32
    /**
33
     * Displays a view
34
     *
35
     * @return void|\Cake\Network\Response
36
     * @throws \Cake\Network\Exception\ForbiddenException When a directory traversal attempt.
37
     * @throws \Cake\Network\Exception\NotFoundException When the view file could not
38
     *   be found or \Cake\View\Exception\MissingTemplateException in debug mode.
39
     */
40 7
    public function display()
41
    {
42 7
        $path = func_get_args();
43
44 7
        $count = count($path);
45 7
        if (!$count) {
46 1
            return $this->redirect('/');
47
        }
48 6
        if (in_array('..', $path, true) || in_array('.', $path, true)) {
49 1
            throw new ForbiddenException();
50
        }
51 5
        $page = $subpage = null;
52
53 5
        if (!empty($path[0])) {
54 5
            $page = $path[0];
55
        }
56 5
        if (!empty($path[1])) {
57
            $subpage = $path[1];
58
        }
59 5
        $this->set(compact('page', 'subpage'));
60
61
        try {
62 5
            $this->render(implode('/', $path));
63 2
        } catch (MissingTemplateException $e) {
64 2
            if (Configure::read('debug')) {
65 1
                throw $e;
66
            }
67 1
            throw new NotFoundException();
68
        }
69 3
    }
70
}
71