Completed
Push — master ( 1fa2c7...4160d6 )
by Mathieu
03:42
created

AbstractTemplate::app()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\App\Template;
4
5
// slim/slim dependencies
6
use \Slim\App as SlimApp;
7
8
// PSR-3 logger
9
use \Psr\Log\LoggerInterface;
10
use \Psr\Log\LoggerAwareInterface;
11
12
// Module `charcoal-view` dependencies
13
use \Charcoal\View\GenericView;
14
use \Charcoal\View\ViewableInterface;
15
use \Charcoal\View\ViewableTrait;
16
17
// Local namespace dependencies
18
use \Charcoal\App\Template\TemplateInterface;
19
20
/**
21
*
22
*/
23
abstract class AbstractTemplate implements
24
    LoggerAwareInterface,
25
    TemplateInterface,
26
    ViewableInterface
27
{
28
29
    use ViewableTrait;
30
31
    /**
32
    * @var LoggerInterface $logger
33
    */
34
    private $logger;
35
36
    public function __construct(array $data = null)
37
    {
38
        if (isset($data['logger'])) {
39
            $this->set_logger($data['logger']);
40
        }
41
42
        $this->set_app($data['app']);
43
    }
44
45
    /**
46
    * @param SlimApp $app
47
    * @return App Chainable
48
    */
49
    public function set_app(SlimApp $app)
50
    {
51
        $this->app = $app;
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
        return $this;
53
    }
54
55
    public function app($app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        return $this->app;
58
    }
59
60
    /**
61
    * > LoggerAwareInterface > setLogger()
62
    *
63
    * Fulfills the PSR-1 style LoggerAwareInterface
64
    *
65
    * @param LoggerInterface $logger
66
    * @return AbstractEngine Chainable
67
    */
68
    public function setLogger(LoggerInterface $logger)
69
    {
70
        return $this->set_logger($logger);
71
    }
72
73
    /**
74
    * @param LoggerInterface $logger
75
    * @return AbstractEngine Chainable
76
    */
77
    public function set_logger(LoggerInterface $logger = null)
78
    {
79
        $this->logger = $logger;
80
        return $this;
81
    }
82
83
    /**
84
    * @erturn LoggerInterface
85
    */
86
    public function logger()
87
    {
88
        return $this->logger;
89
    }
90
91
    /**
92
    * The default Template View is a simple GenericView.
93
    *
94
    * @return \Charcoal\View\ViewInterface
95
    */
96 View Code Duplication
    public function create_view(array $data = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $view = new GenericView([
99
            'logger'=>null
100
        ]);
101
        if ($data !== null) {
102
            $view->set_data($data);
103
        }
104
        return $view;
105
    }
106
}
107