Completed
Branch master (082d55)
by Rudie
02:26
created

Vehicle::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 3
eloc 11
nc 3
nop 2
1
<?php
2
3
namespace rdx\fuelly;
4
5
use rdx\fuelly\Client;
6
use rdx\fuelly\FuelUp;
7
8
class Vehicle {
9
10
	public $client; // rdx\fuelly\Client
11
12
	public $id = 0;
13
	public $url = '';
14
	public $name = '';
15
	public $image = '';
16
	public $trend = array();
17
18
	/**
19
	 *
20
	 */
21
	public function __construct( Client $client, array $vehicle ) {
22
		$this->client = $client;
23
24
		$this->id = $vehicle['id'];
25
		$this->url = $vehicle['url'];
26
		$this->name = $vehicle['name'];
27
		$this->image = $vehicle['image'];
28
29
		if ( isset($vehicle['trend']) ) {
30
			$input = $client->createTrendInputConversion();
31
32
			foreach ( $vehicle['trend'] as $fuelup) {
33
				$this->trend[] = FuelUp::createFromTrend($this, $fuelup, $input);
34
			}
35
36
			// Sort by date DESC
37
			usort($this->trend, array(FuelUp::class, 'dateCmp'));
38
		}
39
	}
40
41
}
42