AsyncHttpGenericService   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 90
ccs 15
cts 15
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getMethod() 0 4 1
A getUrl() 0 4 1
A getContent() 0 8 2
A getHeaders() 0 12 2
A execute() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Lombardo
5
 * Date: 27/12/16
6
 * Time: 16:35
7
 */
8
9
namespace AsyncHttpClient\Service;
10
11
use React\HttpClient\Response;
12
13
class AsyncHttpGenericService implements AsyncHttpService
14
{
15
16
    /**
17
     * @var string
18
     */
19
    private $method;
20
21
    /**
22
     * @var string
23
     */
24
    private $url;
25
    
26
    /**
27
     * @var string
28
     */
29
    private $content;
30
    
31 1
    /**
32
     * @var callable
33 1
     */
34 1
    private $callback;
35 1
36 1
    
37
    public function __construct($method, $url, $content, callable $callback = null)
38
    {
39
        $this->method   = $method;
40
        $this->url      = $url;
41 1
        $this->content  = $content;
42
        $this->callback = $callback;
43 1
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getMethod()
49 1
    {
50
        return $this->method;
51 1
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getUrl()
57
    {
58
        return $this->url;
59
    }
60 1
    
61
    /**
62 1
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
63 1
     */
64 1
    public function getContent()
65 1
    {
66 1
        if ($this->getMethod() == 'POST') {
67
            return $this->content;
68
        }
69
        
70
        return null;
71
    }
72
    
73
    /**
74
     * @return array
75
     */
76
    public function getHeaders()
77
    {
78
        if ($this->getMethod() == 'POST')
79
        {
80
            return [
81
                'Content-Length' => strlen($this->getContent()),
82
                'Content-Type' => 'application/x-www-form-urlencoded'
83
            ];
84
        }
85
        
86
        return [];
87
    }
88
    
89
    /**
90
     * @param          $data
91
     * @param Response $response
92
     *
93
     * @return void
94
     */
95
    public function execute($data, Response $response)
96
    {
97
        if (!is_null($this->callback)) {
98
            $callback = $this->callback;
99
            $callback($data, $response);
100
        }
101
    }
102
}
103