Passed
Push — master ( ef19e3...1810ac )
by Korotkov
16:58 queued 08:39
created

HttpErrors::error404()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Common;
4
5
use Rudra\Exceptions\RouterException;
6
7
trait HttpErrors
8
{
9
    public function handle404($data, string $type = 'db', array $page = [])
10
    {
11
        if ($type == 'db') {
12
            if (count($data) < 1 || !$data) {
13
                throw new RouterException('404');
14
            }
15
        } elseif ($type == 'pagination') {
16
            if ($page['id'] > count($data)) {
17
                throw new RouterException('404');
18
            }
19
        }
20
    }
21
22
    public function error404()
23
    {
24
        $this->redirect()->responseCode('404');
25
26
        return $this->twig('errors/404.html.twig', [
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->twig('errors/404.... $this->data('title'))) targeting App\Common\HttpErrors::twig() 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 getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
            'title' => '404 Page Not Found :: ' . $this->data('title'),
0 ignored issues
show
Bug introduced by
Are you sure $this->data('title') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

27
            'title' => '404 Page Not Found :: ' . /** @scrutinizer ignore-type */ $this->data('title'),
Loading history...
28
        ]);
29
    }
30
31
    public function error503()
32
    {
33
        $this->redirect()->responseCode('503');
34
35
        return $this->twig('errors/503.html.twig', [
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->twig('errors/503.... $this->data('title'))) targeting App\Common\HttpErrors::twig() 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 getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
            'title' => '503 Service Unavailable :: ' . $this->data('title'),
0 ignored issues
show
Bug introduced by
Are you sure $this->data('title') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

36
            'title' => '503 Service Unavailable :: ' . /** @scrutinizer ignore-type */ $this->data('title'),
Loading history...
37
        ]);
38
    }
39
40
    public function error500()
41
    {
42
        $this->redirect()->responseCode('503');
43
44
        return $this->twig('errors/503.html.twig', [
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->twig('errors/503.... $this->data('title'))) targeting App\Common\HttpErrors::twig() 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 getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
            'title' => '503 Service Unavailable :: ' . $this->data('title'),
0 ignored issues
show
Bug introduced by
Are you sure $this->data('title') of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

45
            'title' => '503 Service Unavailable :: ' . /** @scrutinizer ignore-type */ $this->data('title'),
Loading history...
46
        ]);
47
    }
48
49
    /**
50
     * @param null $target
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $target is correct as it would always require null to be passed?
Loading history...
51
     *
52
     * @return mixed
53
     */
54
    public abstract function redirect($target = null);
55
56
    /**
57
     * @param string $template
58
     * @param array  $params
59
     */
60
    public abstract function twig(string $template, array $params = []): void;
61
62
    /**
63
     * @param string $key
64
     *
65
     * @return string|array
66
     */
67
    public abstract function data(string $key = null);
68
}
69