1 | <?php |
||
2 | |||
3 | namespace MiladRahimi\PhpRouter\View; |
||
4 | |||
5 | /** |
||
6 | * It makes views from PHP and HTML/PHP files |
||
7 | */ |
||
8 | class PhpView implements View |
||
9 | { |
||
10 | /** |
||
11 | * The root directory of view files |
||
12 | */ |
||
13 | private string $directory; |
||
14 | |||
15 | public function __construct(string $directory) |
||
16 | { |
||
17 | $this->directory = $directory; |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @inheritDoc |
||
22 | */ |
||
23 | public function make(string $name, array $data = [], int $httpStatus = 200, array $httpHeaders = []) |
||
24 | { |
||
25 | $file = str_replace('.', DIRECTORY_SEPARATOR, $name) . '.phtml'; |
||
26 | $path = join('/', [$this->directory, $file]); |
||
27 | |||
28 | http_response_code($httpStatus); |
||
29 | |||
30 | foreach ($httpHeaders as $name => $values) { |
||
31 | @header($name . ': ' . $values); |
||
0 ignored issues
–
show
Are you sure the usage of
header($name . ': ' . $values) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
32 | } |
||
33 | |||
34 | extract($data); |
||
35 | |||
36 | require $path; |
||
37 | |||
38 | return null; |
||
39 | } |
||
40 | } |
If you suppress an error, we recommend checking for the error condition explicitly: