Test Failed
Branch 2.0.0 (a6ce5f)
by Chubarov
03:11
created

Update   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 35
loc 98
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A injectionKernel() 0 4 1
A getUrl() 0 4 1
A setData() 0 4 1
A processData() 0 5 1
A getData() 0 4 1
B query() 35 36 4

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\VerifyValues;
6
use agoalofalife\bpm\Contracts\Action;
7
use agoalofalife\bpm\Contracts\ActionGet;
8
use agoalofalife\bpm\Contracts\ActionSet;
9
use agoalofalife\bpm\Contracts\Authentication;
10
use agoalofalife\bpm\KernelBpm;
11
use GuzzleHttp\ClientInterface;
12
use GuzzleHttp\Exception\ClientException;
13
14
/**
15
 * Class Update
16
 * @property KernelBpm kernel
17
 * @property string HTTP_TYPE
18
 * @property array data
19
 * @property string url
20
 * @package agoalofalife\bpm\Actions
21
 */
22
class Update implements Action, ActionGet, ActionSet
23
{
24
    use ConstructorUrl;
25
26
    protected $url = '?';
27
28
    /**
29
     * Request type to created
30
     * @var string
31
     */
32
    protected $HTTP_TYPE = 'PUT';
33
    protected $data = [];
34
    protected $kernel;
35
36
    /**
37
     * @param KernelBpm $bpm
38
     * @return void
39
     */
40
    public function injectionKernel(KernelBpm $bpm)
41
    {
42
        $this->kernel = $bpm;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getUrl()
49
    {
50
        return $this->url;
51
    }
52
53
    /**
54
     * @param array $data
55
     * @return array
56
     */
57
    public function setData(array $data)
58
    {
59
        return $this->data = $data;
60
    }
61
62
    /**
63
     * @return \agoalofalife\bpm\Contracts\Handler
64
     */
65
    public function processData()
66
    {
67
        $this->query();
68
        return $this->kernel->getHandler();
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getData()
75
    {
76
        return $this->data;
77
    }
78
79
    /**
80
     * @return mixed
81
     */
82 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...
83
    {
84
        $parameters = str_replace(' ', '%20', $this->url);
85
86
        $url        = $this->kernel->getCollection() . $parameters;
87
        $client     = app()->make(ClientInterface::class);
88
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
89
90
91
        try {
92
            $response = $client->request($this->HTTP_TYPE, $urlHome . $url,
93
                [
94
                    'headers' => [
95
                        'HTTP/1.0',
96
                        'Accept'       => $this->kernel->getHandler()->getAccept(),
97
                        'Content-type' => $this->kernel->getHandler()->getContentType(),
98
                        app()->make(Authentication::class)->getPrefixCSRF()     => app()->make(Authentication::class)->getCsrf(),
99
                    ],
100
                    'curl' => [
101
                        CURLOPT_COOKIEFILE => app()->make(Authentication::class)->getPathCookieFile(),
102
                    ],
103
                    'body' => $this->kernel->getHandler()->create($this->data)
104
                ]);
105
106
            $body = $response->getBody();
107
108
            $this->kernel->getHandler()->parse($body->getContents());
109
        } catch (ClientException $e) {
110
111
            if ($e->getResponse()->getStatusCode() == 401 && $e->getResponse()->getReasonPhrase() == 'Unauthorized')
112
            {
113
                $this->kernel->authentication();
114
                return $this->query();
115
            }
116
        }
117
    }
118
119
}