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

Delete::query()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 31
Code Lines 18

Duplication

Lines 31
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 2
nop 0
dl 31
loc 31
ccs 0
cts 21
cp 0
crap 12
rs 8.8571
c 0
b 0
f 0
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
}