chess_ratings_adj_linear()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
nc 4
nop 5
dl 0
loc 17
rs 9.8666
c 2
b 0
f 0
1
<?php
2
// ------------------------------------------------------------------------- //
3
//  This program is free software; you can redistribute it and/or modify     //
4
//  it under the terms of the GNU General Public License as published by     //
5
//  the Free Software Foundation; either version 2 of the License, or        //
6
//  (at your option) any later version.                                      //
7
//                                                                           //
8
//  You may not change or alter any portion of this comment or credits       //
9
//  of supporting developers from this source code or any supporting         //
10
//  source code which is considered copyrighted (c) material of the          //
11
//  original comment or credit authors.                                      //
12
//                                                                           //
13
//  This program is distributed in the hope that it will be useful,          //
14
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
15
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
16
//  GNU General Public License for more details.                             //
17
//                                                                           //
18
//  You should have received a copy of the GNU General Public License        //
19
//  along with this program; if not, write to the Free Software              //
20
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
21
//  ------------------------------------------------------------------------ //
22
23
/**
24
 * Ratings functions specific to Linear rating system.
25
 *
26
 * @package    chess
27
 * @subpackage ratings
28
 */
29
30
/**
31
 * Update the players' ratings for an individual game, using the Linear rating system.
32
 *
33
 * @param int    $white_rating White's current rating
34
 * @param int    $white_games  Number of rated games that white has played
35
 * @param int    $black_rating Black's current rating
36
 * @param int    $black_games  Number of rated games that black has played
37
 * @param string $pgn_result   Game result: '1-0' (white won), '0-1' (black won) or '1/2-1/2' (draw)
38
 * @return array  Array with two elements:
39
 *                             - $white_rating_new - white's new rating
40
 *                             - $black_rating_new - black's new rating
41
 */
42
function chess_ratings_adj_linear($white_rating, $white_games, $black_rating, $black_games, $pgn_result)
0 ignored issues
show
Unused Code introduced by
The parameter $white_games is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
function chess_ratings_adj_linear($white_rating, /** @scrutinizer ignore-unused */ $white_games, $black_rating, $black_games, $pgn_result)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $black_games is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
function chess_ratings_adj_linear($white_rating, $white_games, $black_rating, /** @scrutinizer ignore-unused */ $black_games, $pgn_result)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
{
44
    // compute score: +1 for win, 0 for draw, -1 for loss
45
    switch ($pgn_result) {
46
        case '1-0':
47
            $S = 1;
48
            break;
49
        case '1/2-1/2':
50
        default: // should not occur
51
            $S = 0;
52
            break;
53
        case '0-1':
54
            $S = -1;
55
            break;
56
    }
57
58
    return [$white_rating + $S * 10, $black_rating - $S * 10];
59
}
60
61
/**
62
 * Get the number of provisional games used in the Linear rating system.
63
 *
64
 * @return int  Number of provisional games
65
 */
66
function chess_ratings_num_provisional_games_linear()
67
{
68
    return 2;
69
}
70
71
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
72