Completed
Branch 2.0.0 (a6ce5f)
by Chubarov
06:30 queued 03:11
created

Delete::query()   B

Complexity

Conditions 4
Paths 7

Size

Total Lines 34
Code Lines 19

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 7
nop 0
dl 34
loc 34
rs 8.5806
c 0
b 0
f 0
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\Authentication;
9
use agoalofalife\bpm\KernelBpm;
10
use GuzzleHttp\ClientInterface;
11
use GuzzleHttp\Exception\ClientException;
12
13
/**
14
 * Class Delete
15
 * @property KernelBpm kernel
16
 * @property string HTTP_TYPE
17
 * @property string url
18
 * @property array data
19
 * @package agoalofalife\bpm\Actions
20
 */
21
class Delete implements Action, ActionGet
22
{
23
    use ConstructorUrl;
24
25
    protected $kernel;
26
    protected $url = '?';
27
    protected $data = [];
28
    /**
29
     * Type of Request to delete
30
     * @var string
31
     */
32
    protected $HTTP_TYPE = 'DELETE';
33
34
    public function injectionKernel(KernelBpm $bpm)
35
    {
36
        $this->kernel = $bpm;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getUrl()
43
    {
44
        return $this->url;
45
    }
46
47
    /**
48
     * @return \agoalofalife\bpm\Contracts\Handler
49
     */
50
    public function processData()
51
    {
52
        $this->query();
53
        return $this->kernel->getHandler();
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getData()
60
    {
61
        return $this->getData();
62
    }
63
64 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...
65
    {
66
        $parameters = str_replace(' ', '%20', $this->url);
67
68
        $url        = $this->kernel->getCollection() . $parameters;
69
        $client     = app()->make(ClientInterface::class);
70
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
71
72
73
        try {
74
            $response = $client->request($this->HTTP_TYPE, $urlHome . $url,
75
                [
76
                    'headers' => [
77
                        'HTTP/1.0',
78
                        'Accept'       => $this->kernel->getHandler()->getAccept(),
79
                        'Content-type' => $this->kernel->getHandler()->getContentType(),
80
//                        app()->make(Authentication::class)->getPrefixCSRF()     => app()->make(Authentication::class)->getCsrf(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
                    ],
82
                    'curl' => [
83
                        CURLOPT_COOKIEFILE => app()->make(Authentication::class)->getPathCookieFile(),
84
                    ]
85
                ]);
86
87
            $body = $response->getBody();
88
            $this->kernel->getHandler()->parse($body->getContents());
89
        } catch (ClientException $e) {
90
91
            if ($e->getResponse()->getStatusCode() == 401 && $e->getResponse()->getReasonPhrase() == 'Unauthorized')
92
            {
93
                $this->kernel->authentication();
94
                return $this->query();
95
            }
96
        }
97
    }
98
}