Passed
Branch 2.0.0 (1a6d28)
by Chubarov
06:39
created

Delete   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 41.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 31
loc 75
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A injectionKernel() 0 4 1
A getUrl() 0 4 1
A processData() 0 5 1
A getData() 0 4 1
B query() 31 31 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\Contracts\Action;
6
use agoalofalife\bpm\Contracts\ActionGet;
7
use agoalofalife\bpm\Contracts\Authentication;
8
use agoalofalife\bpm\KernelBpm;
9
10
/**
11
 * Class Delete
12
 * @property KernelBpm kernel
13
 * @property string HTTP_TYPE
14
 * @property string url
15
 * @property array data
16
 * @package agoalofalife\bpm\Actions
17
 */
18
class Delete implements Action, ActionGet
19
{
20
    use ConstructorUrl;
21
22
    protected $kernel;
23
    protected $url = '?';
24
    protected $data = [];
25
    /**
26
     * Type of Request to delete
27
     * @var string
28
     */
29
    protected $HTTP_TYPE = 'DELETE';
30
31
    public function injectionKernel(KernelBpm $bpm)
32
    {
33
        $this->kernel = $bpm;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getUrl()
40
    {
41
        return $this->url;
42
    }
43
44
    /**
45
     * @return \agoalofalife\bpm\Contracts\Handler
46
     */
47
    public function processData()
48
    {
49
        $this->query();
50
        return $this->kernel->getHandler();
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getData()
57
    {
58
        return $this->getData();
59
    }
60
61 View Code Duplication
    private function query()
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...
62
    {
63
        $parameters = str_replace(' ', '%20', $this->url);
64
65
        $url        = $this->kernel->getCollection() . $parameters;
66
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
67
68
69
            $response =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
70
                [
71
                    'headers' => [
72
                        'HTTP/1.0',
73
                        'Accept'       => $this->kernel->getHandler()->getAccept(),
74
                        'Content-type' => $this->kernel->getHandler()->getContentType(),
75
                        app()->make(Authentication::class)->getPrefixCSRF()     => app()->make(Authentication::class)->getCsrf(),
76
                    ],
77
                    'curl' => [
78
                        CURLOPT_COOKIEFILE => app()->make(Authentication::class)->getPathCookieFile(),
79
                    ],
80
                    'http_errors' => false
81
                ]);
82
83
            $body = $response->getBody();
84
            $this->kernel->getHandler()->parse($body->getContents());
85
86
            if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' )
87
            {
88
                $this->kernel->authentication();
89
                $this->query();
90
            }
91
    }
92
}