Passed
Branch 2.0.0 (c5bb78)
by Chubarov
09:06
created

Delete   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 65
loc 65
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A injectionKernel() 4 4 1
A getUrl() 4 4 1
A processData() 5 5 1
A getData() 4 4 1
A query() 21 21 3

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
namespace agoalofalife\bpm\Actions;
3
4
use agoalofalife\bpm\Assistants\ConstructorUrl;
5
use agoalofalife\bpm\Assistants\QueryBuilder;
6
use agoalofalife\bpm\Contracts\Action;
7
use agoalofalife\bpm\Contracts\ActionGet;
8
use agoalofalife\bpm\Contracts\Authentication;
9
use agoalofalife\bpm\KernelBpm;
10
11
/**
12
 * Class Delete
13
 * @property KernelBpm kernel
14
 * @property string HTTP_TYPE
15
 * @property string url
16
 * @property array data
17
 * @package agoalofalife\bpm\Actions
18
 */
19 View Code Duplication
class Delete implements Action, ActionGet
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
    use ConstructorUrl, QueryBuilder;
22
23
    protected $kernel;
24
    protected $url = '?';
25
    protected $data = [];
26
    /**
27
     * Type of Request to delete
28
     * @var string
29
     */
30
    protected $HTTP_TYPE = 'DELETE';
31
32
    public function injectionKernel(KernelBpm $bpm)
33
    {
34
        $this->kernel = $bpm;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getUrl()
41
    {
42
        return $this->url;
43
    }
44
45
    /**
46
     * @return \agoalofalife\bpm\Contracts\Handler
47
     */
48
    public function processData()
49
    {
50
        $this->query();
51
        return $this->kernel->getHandler();
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getData()
58
    {
59
        return $this->getData();
60
    }
61
62
    private function query()
63
    {
64
        $parameters = str_replace(' ', '%20', $this->url);
65
66
        $url        = $this->kernel->getCollection() . $parameters;
67
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
68
69
70
        $response =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
71
                     $this->headers()->getCookie()->httpErrorsFalse()->get()
72
        );
73
74
        $body = $response->getBody();
75
        $this->kernel->getHandler()->parse($body->getContents());
0 ignored issues
show
Bug introduced by
The method parse() does not seem to exist on object<Illuminate\Container\Container>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
77
        if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' )
78
        {
79
            $this->kernel->authentication();
80
            $this->query();
81
        }
82
    }
83
}