|
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 |
|
* @return string|array<string>) |
|
52
|
|
|
* |
|
53
|
1 |
|
* @throws Exception |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getVehicleFuelType(int $count = 1): string|array |
|
56
|
|
|
{ |
|
57
|
|
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleFuelTypes, $count); |
|
58
|
|
|
} |
|
59
|
1 |
|
|
|
60
|
|
|
/** |
|
61
|
1 |
|
* @throws Exception |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getVehicleDoorCount(): int |
|
64
|
|
|
{ |
|
65
|
|
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleDoorCount); |
|
66
|
|
|
} |
|
67
|
1 |
|
|
|
68
|
|
|
/** |
|
69
|
1 |
|
* @throws Exception |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getVehicleSeatCount(): int |
|
72
|
|
|
{ |
|
73
|
|
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleSeatCount); |
|
74
|
|
|
} |
|
75
|
1 |
|
|
|
76
|
|
|
/** |
|
77
|
1 |
|
* @return array<string> |
|
78
|
|
|
* |
|
79
|
|
|
* @throws Exception |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getVehicleProperties(int $count = 1): array |
|
82
|
|
|
{ |
|
83
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleProperties, $count); |
|
84
|
|
|
} |
|
85
|
1 |
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @throws Exception |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getVehicleGearBoxType(): string |
|
90
|
|
|
{ |
|
91
|
1 |
|
return FakeCarHelper::getArrayData($this->vehicleData::$vehicleGearBoxType); |
|
92
|
|
|
} |
|
93
|
1 |
|
|
|
94
|
1 |
|
/** |
|
95
|
|
|
* @throws Exception |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getVehicleEnginePower(): string |
|
98
|
|
|
{ |
|
99
|
|
|
['range' => $range, 'unit' => $unit] = $this->vehicleData::$vehicleEnginePower; |
|
100
|
1 |
|
|
|
101
|
|
|
return FakeCarHelper::getRangeWithUnit($range, $unit); |
|
102
|
1 |
|
} |
|
103
|
1 |
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @throws Exception |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getVehicleEnginePowerValue(): int|string |
|
108
|
|
|
{ |
|
109
|
|
|
['range' => $range] = $this->vehicleData::$vehicleEnginePower; |
|
110
|
|
|
|
|
111
|
|
|
return FakeCarHelper::getRange($range); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @throws Exception |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getVehicleEngineTorque(): string |
|
118
|
|
|
{ |
|
119
|
|
|
['range' => $range, 'unit' => $unit] = $this->vehicleData::$vehicleEngineTorque; |
|
120
|
|
|
|
|
121
|
|
|
return FakeCarHelper::getRangeWithUnit($range, $unit); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @throws Exception |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getVehicleEngineTorqueValue(): int|string |
|
128
|
|
|
{ |
|
129
|
|
|
['range' => $range] = $this->vehicleData::$vehicleEngineTorque; |
|
130
|
|
|
|
|
131
|
|
|
return FakeCarHelper::getRange($range); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|