|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Faker\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
|
|
8
|
|
|
class FakeCarDataProvider implements FakeCarDataProviderInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected $vehicleData; |
|
11
|
|
|
|
|
12
|
19 |
|
public function __construct($vehicleData = null) |
|
13
|
|
|
{ |
|
14
|
19 |
|
$this->vehicleData = $vehicleData ?: FakeCarData::class; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @throws Exception |
|
19
|
|
|
*/ |
|
20
|
5 |
|
public function getVehicleBrand(): string |
|
21
|
|
|
{ |
|
22
|
5 |
|
return (string) FakeCarHelper::getRandomElementFromArray(array_keys($this->vehicleData::$brandsWithModels)); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @throws Exception |
|
27
|
|
|
*/ |
|
28
|
4 |
|
public function getVehicleModel(string $brand = null): string |
|
29
|
|
|
{ |
|
30
|
4 |
|
$brandsWithModels = $this->vehicleData::$brandsWithModels; |
|
31
|
|
|
|
|
32
|
4 |
|
return (string) FakeCarHelper::getRandomElementFromArray($brandsWithModels[$brand ?: $this->getVehicleBrand()]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
4 |
|
public function getBrandsWithModels(): array |
|
36
|
|
|
{ |
|
37
|
4 |
|
return $this->vehicleData::$brandsWithModels; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @throws Exception |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function getVehicleType(): string |
|
44
|
|
|
{ |
|
45
|
2 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleTypes); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @throws Exception |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getVehicleFuelType(int $count = 1): string|array |
|
52
|
|
|
{ |
|
53
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleFuelTypes, $count); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws Exception |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getVehicleDoorCount(): int |
|
60
|
|
|
{ |
|
61
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleDoorCount); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @throws Exception |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function getVehicleSeatCount(): int |
|
68
|
|
|
{ |
|
69
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleSeatCount); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @throws Exception |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function getVehicleProperties(int $count = 0): array |
|
76
|
|
|
{ |
|
77
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleProperties, $count); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws Exception |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getVehicleGearBoxType(): string |
|
84
|
|
|
{ |
|
85
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleGearBoxType); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @throws Exception |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getVehicleEnginePower(): string |
|
92
|
|
|
{ |
|
93
|
|
|
['range' => $range, 'unit' => $unit] = $this->vehicleData::$vehicleEnginePower; |
|
94
|
|
|
return FakeCarHelper::getRangeWithUnit($range, $unit); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @throws Exception |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getVehicleEngineTorque(): string |
|
101
|
|
|
{ |
|
102
|
1 |
|
['range' => $range, 'unit' => $unit] = $this->vehicleData::$vehicleEngineTorque; |
|
103
|
1 |
|
return FakeCarHelper::getRangeWithUnit($range, $unit); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|