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

MultiResponseHandlerTest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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