carNames.php ➔ carName()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 88
Code Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 85
nc 2
nop 1
dl 0
loc 88
rs 8.6012
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
function carName($class)
3
{
4
    $car['C_Offroad_01_F'] = 'Offroad';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$car was never initialized. Although not strictly required by PHP, it is generally a good practice to add $car = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
5
    $car['C_SUV_01_F'] = 'SUV';
6
    $car['C_Offroad_01_repair_F'] = 'Offroad (Repair)';
7
    $car['O_Heli_Light_02_unarmed_F'] = 'PO-30 Orca';
8
    $car['C_Heli_Light_01_civil_F'] = 'M-900';
9
    $car['B_Quadbike_01_F'] = 'Quadbike';
10
    $car['C_Hatchback_01_F'] = 'Hatchback';
11
    $car['C_Hatchback_01_sport_F'] = 'Hatchback Sport';
12
    $car['C_Van_01_transport_F'] = 'Truck';
13
    $car['C_Van_01_box_F'] = 'Truck Boxer';
14
    $car['C_Van_01_fuel_F'] = 'Fuel Truck';
15
    $car['I_Truck_02_transport_F'] = 'Zamak Transport';
16
    $car['O_Truck_03_transport_F'] = 'Tempest Transport';
17
    $car['B_Truck_01_transport_F'] = 'HEMTT Transport';
18
    $car['O_Truck_02_covered_F'] = 'Zamak Transport (Covered)';
19
    $car['O_Truck_03_covered_F'] = 'Tempest Transport (Covered)';
20
    $car['B_Truck_01_covered_F'] = 'HEMTT Transport (Covered)';
21
    $car['B_Truck_01_box_F'] = 'HEMTT Box';
22
    $car['O_Truck_03_ammo_F'] = 'Tempest Ammo';
23
    $car['I_Truck_02_fuel_F'] = 'Zamak Fuel';
24
    $car['O_Truck_03_fuel_F'] = 'Tempest Fuel';
25
    $car['B_Truck_01_fuel_F'] = 'HEMTT Fuel';
26
    $car['O_Truck_03_device_F'] = 'Tempest (Device)';
27
    $car['I_Heli_Transport_02_F'] = 'CH-49 Mohawk';
28
    $car['O_Heli_Transport_04_F'] = 'Mi-290 Taru';
29
    $car['O_Heli_Transport_04_covered_F'] = 'Mi-290 Taru (Transport)';
30
    $car['O_Heli_Transport_04_box_F'] = 'Mi-290 Taru (Cargo)';
31
    $car['O_Heli_Transport_04_fuel_F'] = 'Mi-290 Taru (Fuel)';
32
    $car['C_Rubberboat'] = 'Rescue Boat';
33
    $car['C_Boat_Civil_01_F'] = 'Motorboat';
34
    $car['B_SDV_01_F'] = 'SDV (Submarine)';
35
    $car['B_G_Offroad_01_F'] = 'Offroad';
36
    $car['B_Heli_Light_01_F'] = 'MH-9 Hummingbird';
37
    $car['O_MRAP_02_F'] = 'Ifrit';
38
    $car['B_G_Offroad_01_armed_F'] = 'Offroad (Armed)';
39
    $car['O_Heli_Transport_04_bench_F'] = 'Mi-290 Taru (Bench)';
40
    $car['O_Heli_Attack_02_black_F'] = 'Mi-48 Kajman (Black)';
41
    $car['B_MRAP_01_F'] = 'Hunter';
42
    $car['I_MRAP_03_F'] = 'Strider';
43
    $car['B_MRAP_01_hmg_F'] = 'Hunter HMG';
44
    $car['I_Heli_light_03_unarmed_F'] = 'WY-55 Hellcat (Green)';
45
    $car['I_Heli_light_03_F'] = 'WY-55 Hellcat';
46
    $car['B_Heli_Transport_01_F'] = 'UH-80 Ghost Hawk';
47
    $car['B_Heli_Transport_03_F'] = 'CH-67 Huron';
48
    $car['B_Heli_Transport_03_unarmed_F'] = 'CH-67 Huron (Black)';
49
    $car['B_Boat_Transport_01_F'] = 'Assault Boat';
50
    $car['C_Boat_Civil_01_police_F'] = 'Motorboat (Police)';
51
    $car['B_Boat_Armed_01_minigun_F'] = 'Speedboat Minigun';
52
    $car['O_Truck_02_Fuel_F'] = 'Zamak Fuel';
53
    $car['O_Truck_03_fuel_F'] = 'Tempest Fuel';
54
    $car['B_Truck_01_ammo_F'] = 'HEMTT Ammo';
55
    $car['O_Truck_02_box_F'] = 'Zamak Repair';
56
    $car['O_Heli_Transport_04_medevac_F'] = 'Mi-290 Taru (Medical)';
57
    $car['O_Boat_Armed_01_hmg_F'] = 'Speedboat HMG';
58
    $car['I_MRAP_03_hmg_F'] = 'Strider HMG';
59
    $car['O_MRAP_02_hmg_F'] = 'Ifrit HMG';
60
    $car['O_Truck_03_Ammo_F'] = 'Tempest Ammo';
61
    $car['Box_IND_AmmoVeh_F'] = 'Box_IND_AmmoVeh_F';
62
    $car['B_Slingload_01_Cargo_F'] = 'B_Slingload_01_Cargo_F';
63
    $car['C_supplyCrate_F'] = 'C_supplyCrate_F';
64
    $car['B_Heli_Attack_01_F'] = 'AH-99 Blackfoot';
65
    $car['B_Truck_01_medical_F'] = 'Hemmt Medic';
66
    $car['O_Truck_03_medical_F'] = 'Tempest Medic';
67
    $car['I_APC_Wheeled_03_cannon_F'] = 'Marid';
68
    $car['O_APC_Wheeled_02_rcws_F'] = 'Marid Cop';
69
    $car['I_Truck_02_covered_F'] = 'Zamak Abgedeckt';
70
    $car['B_Truck_01_mover_F'] = 'Hemmt Mover';
71
    $car['O_MRAP_02_gmg_F'] = 'Marid';
72
    $car['I_APC_Wheeled_03_cannon_F'] = 'iFRIT GMG';
73
    $car['C_Kart_01_Vrana_F'] = 'Kart Vrana';
74
    $car['C_Kart_01_F'] = 'Kart';
75
    $car['C_Kart_01_Fuel_F'] = 'Kart Fuel';
76
    $car['C_Kart_01_Blue_F'] = 'Kart Blue';
77
    $car['C_Kart_01_Green_F'] = 'Kart Green';
78
    $car['C_Kart_01_Orange_F'] = 'Kart Orange';
79
    $car['C_Kart_01_White_F'] = 'Kart White';
80
    $car['C_Kart_01_Yellow_F'] = 'Kart Yellow';
81
    $car['C_Kart_01_Black_F'] = 'Kart Black';
82
    $car['C_Kart_01_Red_F'] = 'Kart Red';
83
    $car['O_Truck_02_Ammo_F'] = 'Zamak Ammo';
84
    if (isset($car[$class])) {
85
        return $car[$class];
86
    } else {
87
        return $class;
88
    }
89
    }