FakeTransport::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author Jean Silva <[email protected]>
4
 * @license MIT
5
 */
6
namespace Jeancsil\FlightSpy\Api\Http;
7
8
use Jeancsil\FlightSpy\Api\DataTransfer\SessionParameters;
9
10
class FakeTransport implements TransportInterface
11
{
12
    const RESPONSE_FILE = 'skyscanner_response.json';
13
14
    /**
15
     * @var string
16
     */
17
    private $resourcesDir;
18
19
    public function __construct($resourcesDir)
20
    {
21
        $this->resourcesDir = $resourcesDir;
22
    }
23
24
    /**
25
     * @param SessionParameters $parameters
26
     * @param bool $newSession
27
     * @return \stdClass
28
     */
29
    public function findQuotes(SessionParameters $parameters, $newSession)
30
    {
31
        try {
32
            $contents = file_get_contents($this->resourcesDir . '/' . static::RESPONSE_FILE);
33
34
            $arrayContent = \GuzzleHttp\json_decode(
35
                str_replace("'", '\'', $contents),
36
                true
37
            );
38
39
            return (object) $arrayContent;
40
        } catch (\Exception $e) {
41
            // do nothing
42
        }
43
    }
44
}
45