Template_Controller::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 2
b 1
f 0
nc 2
nop 0
dl 0
loc 12
rs 9.4285
1
<?php defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * Allows a template to be automatically loaded and displayed. Display can be
4
 * dynamically turned off in the controller methods, and the template file
5
 * can be overloaded.
6
 *
7
 * To use it, declare your controller to extend this class:
8
 * `class Your_Controller extends Template_Controller`
9
 *
10
 * $Id: template.php 3769 2008-12-15 00:48:56Z zombor $
11
 *
12
 * @package    Core
13
 * @author     Kohana Team
14
 * @copyright  (c) 2007-2008 Kohana Team
15
 * @license    http://kohanaphp.com/license.html
16
 */
17
abstract class Template_Controller extends Controller
18
{
19
20
    // Template view name
21
    public $template = 'template';
22
23
    // Default to do auto-rendering
24
    public $auto_render = true;
25
26
    /**
27
     * Template loading and setup routine.
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
33
        // Load the template
34
        $this->template = new View($this->template);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \View($this->template) of type object<View> is incompatible with the declared type string of property $template.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
36
        if ($this->auto_render == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
37
            // Render the template immediately after the controller method
38
            Event::add('system.post_controller', array($this, '_render'));
39
        }
40
    }
41
42
    /**
43
     * Render the loaded template.
44
     */
45
    public function _render()
46
    {
47
        if ($this->auto_render == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
48
            // Render the template when the class is destroyed
49
            $this->template->render(true);
0 ignored issues
show
Bug introduced by
The method render cannot be called on $this->template (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
50
        }
51
    }
52
} // End Template_Controller
53