Completed
Push — master ( 3a1449...d95c29 )
by Jean
02:46
created

MappingProcessor::process()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 0
cts 29
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 25
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * @author Jean Silva <[email protected]>
4
 * @license MIT
5
 */
6
namespace Jeancsil\FlightSpy\History\ElasticSearch;
7
8
class MappingProcessor implements Processor
9
{
10
    /**
11
     * @var array
12
     */
13
    private $dataCache;
14
15
    public function process(array $data) {
16
        $this->dataCache = $data;
17
18
        $mappedData = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
19
        $mappedData['Creation'] = (new \DateTime())->format(\DATE_ATOM);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20
        $mappedData['SessionKey'] = $data['SessionKey'];
21
        $mappedData['Status'] = $data['Status'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
22
        $mappedData['Query'] = $data['Query'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
23
        unset($mappedData['Query']['LocationSchema']);
24
25
        $mappedData['Query']['OriginPlace'] = $this->getPlaceNameById($data['Query']['OriginPlace']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
        $mappedData['Query']['DestinationPlace'] = $this->getPlaceNameById($data['Query']['DestinationPlace']);
27
        $mappedData['Query']['OutboundDate'] = $this->formatDate($mappedData['Query']['OutboundDate']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28
        $mappedData['Query']['InboundDate'] = $this->formatDate($mappedData['Query']['InboundDate']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
30
        $count = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 21 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $mappedData['Itineraries'] = [];
32
        foreach ($data['Itineraries'] as $itinerary) {
33
            $outboundCarrier = $this->getCarrier($itinerary['OutboundLegId']);
34
            $inboundCarrier = $this->getCarrier($itinerary['InboundLegId']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
36
            foreach ($itinerary['PricingOptions'] as $priceOption) {
37
                $mappedData['Itineraries'][$count] = [
38
                    'Price' => $priceOption['Price'],
39
                    'Deeplink' => 'none',//$priceOption['DeeplinkUrl'],
40
                    'OutboundCarrier' => $outboundCarrier['Name'],
41
                    'InboundCarrier' => $inboundCarrier['Name'],
42
                ];
43
            }
44
45
            $count++;
46
        }
47
48
        return $mappedData;
49
    }
50
51
    private function formatDate($date) {
52
        return (new \DateTime($date))
53
            ->format(\DATE_ATOM);
54
    }
55
56
    /**
57
     * @param $placeId
58
     * @return string
59
     */
60
    private function getPlaceNameById($placeId) {
61
        foreach ($this->dataCache['Places'] as $place) {
62
            if ($place['Id'] == $placeId) {
63
                return $place['Name'];
64
            }
65
        }
66
    }
67
68
    /**
69
     * @param $legId
70
     * @return array
71
     */
72
    private function getCarrier($legId) {
73
        foreach ($this->dataCache['Legs'] as $leg) {
74
            if ($leg['Id'] == $legId) {
75
                foreach ($this->dataCache['Carriers'] as $carrier) {
76
                    if ($carrier['Id'] == $leg['Carriers'][0]) {
77
                        return $carrier;
78
                    }
79
                }
80
            }
81
        }
82
    }
83
}
84