Completed
Push — master ( 2c9d27...9c0bb9 )
by Cheren
03:04
created

AppView::beforeLayout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View;
17
18
use Core\Plugin;
19
use Cake\View\View;
20
use JBZoo\Utils\FS;
21
22
/**
23
 * Class AppView
24
 *
25
 * @package Core\View
26
 * @property \Core\View\Helper\AssetsHelper $Assets
27
 * @property \Core\View\Helper\DocumentHelper $Document
28
 * @property \Core\View\Helper\FormHelper $Form
29
 * @property \Core\View\Helper\UrlHelper $Url
30
 * @property \Core\View\Helper\LessHelper $Less
31
 * @property \Core\View\Helper\HtmlHelper $Html
32
 */
33
class AppView extends View
34
{
35
36
    /**
37
     * Initialization hook method.
38
     *
39
     * Properties like $helpers etc. cannot be initialized statically in your custom
40
     * view class as they are overwritten by values from controller in constructor.
41
     * So this method allows you to manipulate them as required after view instance
42
     * is constructed.
43
     *
44
     * @return void
45
     */
46
    public function initialize()
47
    {
48
        parent::initialize();
49
        Plugin::manifestEvent('View.initialize', $this);
50
    }
51
52
    /**
53
     * Render layout partial.
54
     *
55
     * @param string $name
56
     * @param array $data
57
     * @return null|string
58
     */
59
    public function partial($name, array $data = [])
60
    {
61
        $file = $this->_getLayoutPartialPath($name);
62
63
        if (FS::isFile($file)) {
0 ignored issues
show
Security Bug introduced by
It seems like $file defined by $this->_getLayoutPartialPath($name) on line 61 can also be of type false; however, JBZoo\Utils\FS::isFile() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
64
            return $this->_render($file, $data);
0 ignored issues
show
Security Bug introduced by
It seems like $file defined by $this->_getLayoutPartialPath($name) on line 61 can also be of type false; however, Cake\View\View::_render() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
65
        }
66
67
        return null;
68
    }
69
70
    /**
71
     * Finds an partial filename, returns false on failure.
72
     *
73
     * @param string $name
74
     * @return bool|string
75
     */
76
    protected function _getLayoutPartialPath($name)
77
    {
78
        list($plugin, $name) = $this->pluginSplit($name);
79
80
        $paths       = $this->_paths($plugin);
81
        $layoutPaths = $this->_getSubPaths('Layout' . DS . 'Partial');
82
83
        foreach ($paths as $path) {
84
            foreach ($layoutPaths as $layoutPath) {
85
                $partial = $path . $layoutPath . DS . $name . $this->_ext;
86
                if (FS::isFile($partial)) {
87
                    return $partial;
88
                }
89
            }
90
        }
91
92
        return false;
93
    }
94
}
95