Test Failed
Push — master ( e18acf...2713a2 )
by Marcio
12:48
created

View::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * KNUT7 K7F (https://marciozebedeu.com/)
5
 * KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/).
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @see      https://github.com/knut7/framework/ for the canonical source repository
12
 *
13
 * @copyright (c) 2015.  KNUT7  Software Technologies AO Inc. (https://marciozebedeu.com/)
14
 * @license   https://marciozebedeu.com/license/new-bsd New BSD License
15
 * @author    Marcio Zebedeu - [email protected]
16
 *
17
 * @version   1.0.2
18
 *
19
 *   Includes - Ability to include other views
20
 *
21
 *   Captures - Ability to easily capture content within your view
22
 *
23
 *   Layouts - Ability to inject data into a re-usable layout template
24
 *
25
 *   Fetching - Ability to fetch view output instead of sending it to output buffer
26
 *
27
 *   data - Ability to access the resulting data once the view is finished
28
 *
29
 * *NOTE* When a view uses a layout, the output of the view is ignored, as
30
 *        as the view is expected to use capture() to send data to the layout.
31
 * @property  UserData propriedade gerada e usada para pegar dados do model
32
 */
33
34
namespace Ballybran\Core\View;
35
36
use Ballybran\Core\Collections\Collection\IteratorDot;
37
use Ballybran\Helpers\Security\RenderFiles;
38
use \Ballybran\Helpers\Event\Registry;
39
40
class View extends RenderFiles implements ViewrInterface, \ArrayAccess
41
{
42
    public string $view;
43
    public array $data = array();
44
    protected string $controllers;
45
    private Form $form;
0 ignored issues
show
Bug introduced by
The type Ballybran\Core\View\Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
introduced by
The private property $form is not used, and could be removed.
Loading history...
46
    private Registry $reg;
47
    public IteratorDot $dot;
48
49
    /**
50
     * @var string title for meta title
51
     */
52
    public $title;
53
54
    public function __construct()
55
    {
56
        $this->reg = Registry::getInstance();
57
        $this->data;
58
        $this->dot = new IteratorDot();
59
    }
60
61
    /**
62
     * render.
63
     *
64
     * @param mixed $controller
65
     * @param mixed $view
66
     * @param mixed $data
67
     *
68
     * @return string
69
     */
70
    public function render(object $controller, string $view): string
71
    {
72
        ob_start();
73
        $data = (null === $this->get_data()) ? array() : $this->get_data();
0 ignored issues
show
introduced by
The condition null === $this->get_data() is always false.
Loading history...
74
        $this->dot->merge($data);
75
        $this->view = $view;
76
        $remove_namespace = explode('\\', get_class($controller));
77
        $this->controllers = $remove_namespace[3];
78
        extract($this->get_data());
79
        $this->isHeader();
80
81
        include VIEW . $this->controllers . DS . $this->view . $this->ex;
82
        $this->isFooter();
83
84
        $content = ob_get_contents();
85
        return $content;
86
    }
87
88
89
    public function fetch($data = null)
90
    {
91
        ob_start();
92
        $this->render($this->controllers, $this->view, $data);
0 ignored issues
show
Unused Code introduced by
The call to Ballybran\Core\View\View::render() has too many arguments starting with $data. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
        $this->/** @scrutinizer ignore-call */ 
93
               render($this->controllers, $this->view, $data);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
$this->controllers of type string is incompatible with the type object expected by parameter $controller of Ballybran\Core\View\View::render(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
        $this->render(/** @scrutinizer ignore-type */ $this->controllers, $this->view, $data);
Loading history...
93
94
        return ob_get_clean();
95
    }
96
97
    public function add(array $data) : void
98
    {
99
        $this->data = array_merge( $this->data, $data );
100
101
    }
102
103
    public function get_data() : array
104
    {
105
        return $this->data;
106
    }
107
108
    protected function capture()
109
    {
110
        ob_start();
111
    }
112
113
    protected function end_capture($name)
114
    {
115
        $this->data[$name] = ob_get_clean();
116
    }
117
118
    private function init(): bool
0 ignored issues
show
Unused Code introduced by
The method init() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
119
    {
120
        $this->isViewPath($this->controllers);
121
        $this->isIndex($this->controllers, $this->view);
122
123
        return true;
124
    }
125
126
    public function offsetExists($offset) : bool
127
    {
128
        return isset($this->data[$offset]);
129
    }
130
131
    public function offsetGet($offset) : string
132
    {
133
        return $this->data[$offset];
134
    }
135
136
    public function offsetSet($offset, $value) : void
137
    {
138
        $this->data[$offset] = $value;
139
    }
140
141
    public function offsetUnset($offset) : void
142
    {
143
        unset($this->data[$offset]);
144
    }
145
}
146