1
|
|
|
<?php |
2
|
|
|
namespace agoalofalife\bpm\Actions; |
3
|
|
|
|
4
|
|
|
use agoalofalife\bpm\Assistants\QueryBuilder; |
5
|
|
|
use agoalofalife\bpm\Contracts\Action; |
6
|
|
|
use agoalofalife\bpm\Contracts\ActionSet; |
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
|
|
|
use QueryBuilder; |
22
|
|
|
|
23
|
|
|
protected $kernel; |
24
|
|
|
protected $url = '/'; |
25
|
|
|
/** |
26
|
|
|
* Request type to created |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $HTTP_TYPE = 'POST'; |
30
|
|
|
protected $data = []; |
31
|
|
|
|
32
|
2 |
|
public function injectionKernel(KernelBpm $bpm) |
33
|
|
|
{ |
34
|
2 |
|
$this->kernel = $bpm; |
35
|
2 |
|
} |
36
|
|
|
|
37
|
1 |
|
public function getUrl() |
38
|
|
|
{ |
39
|
1 |
|
return $this->url; |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function processData() |
43
|
|
|
{ |
44
|
1 |
|
$this->query(); |
45
|
1 |
|
return $this->kernel->getHandler(); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function setData(array $data) |
49
|
|
|
{ |
50
|
1 |
|
$this->data = $data; |
51
|
1 |
|
} |
52
|
|
|
|
53
|
1 |
|
private function query() |
54
|
|
|
{ |
55
|
1 |
|
$parameters = str_replace(' ', '%20', $this->url); |
56
|
|
|
|
57
|
1 |
|
$url = $this->kernel->getCollection() . $parameters; |
58
|
1 |
|
$urlHome = config($this->kernel->getPrefixConfig() . '.UrlHome'); |
59
|
|
|
|
60
|
1 |
|
$this->headers()->getCookie()->body()->httpErrorsFalse()->get(); |
|
|
|
|
61
|
1 |
|
$response = $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url, |
62
|
1 |
|
$this->headers()->getCookie()->body()->httpErrorsFalse()->get() |
63
|
1 |
|
); |
64
|
1 |
|
$body = $response->getBody(); |
65
|
1 |
|
$this->kernel->getHandler()->parse($body->getContents()); |
|
|
|
|
66
|
|
|
|
67
|
1 |
|
if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' ) |
68
|
1 |
|
{ |
69
|
|
|
$this->kernel->authentication(); |
70
|
|
|
$this->query(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: