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

Create   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 8
cts 28
cp 0.2857
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A injectionKernel() 0 4 1
A getUrl() 0 4 1
A processData() 0 5 1
A setData() 0 4 1
B query() 0 24 1
1
<?php
2
namespace agoalofalife\bpm\Actions;
3
4
use agoalofalife\bpm\Contracts\Action;
5
use agoalofalife\bpm\Contracts\ActionSet;
6
use agoalofalife\bpm\Contracts\Authentication;
7
use agoalofalife\bpm\KernelBpm;
8
9
10
/**
11
 * Class Create
12
 * Class to create a new object in the BPM
13
 *
14
 * @property KernelBpm kernel
15
 * @property string HTTP_TYPE
16
 * @property array data
17
 * @package agoalofalife\bpm\Actions
18
 */
19
class Create implements Action, ActionSet
20
{
21
    protected $kernel;
22
    protected $url = '/';
23
    /**
24
     * Request type to created
25
     * @var string
26
     */
27
    protected $HTTP_TYPE = 'POST';
28
    protected $data = [];
29
30 1
    public function injectionKernel(KernelBpm $bpm)
31
    {
32 1
        $this->kernel = $bpm;
33 1
    }
34
35 1
    public function getUrl()
36
    {
37 1
        return $this->url;
38
    }
39
40
    public function processData()
41
    {
42
        $this->query();
43
        return $this->kernel->getHandler();
44
    }
45
46 1
    public function setData(array $data)
47
    {
48 1
        $this->data = $data;
49 1
    }
50
51
    private function query()
52
    {
53
        $parameters = str_replace(' ', '%20', $this->url);
54
55
        $url        = $this->kernel->getCollection() . $parameters;
56
        $urlHome    = config($this->kernel->getPrefixConfig() . '.UrlHome');
57
58
        $response   =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
59
                [
60
                    'headers' => [
61
                        'HTTP/1.0',
62
                        'Accept'       => $this->kernel->getHandler()->getAccept(),
63
                        'Content-type' => $this->kernel->getHandler()->getContentType(),
64
                        app()->make(Authentication::class)->getPrefixCSRF()     => app()->make(Authentication::class)->getCsrf(),
65
                    ],
66
                    'curl' => [
67
                        CURLOPT_COOKIEFILE => app()->make(Authentication::class)->getPathCookieFile(),
68
                    ],
69
                    'body' => $this->kernel->getHandler()->create($this->data),
70
                    'http_errors' => false
71
                ]);
72
        $body       = $response->getBody();
73
        $this->kernel->getHandler()->parse($body->getContents());
74
    }
75
}