Completed
Push — master ( d056fc...eab060 )
by Korotkov
05:25
created

HttpErrors   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 38.1 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 24
loc 63
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
B handle404() 0 12 6
A error404() 8 8 1
A error503() 8 8 1
A error500() 8 8 1
redirect() 0 1 ?
twig() 0 1 ?
data() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Web\Supports;
4
5
use Rudra\RouterException;
6
7
trait HttpErrors
8
{
9
10
    public function handle404($data, string $type = 'db', array $page = [])
11
    {
12
        if ($type == 'db') {
13
            if (count($data) < 1 || !$data) {
14
                throw new RouterException('404');
15
            }
16
        } elseif ($type == 'pagination') {
17
            if ($page['id'] > count($data)) {
18
                throw new RouterException('404');
19
            }
20
        }
21
    }
22
23 View Code Duplication
    public function error404()
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...
24
    {
25
        $this->redirect()->responseCode('404');
26
27
        return $this->twig('errors/404.html.twig', [
28
            'title' => '404 Page Not Found :: ' . $this->data('title'),
29
        ]);
30
    }
31
32 View Code Duplication
    public function error503()
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...
33
    {
34
        $this->redirect()->responseCode('503');
35
36
        return $this->twig('errors/503.html.twig', [
37
            'title' => '503 Service Unavailable :: ' . $this->data('title'),
38
        ]);
39
    }
40
41 View Code Duplication
    public function error500()
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...
42
    {
43
        $this->redirect()->responseCode('503');
44
45
        return $this->twig('errors/503.html.twig', [
46
            'title' => '503 Service Unavailable :: ' . $this->data('title'),
47
        ]);
48
    }
49
50
    /**
51
     * @param null $target
52
     *
53
     * @return mixed
54
     */
55
    public abstract function redirect($target = null);
56
57
    /**
58
     * @param string $template
59
     * @param array  $params
60
     */
61
    public abstract function twig(string $template, array $params = []): void;
62
63
    /**
64
     * @param string $key
65
     *
66
     * @return string|array
67
     */
68
    public abstract function data(string $key = null);
69
}