Passed
Branch 2.0.0 (25c5b4)
by Chubarov
02:54
created

Delete::query()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 0
dl 0
loc 21
ccs 0
cts 15
cp 0
crap 12
rs 9.3142
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\QueryBuilder;
6
use agoalofalife\bpm\Contracts\Action;
7
use agoalofalife\bpm\Contracts\ActionGet;
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
19
{
20
    use ConstructorUrl, QueryBuilder;
21
22
    protected $kernel;
23
    protected $url = '?';
24
    /**
25
     * Type of Request to delete
26
     * @var string
27
     */
28
    protected $HTTP_TYPE = 'DELETE';
29
30
    public function injectionKernel(KernelBpm $bpm)
31
    {
32
        $this->kernel = $bpm;
33
    }
34
35
    /**
36
     * @return string
37
     */
38 2
    public function getUrl()
39
    {
40 2
        return $this->url;
41
    }
42
43
    /**
44
     * @return \agoalofalife\bpm\Contracts\Handler
45
     */
46
    public function processData()
47
    {
48
        $this->query();
49
        return $this->kernel->getHandler();
50
    }
51
52
    private function query()
53
    {
54
        $parameters = str_replace(' ', '%20', $this->url);
55
56
        $url        = $this->kernel->getCollection() . $parameters;
57
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
58
59
60
        $response =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
61
                     $this->headers()->getCookie()->httpErrorsFalse()->get()
62
        );
63
64
        $body = $response->getBody();
65
        $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...
66
67
        if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' )
68
        {
69
            $this->kernel->authentication();
70
            $this->query();
71
        }
72
    }
73
}