Passed
Push — v3 ( 962004...bdfc5f )
by Austin
06:52
created

Bf4::processDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 57
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 57
ccs 34
cts 34
cp 1
rs 9.392
cc 2
nc 2
nop 1
crap 2

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
 * This file is part of GameQ.
4
 *
5
 * GameQ is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * GameQ is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace GameQ\Protocols;
20
21
use GameQ\Buffer;
22
use GameQ\Result;
23
24
/**
25
 * Battlefield 4 Protocol class
26
 *
27
 * Good place for doc status and info is http://battlelog.battlefield.com/bf4/forum/view/2955064768683911198/
28
 *
29
 * @package GameQ\Protocols
30
 * @author  Austin Bischoff <[email protected]>
31
 */
32
class Bf4 extends Bf3
33
{
34
35
    /**
36
     * String name of this protocol class
37
     *
38
     * @type string
39
     */
40
    protected $name = 'bf4';
41
42
    /**
43
     * Longer string name of this protocol class
44
     *
45
     * @type string
46
     */
47
    protected $name_long = "Battlefield 4";
48
49
    /**
50
     * Handle processing details since they are different than BF3
51
     *
52
     * @param \GameQ\Buffer $buffer
53
     *
54
     * @return array
55
     */
56 4
    protected function processDetails(Buffer $buffer)
57
    {
58
59
        // Decode into items
60 4
        $items = $this->decode($buffer);
61
62
        // Set the result to a new result instance
63 4
        $result = new Result();
64
65
        // Server is always dedicated
66 4
        $result->add('dedicated', 1);
67
68
        // These are the same no matter what mode the server is in
69 4
        $result->add('hostname', $items[1]);
70 4
        $result->add('num_players', (int) $items[2]);
71 4
        $result->add('max_players', (int) $items[3]);
72 4
        $result->add('gametype', $items[4]);
73 4
        $result->add('map', $items[5]);
74 4
        $result->add('roundsplayed', (int) $items[6]);
75 4
        $result->add('roundstotal', (int) $items[7]);
76 4
        $result->add('num_teams', (int) $items[8]);
77
78
        // Set the current index
79 4
        $index_current = 9;
80
81
        // Pull the team count
82 4
        $teamCount = $result->get('num_teams');
83
84
        // Loop for the number of teams found, increment along the way
85 4
        for ($id = 1; $id <= $teamCount; $id++, $index_current++) {
86
            // Shows the tickets
87 4
            $result->addTeam('tickets', $items[$index_current]);
88
            // We add an id so we know which team this is
89 4
            $result->addTeam('id', $id);
90
        }
91
92
        // Get and set the rest of the data points.
93 4
        $result->add('targetscore', (int) $items[$index_current]);
94 4
        $result->add('online', 1); // Forced true, it seems $words[$index_current + 1] is always empty
95 4
        $result->add('ranked', (int) $items[$index_current + 2]);
96 4
        $result->add('punkbuster', (int) $items[$index_current + 3]);
97 4
        $result->add('password', (int) $items[$index_current + 4]);
98 4
        $result->add('uptime', (int) $items[$index_current + 5]);
99 4
        $result->add('roundtime', (int) $items[$index_current + 6]);
100 4
        $result->add('ip_port', $items[$index_current + 7]);
101 4
        $result->add('punkbuster_version', $items[$index_current + 8]);
102 4
        $result->add('join_queue', (int) $items[$index_current + 9]);
103 4
        $result->add('region', $items[$index_current + 10]);
104 4
        $result->add('pingsite', $items[$index_current + 11]);
105 4
        $result->add('country', $items[$index_current + 12]);
106
        //$result->add('quickmatch', (int) $items[$index_current + 13]); Supposed to be here according to R42 but is not
107 4
        $result->add('blaze_player_count', (int) $items[$index_current + 13]);
108 4
        $result->add('blaze_game_state', (int) $items[$index_current + 14]);
109
110 4
        unset($items, $index_current, $teamCount, $buffer);
111
112 4
        return $result->fetch();
113
    }
114
}
115