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