Completed
Push — master ( bc3bf5...3f770a )
by smiley
02:50
created

MultiResponseHandlerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 2
c 5
b 0
f 1
lcom 1
cbo 1
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handleResponse() 0 13 1
1
<?php
2
/**
3
 * Class MultiResponseHandlerTest
4
 *
5
 * @filesource   MultiResponseHandlerTest.php
6
 * @created      15.02.2016
7
 * @package      chillerlan\TinyCurl
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2016 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\TinyCurlTest;
14
15
use chillerlan\TinyCurl\MultiRequest;
16
use chillerlan\TinyCurl\Response\MultiResponseHandlerInterface;
17
use chillerlan\TinyCurl\Response\ResponseInterface;
18
use stdClass;
19
20
/**
21
 *
22
 */
23
class MultiResponseHandlerTest implements MultiResponseHandlerInterface{
24
25
	/**
26
	 * @var \chillerlan\TinyCurl\MultiRequest
27
	 */
28
	protected $request;
29
30
	public function __construct(MultiRequest $request){
31
		$this->request = $request;
32
	}
33
34
	/**
35
	 * @param \chillerlan\TinyCurl\Response\ResponseInterface $response
36
	 *
37
	 * @return mixed
38
	 */
39
	public function handleResponse(ResponseInterface $response){
40
		$data = new stdClass;
41
		$data->errorcode             = $response->error->code;
0 ignored issues
show
Bug introduced by
Accessing error on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
42
		$data->statuscode            = $response->info->http_code;
0 ignored issues
show
Bug introduced by
Accessing info on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
43
		$data->content_length_header = $response->headers->{'content-length'};
0 ignored issues
show
Bug introduced by
Accessing headers on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
44
		$data->content_length_body   = $response->body->length;
0 ignored issues
show
Bug introduced by
Accessing body on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
45
		$data->content_type          = $response->body->content_type;
0 ignored issues
show
Bug introduced by
Accessing body on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
46
		$data->ids                   = array_column($response->json, 'id');
0 ignored issues
show
Bug introduced by
Accessing json on the interface chillerlan\TinyCurl\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
47
48
		sort($data->ids);
49
50
		$this->request->addResponse($data);
51
	}
52
53
}
54