Completed
Push — master ( 7c5112...0705e2 )
by
unknown
15s
created

RaceDataProvider::onWayPoint()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 55
Code Lines 39

Duplication

Lines 32
Ratio 58.18 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 32
loc 55
ccs 0
cts 40
cp 0
rs 9.078
c 0
b 0
f 0
cc 4
eloc 39
nc 4
nop 1
crap 20

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
3
namespace eXpansion\Framework\GameTrackmania\DataProviders;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\Storage\MapStorage;
7
8
9
/**
10
 * Class RaceDataProvider
11
 *
12
 * @package eXpansion\Framework\GameTrackmania\DataProviders;
13
 * @author  oliver de Cramer <[email protected]>
14
 */
15
class RaceDataProvider extends AbstractDataProvider
16
{
17
    /** @var MapStorage */
18
    protected $mapStorage;
19
20
    /**
21
     * RaceDataProvider constructor.
22
     *
23
     * @param MapStorage $mapStorage
24
     */
25
    public function __construct(MapStorage $mapStorage)
26
    {
27
        $this->mapStorage = $mapStorage;
28
    }
29
30
31
    public function onWayPoint($params)
32
    {
33 View Code Duplication
        if ($params['isendrace']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $this->dispatch(
35
                'onPlayerEndRace',
36
                [
37
                    $params['login'],
38
                    $params['time'],
39
                    $params['racetime'],
40
                    $params['stuntsscore'],
41
                    $params['checkpointinrace'],
42
                    $params['curracecheckpoints'],
43
                    $params['blockid'],
44
                    $params['speed'],
45
                    $params['distance'],
46
                ]
47
            );
48
        }
49
50 View Code Duplication
        if ($params['isendlap'] && $this->mapStorage->getCurrentMap()->lapRace) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $this->dispatch(
52
                'onPlayerEndLap',
53
                [
54
                    $params['login'],
55
                    $params['time'],
56
                    $params['laptime'],
57
                    $params['stuntsscore'],
58
                    $params['checkpointinlap'],
59
                    $params['curlapcheckpoints'],
60
                    $params['blockid'],
61
                    $params['speed'],
62
                    $params['distance'],
63
                ]
64
            );
65
        }
66
67
        $this->dispatch(
68
            'onPlayerWayPoint',
69
            [
70
                $params['login'],
71
                $params['time'],
72
                $params['racetime'],
73
                $params['laptime'],
74
                $params['stuntsscore'],
75
                $params['checkpointinrace'],
76
                $params['checkpointinlap'],
77
                $params['curracecheckpoints'],
78
                $params['curlapcheckpoints'],
79
                $params['blockid'],
80
                $params['speed'],
81
                $params['distance'],
82
            ]
83
        );
84
85
    }
86
87
}
88