MappingProcessor::getArrivalDate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
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
use Jeancsil\FlightSpy\Service\ElasticSearch\Processor;
9
10
class MappingProcessor implements Processor
11
{
12
    /**
13
     * @var array
14
     */
15
    private $dataCache;
16
17
    /** @inheritdoc */
18
    public function process(array $data)
19
    {
20
        $this->dataCache = $data;
21
22
        $mappedDocuments = [];
23
        foreach ($data['Itineraries'] as $itinerary) {
24
            $outboundCarrier = $this->getCarrier($itinerary['OutboundLegId']);
25
            $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...
26
27
            foreach ($itinerary['PricingOptions'] as $priceOption) {
28
                $mappedData = [];
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...
29
                $mappedData['Creation'] = $this->formatDate('now');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
30
                $mappedData['SessionKey'] = $data['SessionKey'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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['Status'] = $data['Status'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
32
                $mappedData['Adults'] = $data['Query']['Adults'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
33
                $mappedData['Children'] = $data['Query']['Children'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
34
                $mappedData['Infants'] = $data['Query']['Infants'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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
                $mappedData['CabinClass'] = $data['Query']['CabinClass'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
36
                $mappedData['Country'] = $data['Query']['Country'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
37
                $mappedData['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...
38
                $mappedData['DestinationPlace'] = $this->getPlaceNameById($data['Query']['DestinationPlace']);
39
                $mappedData['Locale'] = $data['Query']['Locale'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
40
                $mappedData['GroupPricing'] = $data['Query']['GroupPricing'];
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...
41
                $mappedData['Departure'] = $this->getDepartureDate($itinerary['OutboundLegId']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
42
                $mappedData['Arrival'] = $this->getArrivalDate($itinerary['InboundLegId']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
43
                $mappedData['Price'] = $this->getPrice($priceOption);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
44
                $mappedData['PriceFormatted'] = $this->getPrice($priceOption, $data['Query']['Currency']);
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...
45
                $mappedData['OutboundAirline'] = $outboundCarrier['Name'];
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...
46
                $mappedData['InboundAirline'] = $inboundCarrier['Name'];
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...
47
                $mappedData['DeeplinkUrl'] = $priceOption['DeeplinkUrl'];
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...
48
49
                $mappedDocuments[] = $mappedData;
50
            }
51
        }
52
53
        $this->dataCache = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $dataCache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
55
        return $mappedDocuments;
56
    }
57
58
    private function formatDate($date)
59
    {
60
        return (new \DateTime($date))
61
            ->format(\DATE_ATOM);
62
    }
63
64
    private function getDepartureDate($legId)
65
    {
66
        foreach ($this->dataCache['Legs'] as $leg) {
67
            if ($leg['Id'] == $legId) {
68
                return $this->formatDate($leg['Departure']);
69
            }
70
        }
71
    }
72
73
    private function getArrivalDate($legId)
74
    {
75
        foreach ($this->dataCache['Legs'] as $leg) {
76
            if ($leg['Id'] == $legId) {
77
                return $this->formatDate($leg['Arrival']);
78
            }
79
        }
80
    }
81
82
    /**
83
     * @param $placeId
84
     * @return string
85
     */
86
    private function getPlaceNameById($placeId)
87
    {
88
        foreach ($this->dataCache['Places'] as $place) {
89
            if ($place['Id'] == $placeId) {
90
                return $place['Name'];
91
            }
92
        }
93
    }
94
95
    /**
96
     * @param $legId
97
     * @return array
98
     */
99
    private function getCarrier($legId)
100
    {
101
        foreach ($this->dataCache['Legs'] as $leg) {
102
            if ($leg['Id'] == $legId) {
103
                foreach ($this->dataCache['Carriers'] as $carrier) {
104
                    if ($carrier['Id'] == $leg['Carriers'][0]) {
105
                        return $carrier;
106
                    }
107
                }
108
            }
109
        }
110
    }
111
112
    /**
113
     * @param $priceOption
114
     * @param $currencyCode
115
     * @return string
116
     */
117
    private function getPrice($priceOption, $currencyCode = null)
118
    {
119
        if ($currencyCode == null) {
120
            return $priceOption['Price'];
121
        }
122
123
        foreach ($this->dataCache['Currencies'] as $currency) {
124
            if ($currency['Code'] == $currencyCode) {
125
                if ($currency['SymbolOnLeft'] == 'true') {
126
                    return $currency['Symbol'] . $priceOption['Price'];
127
                }
128
129
                return $priceOption['Price'] . $currency['Symbol'];
130
            }
131
        }
132
    }
133
}
134