Template   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fetch() 0 22 2
1
<?php
2
/**
3
 * basic output functions
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Output
9
 * @author    Damien Roth <[email protected]>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 * @version   SVN: $Id: class.Output.inc.php 315 2009-09-02 15:48:31Z bigmichi1 $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
/**
16
 * basic output functions for all output formats
17
 *
18
 * @category  PHP
19
 * @package   PSI_Output
20
 * @author    Damien Roth <[email protected]>
21
 * @copyright 2009 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class Template
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * Vars used in the template
30
     *
31
     * @Array
32
     */
33
    private $_vars;
34
35
    /**
36
     * Template file
37
     *
38
     * @String
39
     */
40
    private $_file;
41
42
    /**
43
     * Constructor
44
     *
45
     * @param String $file the template file name
0 ignored issues
show
Documentation introduced by
Should the type for parameter $file not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
46
     */
47
    public function __construct($file=null)
48
    {
49
        $this->_file = $file;
50
        $this->_vars = array();
51
    }
52
53
    /**
54
     * Set a template variable.
55
     *
56
     * @param string variable name
57
     * @param string variable value
58
     */
59
    public function set($name, $value)
60
    {
61
        $this->_vars[$name] = is_object($value) ? $value->fetch() : $value;
62
    }
63
64
    /**
65
     * Open, parse, and return the template file.
66
     *
67
     * @param string $file
0 ignored issues
show
Documentation introduced by
Should the type for parameter $file not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
68
     *
69
     * @return string
70
     */
71
    public function fetch($file=null)
72
    {
73
        if (!$file) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
74
            $file = $this->_file;
75
        }
76
77
        // Extract the vars to local namespace
78
        extract($this->_vars);
79
80
        // Start output buffering
81
        ob_start();
82
83
        include(APP_ROOT.$file);
84
85
        // Get the contents of the buffer
86
        $contents = ob_get_contents();
87
88
        // End buffering and discard
89
        ob_end_clean();
90
91
        return $contents;
92
    }
93
}
94