Completed
Push — master ( d95c29...bf4997 )
by Jean
02:42
created

MappingProcessor::getPrice()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 5
nop 2
crap 30
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
    /** @inheritdoc */
16
    public function process(array $data) {
17
        $this->dataCache = $data;
18
19
        $mappedDocuments = [];
20
        foreach ($data['Itineraries'] as $itinerary) {
21
            $outboundCarrier = $this->getCarrier($itinerary['OutboundLegId']);
22
            $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...
23
24
            foreach ($itinerary['PricingOptions'] as $priceOption) {
25
                $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...
26
                $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...
27
                $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...
28
                $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...
29
                $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...
30
                $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...
31
                $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...
32
                $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...
33
                $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...
34
                $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...
35
                $mappedData['DestinationPlace'] = $this->getPlaceNameById($data['Query']['DestinationPlace']);
36
                $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...
37
                $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...
38
                $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...
39
                $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...
40
                $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...
41
                $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...
42
                $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...
43
                $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...
44
                $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...
45
46
                $mappedDocuments[] = $mappedData;
47
            }
48
        }
49
50
        $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...
51
52
        return $mappedDocuments;
53
    }
54
55
    private function formatDate($date) {
56
        return (new \DateTime($date))
57
            ->format(\DATE_ATOM);
58
    }
59
60
    private function getDepartureDate($legId) {
61
        foreach ($this->dataCache['Legs'] as $leg) {
62
            if ($leg['Id'] == $legId) {
63
                return $this->formatDate($leg['Departure']);
64
            }
65
        }
66
    }
67
68
    private function getArrivalDate($legId) {
69
        foreach ($this->dataCache['Legs'] as $leg) {
70
            if ($leg['Id'] == $legId) {
71
                return $this->formatDate($leg['Arrival']);
72
            }
73
        }
74
    }
75
76
    /**
77
     * @param $placeId
78
     * @return string
79
     */
80
    private function getPlaceNameById($placeId) {
81
        foreach ($this->dataCache['Places'] as $place) {
82
            if ($place['Id'] == $placeId) {
83
                return $place['Name'];
84
            }
85
        }
86
    }
87
88
    /**
89
     * @param $legId
90
     * @return array
91
     */
92
    private function getCarrier($legId) {
93
        foreach ($this->dataCache['Legs'] as $leg) {
94
            if ($leg['Id'] == $legId) {
95
                foreach ($this->dataCache['Carriers'] as $carrier) {
96
                    if ($carrier['Id'] == $leg['Carriers'][0]) {
97
                        return $carrier;
98
                    }
99
                }
100
            }
101
        }
102
    }
103
104
    /**
105
     * @param $priceOption
106
     * @param $currencyCode
107
     * @return string
108
     */
109
    private function getPrice($priceOption, $currencyCode = null) {
110
        if ($currencyCode == null) {
111
            return $priceOption['Price'];
112
        }
113
114
        foreach ($this->dataCache['Currencies'] as $currency) {
115
            if ($currency['Code'] == $currencyCode) {
116
                if ($currency['SymbolOnLeft']) {
117
                    return $currency['Symbol'] . $priceOption['Price'];
118
                }
119
120
                return $priceOption['Price'] . $currency['Symbol'];
121
            }
122
        }
123
    }
124
}
125