Passed
Branch 2.0.0 (c5bb78)
by Chubarov
09:06
created

Delete::query()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 0
dl 21
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\Contracts\Authentication;
9
use agoalofalife\bpm\KernelBpm;
10
11
/**
12
 * Class Delete
13
 * @property KernelBpm kernel
14
 * @property string HTTP_TYPE
15
 * @property string url
16
 * @property array data
17
 * @package agoalofalife\bpm\Actions
18
 */
19 View Code Duplication
class Delete implements Action, ActionGet
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
    use ConstructorUrl, QueryBuilder;
22
23
    protected $kernel;
24
    protected $url = '?';
25
    protected $data = [];
26
    /**
27
     * Type of Request to delete
28
     * @var string
29
     */
30
    protected $HTTP_TYPE = 'DELETE';
31
32
    public function injectionKernel(KernelBpm $bpm)
33
    {
34
        $this->kernel = $bpm;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getUrl()
41
    {
42
        return $this->url;
43
    }
44
45
    /**
46
     * @return \agoalofalife\bpm\Contracts\Handler
47
     */
48
    public function processData()
49
    {
50
        $this->query();
51
        return $this->kernel->getHandler();
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getData()
58
    {
59
        return $this->getData();
60
    }
61
62
    private function query()
63
    {
64
        $parameters = str_replace(' ', '%20', $this->url);
65
66
        $url        = $this->kernel->getCollection() . $parameters;
67
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
68
69
70
        $response =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
71
                     $this->headers()->getCookie()->httpErrorsFalse()->get()
72
        );
73
74
        $body = $response->getBody();
75
        $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...
76
77
        if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' )
78
        {
79
            $this->kernel->authentication();
80
            $this->query();
81
        }
82
    }
83
}