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