Passed
Push — main ( ebe7df...9489b3 )
by Peter
02:53
created

FakeCarDataProvider::getVehicleEnginePower()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Faker\Provider\Fa...icleData::vehicleTypes) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Faker\Provider\Fa...Data::vehicleDoorCount) also could return the type array|string which is incompatible with the return type mandated by Faker\Provider\FakeCarDa...::getVehicleDoorCount() of integer.
Loading history...
62
    }
63
64
    /**
65
     * @throws Exception
66
     */
67 1
    public function getVehicleSeatCount(): int
68
    {
69 1
        return FakeCarHelper::getArrayData($this->vehicleData::$vehicleSeatCount);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Faker\Provider\Fa...Data::vehicleSeatCount) also could return the type array|string which is incompatible with the return type mandated by Faker\Provider\FakeCarDa...::getVehicleSeatCount() of integer.
Loading history...
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Faker\Provider\Fa...icleProperties, $count) could return the type string which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
78
    }
79
80
    /**
81
     * @throws Exception
82
     */
83 1
    public function getVehicleGearBoxType(): string
84
    {
85 1
        return FakeCarHelper::getArrayData($this->vehicleData::$vehicleGearBoxType);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Faker\Provider\Fa...ta::vehicleGearBoxType) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
86
    }
87
88
    /**
89
     * @throws Exception
90
     */
91 1
    public function getVehicleEnginePower(): string
92
    {
93 1
        ['range' => $range, 'unit' => $unit] = $this->vehicleData::$vehicleEnginePower;
94 1
        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