Completed
Push — master ( 871d94...af939e )
by Michael
03:14
created

coi.php ➔ GENEALOGY()   F

Complexity

Conditions 18
Paths 2324

Size

Total Lines 83
Code Lines 61

Duplication

Lines 18
Ratio 21.69 %

Importance

Changes 0
Metric Value
cc 18
eloc 61
nc 2324
nop 0
dl 18
loc 83
rs 2.0538
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 90 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
ini_set('memory_limit', '32M');
3
4
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
$moduleDirName = basename(__DIR__);
6
xoops_loadLanguage('main', $moduleDirName);
7
require_once(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php');
8
9
$xoopsOption['template_main'] = 'pedigree_coi.tpl';
10
include XOOPS_ROOT_PATH . '/header.php';
11
12
//get module configuration
13
$moduleHandler = xoops_getHandler('module');
14
$module        = $moduleHandler->getByDirname('pedigree');
15
$configHandler = xoops_getHandler('config');
16
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
17
18
global $xoopsTpl, $xoopsDB, $moduleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
19
20
//start kinship.php code -- help !!
21
/* ************************************************************************************* */
22
/*
23
     This program calculates the coefficient of inbreeding (IC, or COI, or F)
24
     for the offspring of a couple of animals, given by their IDs (s=sire_ID&d=dam_ID),
25
     or for a given animal given by its ID (a=animal_ID).
26
27
     By default, all known ascendants are used.
28
     However, maximum count of distinct ascendants is limited to $nb_maxi (default=600)
29
              [higher values for $nb_maxi could lead to calculations ending in timeout],
30
              or depth of tree can be limited to $nb_gen generations (default = 8).
31
*/
32
/* ************************************************************************************* */
33
34
if (!isset($verbose)) {
35
    $verbose = 0;
36
} // don't display different steps of ICs calculation
37
if (!isset($detail)) {
38
    $detail = 1;
39
} // don't display detail results [faster]
40
if (!isset($nb_maxi)) {
41
    $nb_maxi = 600;
42
} // maximum count of distinct ascendants
43
if (!isset($nb_gen)) {
44
    $nb_gen = 8;
45
} // maximum count of generations of ascendants
46
if (!isset($pedigree)) {
47
    $pedigree = 0;
48
} // dont't display sketch pedigree [faster]
49
if (!isset($max_dist)) { // maximum length of implex loops
50
    if ($nb_gen > 9) {
51
        $max_dist = 14;
52
    } else {
53
        if ($nb_gen == 9) {
54
            $max_dist = 17;
55
        } else {
56
            if ($nb_gen == 8) {
57
                $max_dist = 18;
58
            } else {
59
                $max_dist = 99;
60
            }
61
        }
62
    }
63
}
64
65
$empty = array(); // an empty array
66
$sql1  = 'select ID, father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' where ID ';
67
68
// input data arrays:
69
$IDs     = $empty;
70
$fathers = $empty;
71
$mothers = $empty;
72
73
// working arrays:
74
$inds    = $empty;
75
$marked  = $empty;
76
$ICknown = $empty;
77
$deltaf  = $empty;
78
$pater   = $empty;
79
$mater   = $empty;
80
$chrono  = $empty;
81
82
// Coefficients of Inbreeding array (result):
83
$COIs = $empty;
84
85
/* ******************************  FUNCTIONS  ********************************* */
86
87
/**
88
 * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be null|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
89
 */
90
function chrono_sort()
91
{
92
    global $IDs, $inds, $fathers, $mothers, $chrono, $nl, $detail;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
93
    $impr  = 0;
94
    $modif = 1;
95
    $nloop = 0;
96
    $nba   = count($IDs);
97
    // print_r ($IDs) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
    // echo "<b>231 : $IDs[231] $fathers[231] $mothers[231] $chrono[231] $inds[231] </b><br />\n" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
99
    foreach ($IDs as $i => $v) {
100
        $chrono[$i] = 1;
101
    } // initialize all chronological ranks to 1
102
    $chrono[0] = 0; // except animal #0 (at 0 rank).
103
    while ($modif && $nloop < 40) {
104
        $modif = 0;
105
        ++$nloop;
106
        for ($i = 1; $i < $nba; ++$i) {
107
            $s = $fathers[$i];
108
            if ($s) {
109
                $s = $inds[$s];
110
            }
111
            $d = $mothers[$i];
112
            if ($d) {
113
                $d = $inds[$d];
114
            }
115 View Code Duplication
            if ($s && $chrono[$s] <= $chrono[$i]) {
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...
116
                $chrono[$s] = $chrono[$i] + 1;
117
                $modif      = 1;
118
            }
119 View Code Duplication
            if ($d && $chrono[$d] <= $chrono[$i]) {
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...
120
                $chrono[$d] = $chrono[$i] + 1;
121
                $modif      = 1;
122
            }
123
        }
124
    }
125
    if ($nloop == 40) {
126
        die('Endless loop detected. Stopped.');
0 ignored issues
show
Coding Style Compatibility introduced by
The function chrono_sort() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
127
    }
128
    array_multisort($chrono, $IDs, $fathers, $mothers);
129
    $depth = $chrono[$nba - 1];
0 ignored issues
show
Unused Code introduced by
$depth is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
130
    //commentes out by JC
131
    //if ($detail) echo "<br />Chronological ranking done : Pedigree stretched over <b>$depth</b> generations.<br />$nl" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
132
    if ($impr) {
133
        echo "</center><pre>$nl $nl";
134
        foreach ($chrono as $i => $val) {
135
            echo "<b>$i</b> : $val $IDs[$i] $fathers[$i] $mothers[$i] $nl";
136
        }
137
        echo "</pre>$nl";
138
        die('</html>');
0 ignored issues
show
Coding Style Compatibility introduced by
The function chrono_sort() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
139
    }
140
    $inds = array_flip($IDs);
141
142
    return 0;
143
}
144
145
/**
146
 * @param $s
147
 *
148
 * @return array
149
 */
150
function fetch_record($s)
0 ignored issues
show
Coding Style introduced by
fetch_record uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
151
{
152
    global $database;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
153
    $r = mysqli_db_query($database, $s);
154
    $n = 0;
155
    if ($r) {
156
        $n = mysqli_num_rows($r);
157
    }
158
    if ($n == 0) {
159
        $record = array('0');
160
    } else {
161
        $record = $GLOBALS['xoopsDB']->fetchBoth($r);
162
    }
163
164
    return $record;
165
}
166
167
/**
168
 * @param $ind
169
 * @param $gen
170
 *
171
 * @return int
172
 */
173
function count_all($ind, $gen)
174
{
175
    global $inds, $nb_gen, $nb_all, $fathers, $mothers;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
176
    if ($ind) {
177
        ++$nb_all;
178
    }
179
    $s = $fathers[$ind];
180
    $d = $mothers[$ind];
181
    if ($s && $gen < $nb_gen) {
182
        count_all($s, $gen + 1);
183
    }
184
    if ($d && $gen < $nb_gen) {
185
        count_all($d, $gen + 1);
186
    }
187
188
    return 0;
189
}
190
191
/**
192
 * @param $ch
193
 * @param $niv
194
 *
195
 * @return int
196
 */
197
function add_multi($ch, $niv)
198
{
199
    global $implx, $couls, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
200
    reset($implx);
201
    $first = 1;
202
    foreach ($implx as $im => $impl) {
203
        if ($impl[0] == $ch || $impl[1] == $ch) {
204
            if ($niv > 1 && $first) {
205
                echo "<br />$nl";
206
            } else {
207
                echo '&nbsp;&nbsp;&nbsp;';
208
            }
209
            $i     = $im + 1;
210
            $j     = min($im, 6);
211
            $c     = $couls[$j];
212
            $first = 0;
213
            echo '<font color=' . $c . ' size="+2"><b>*' . $i . '*</b></font>';
214
        }
215
    }
216
217
    return 0;
218
}
219
220
/**
221
 * @param $ind
222
 * @param $gen
223
 * @param $class
224
 *
225
 * @return int
226
 */
227
function output_animal($ind, $gen, $class)
228
{
229
    global $depth, $IDs, $fathers, $mothers, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
230
    if ($gen > $depth) {
231
        return 0;
232
    }
233
    $cell_content = '&Oslash;';
234
    if ($ind || $gen == 0) {
235
        $ID           = $IDs[$ind];
236
        $ani          = set_name($ID);
237
        $name         = $ani[1];
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
238
        $name         = $ID;
239
        $cell_content = showParent($name) . $nl;
240
    }
241
    $rowspan = 1 << ($depth - $gen);
242
    echo '<td rowspan=' . $rowspan . ' align="center" class="' . $class . '">' . $cell_content . "</td>$nl";
243
    if ($gen < $depth) {
244
        $sire = 0;
245
        if ($ind || $gen == 0) {
246
            $sire = $fathers[$ind];
247
        }
248
        output_animal($sire, $gen + 1, '0');
249
        $dam = 0;
250
        if ($ind || $gen == 0) {
251
            $dam = $mothers[$ind];
252
        }
253
        output_animal($dam, $gen + 1, '1');
254
    } else {
255
        echo "</tr><tr>$nl";
256
    }
257
258
    return 0;
259
}
260
261
/**
262
 * @return int
263
 */
264
function SKETCH_PEDIGREE()
265
{
266
    global $nl, $detail, $depth, $IDs;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
267
    // print_r ($IDs) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
268
    echo $nl . '<br />' . $nl . '<table border="3" cellpadding="4" width="85%"" cellpadding="0" cellspacing="0">' . $nl . '<tr><th colspan="10" align="center">SKETCH &nbsp; PEDIGREE &nbsp; OF COMMON PROGENY</th></tr>' . $nl . '<tr align="center" valign="middle"><th>Progeny</th><th>' . _('Sire / Dam') . '</th>';
269
    if ($depth >= 2) {
270
        echo '<th>' . _('Grandparents') . '</th>' . $nl;
271
    }
272
    if ($depth >= 3) {
273
        echo '<th>' . _('Great-Grandparents') . '</th>' . $nl;
274
    }
275
    if ($depth >= 4) {
276
        echo '<th>3xGr. P.</th>' . $nl;
277
    }
278
    if ($depth >= 5) {
279
        echo '<th>4xGr. P.</th>' . $nl;
280
    }
281
    if ($depth >= 6) {
282
        echo '<th>5xGr. P.</th>' . $nl;
283
    }
284
    if ($depth >= 7) {
285
        echo '<th>6xGr. P.</th>' . $nl;
286
    }
287
    echo '</tr><tr>';
288
    output_animal(0, 0, '0'); /* output the sketch pedigree */
289
    echo $nl . '</tr></table>' . $nl . '<p />' . $nl;
290
291
    return 0;
292
}
293
294
/**
295
 * @return int
296
 */
297
function GENEALOGY()
0 ignored issues
show
Coding Style introduced by
GENEALOGY uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
298
{
299
    global $IDs, $fathers, $mothers, $inds, $nb_gen, $nb_maxi, $nbani, $nl, $sql1;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
300
    $impr       = 0;
301
    $fathers[0] = $IDs[1];
302
    $mothers[0] = $IDs[2];
303
    $fathers[1] = 0;
304
    $mothers[1] = 0;
305
    $fathers[2] = 0;
306
    $mothers[2] = 0;
307
    $last       = 2;
308
    if ($impr) {
309
        echo "<!-- genealogy 'de cujus' (gener. 0) : $IDs[0] = $IDs[1] x $IDs[2] -->$nl";
310
    }
311
    $generation = array($IDs[1], $IDs[2]); // starting with first generation (sire and dam)
312
    $nbtot      = 0; // count of total known ascendants within $nb_gen generations
313
    for ($nloop = 1, $tot = 2; $last <= $nb_maxi && $nloop <= $nb_gen; ++$nloop) {
314
        $nbtot += $tot; // count of total known ascendants within $nb_gen generations
315
        $nbani      = $last; // count of    distinct ascendants within $nb_gen generations
316
        $list       = implode(',', array_unique($generation));
317
        $generation = array();
318
        $tot        = 0;
319
        if ($impr) {
320
            echo "    [$list]$nl";
321
        }
322
323
        // HERE IS FETCHED EACH TRIPLET [ID, sire_ID, dam_ID] :
324
        $r = $GLOBALS['xoopsDB']->query("$sql1 IN ($list)");
325
        while (false !== ($rec = $GLOBALS['xoopsDB']->fetchBoth($r))) {
326
            $a = $rec[0] + 0;
327
            $s = $rec[1] + 0;
328
            $d = $rec[2] + 0;
329
            if (!$a) {
330
                echo "ERROR : $a = $s x $d for list = '$list'<br />\n";
331
            }
332
            if ($s) {
333
                ++$tot;
334
            }
335
            if ($d) {
336
                ++$tot;
337
            }
338
            $j           = array_keys($IDs, $a);
339
            $j           = $j[0];
340
            $fathers[$j] = $s;
341
            $mothers[$j] = $d;
342 View Code Duplication
            if ($s && !in_array($s, $IDs)) {
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...
343
                $i           = ++$last;
344
                $IDs[$i]     = $s;
345
                $fathers[$i] = 0;
346
                $mothers[$i] = 0;
347
                if ($s) {
348
                    $generation[] = $s;
349
                }
350
            }
351 View Code Duplication
            if ($d && !in_array($d, $IDs)) {
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...
352
                $i           = ++$last;
353
                $IDs[$i]     = $d;
354
                $fathers[$i] = 0;
355
                $mothers[$i] = 0;
356
                if ($s) {
357
                    $generation[] = $d;
358
                }
359
            }
360
            if ($impr) {
361
                echo "<pre>genealogy ascendant (gener. $nloop) : $a = $s x $d  [tot = $tot]$nl</pre>";
362
            }
363
        }
364
        if (!count($generation)) {
365
            break;
366
        }
367
    }
368
369
    if ($nloop <= $nb_gen) {
370
        $nb_gen = $nloop;
371
    } // tree cut by $nb_maxi !
372
373
    reset($IDs);
374
    $inds = array_flip($IDs);
375
376
    chrono_sort();
377
378
    return $nbtot;
379
}
380
381
/**
382
 * @param $p
383
 *
384
 * @return int
385
 */
386 View Code Duplication
function dist_p($p)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
387
{
388
    global $IDs, $fathers, $mothers, $pater, $nb_gen, $detail, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
389
    // Anim #P is the sire
390
    $listall   = array($p);
391
    $listnew   = array($p);
392
    $pater     = array();
393
    $pater[$p] = 1;
394
    for ($nloop = 2; $nloop < ($nb_gen + 1); ++$nloop) {
395
        $liste = array();
396
        foreach ($listnew as $i) {
397
            $s = $fathers[$i];
398
            $d = $mothers[$i];
399
            if ($s && !$pater[$s]) {
400
                $pater[$s] = $nloop;
401
            } // least distance from $s to sire's progeny
402
            if ($d && !$pater[$d]) {
403
                $pater[$d] = $nloop;
404
            } // least distance from $d to sire's progeny
405
            if ($s) {
406
                $liste[] = $s;
407
            }
408
            if ($d) {
409
                $liste[] = $d;
410
            }
411
        }
412
        if (!count($liste)) {
413
            break;
414
        }
415
        //commented pout by jc
416
        //if (in_array ($IDs[2], $liste) && !$detail)
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
417
        //{ echo "<p>DAM is an ascendant (at $nloop generations) of SIRE.  Stopped." ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
418
        // die ("</body></html>$nl") ; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
419
        $listnew = array_diff(array_unique($liste), $listall);
420
        /* $list1 = join (' ', $listall) ; $list2 = join ('+', $listnew) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
421
             echo "<!-- P ($nloop) $list1/$list2 -->$nl" ; */
422
        $listall = array_merge($listall, $listnew);
423
    }
424
    // Here $pater array contains list of all distinct ascendants of #P (including P himself)
425
    // Values of $pater are minimum distances to #P (in generations) +1
426
    return 0;
427
}
428
429
/**
430
 * @param $m
431
 *
432
 * @return int
433
 */
434 View Code Duplication
function dist_m($m)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
435
{
436
    global $IDs, $fathers, $mothers, $mater, $nb_gen, $detail, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
437
    // Anim #M is the dam
438
    $listall   = array($m);
439
    $listnew   = array($m);
440
    $mater     = array();
441
    $mater[$m] = 1;
442
    for ($nloop = 2; $nloop <= ($nb_gen + 1); ++$nloop) {
443
        $liste = array();
444
        foreach ($listnew as $i) {
445
            $s = $fathers[$i];
446
            $d = $mothers[$i];
447
            if ($s && !$mater[$s]) {
448
                $mater[$s] = $nloop;
449
            } // least distance from $s to dam's progeny
450
            if ($d && !$mater[$d]) {
451
                $mater[$d] = $nloop;
452
            } // least distance from $d to dam's progeny
453
            // echo "I=" . $i . " MATER(I)=" . $mater[$i] . " NLOOP=" . $nloop . "<br />$nl" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
454
            if ($s) {
455
                $liste[] = $s;
456
            }
457
            if ($d) {
458
                $liste[] = $d;
459
            }
460
        }
461
        if (!count($liste)) {
462
            break;
463
        }
464
        //commented out by jc
465
        //if (in_array ($IDs[1], $liste) && !$detail)
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
466
        // { echo "<p>SIRE is an ascendant (at $nloop generations) of DAM.  Stopped." ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
467
        //  die ("</body></html>$nl") ; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
468
        $listnew = array_diff(array_unique($liste), $listall);
469
        // $list1 = join (' ', $listall) ; $list2 = join ('+', $listnew) ; echo "M ($nloop) $list1/$list2 $nl" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
470
        $listall = array_merge($listall, $listnew);
471
    }
472
    // Here $mater array contains list of all distinct ascendants of #M (including M herself)
473
    // Values of $mater are minimum distances to #M (in generations) +1
474
    return 0;
475
}
476
477
/**
478
 * @return array
479
 */
480
function calc_dist() /* Common Ascendants and their distances */
481
{
482
    global $IDs, $fathers, $mothers, $nbanims, $pater, $mater, $empty, $nb_gen, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
483
    global $dmax, $detail, $nb_gen;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
484
    $distan = array();
485
    // dist_m (2) ;   has already been called
486
    dist_p($fathers[0]);
487
    $dmax = 0;
488
    $impr = 0;
489
    $dmx  = 7;
490
    if ($detail) {
491
        $dmx += 2;
492
    }
493
    // ksort ($pater) ; print_r ($pater) ; echo "<br />$nl" ; ksort ($mater) ; print_r ($mater) ; echo "<br />$nl" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
494
    foreach ($pater as $i => $p) {
495
        if ($p) {
496
            $m = $mater[$i];
497
            if ($m) {
498
                $di = $p + $m;
499
                if ($impr) {
500
                    echo " $i : $p + $m = $di <br />$nl";
501
                }
502
                if (!$dmax) {
503
                    $dmax = $dmx + $di - ceil($di / 2.);
504
                }
505
                if ($di > ($dmax + 2)) {
506
                    continue;
507
                }
508
                $distan[$i] = $di;
509
            }
510
        }
511
    }
512
    if (!$dmax) {
513
        $dmax = 2 * $nb_gen - 2;
514
    }
515
516
    return $distan;
517
}
518
519
/**
520
 * @param $p
521
 * @param $m
522
 * @param $a
523
 * @param $ndist
524
 *
525
 * @return int
526
 */
527
function mater_side($p, $m, $a, $ndist)
528
{
529
    global $fathers, $mothers, $marked, $COIs, $deltaf, $ICknown, $verbose, $nl, $chrono, $paternal_rank, $max_dist;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
530
    if (!$m || $ndist > $max_dist) {
531
        return 0;
532
    }
533
    if ($p == $m) {
534
        /* IMPLEX FOUND (node of consanguinity) { for Anim #A */
535
        $already_known = $ICknown[$p];
536
    }
537
    if (!$already_known) {
0 ignored issues
show
Bug introduced by
The variable $already_known does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
538
        CONSANG($p);
539
    } // MAIN RECURSION:
540
    $ICp = $COIs[$p]; // we need to know the IC of Parent for Wright's formula
541
    if ($verbose && !$already_known && $ICp > 0.001 * $verbose) {
542
        echo "IC of Animal $p is $ICp$nl";
543
    }
544
    $incr = 1.0 / (1 << $ndist) * (1. + $ICp); // ******** applying WRIGHT's formula ********
545
546
    // [Note:  1 << $ndist is equal to 2 power $ndist]
547
    $COIs[$a] += $incr; // incrementing the IC of AnimC
548
    if ($a == 0) {
549
        $deltaf[$p] += $incr;
550
    }
551
    /* contribution of Anim #P to IC of Anim #0 */
552
    // if ($verbose && $a == 0 && $incr > 0.0001*$verbose)
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
553
    //    echo "Animal $p is contributing for " . substr ($deltaf[$p], 0, 10) . " to the IC of Animal $a$nl" ;}
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
554
    else {
555
        if (!$marked[$m] && $chrono[$m] < $paternal_rank) {
556
            mater_side($p, $fathers[$m], $a, $ndist + 1);
557
        }
558
        mater_side($p, $mothers[$m], $a, $ndist + 1);
559
    }
560
561
    return 0;
562
}
563
564
/**
565
 * @param $p
566
 * @param $m
567
 * @param $a
568
 * @param $pdist
569
 *
570
 * @return int
571
 */
572
function pater_side($p, $m, $a, $pdist)
573
{
574
    global $mater, $fathers, $mothers, $marked, $chrono, $paternal_rank;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
575
    if (!$p) {
576
        return 0;
577
    }
578
    $paternal_rank = $chrono[$p];
579
    $marked[$p]    = 1; /* cut paternal side */
580
    if ($mater[$p] || $a) {
581
        mater_side($p, $m, $a, $pdist);
582
    }
583
    pater_side($fathers[$p], $m, $a, $pdist + 1);
584
    pater_side($mothers[$p], $m, $a, $pdist + 1);
585
    $marked[$p] = 0; /* free paternal side */
586
587
    return 0;
588
}
589
590
/**
591
 * @param $a
592
 *
593
 * @return int
594
 */
595
function CONSANG($a)
596
{
597
    global $fathers, $mothers, $ICknown, $COIs, $nl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
598
    if (!$a || $ICknown[$a]) {
599
        return 0;
600
    }
601
    if ($a == -1) {
602
        $a = 0;
603
    } // particular case : a= -1 means Anim #0 (to bypass above test)
604
    $IC_if_deadend = 0.0; // 0.0 means taht deadends are deemed to be total outcrosses...
605
    // if IC was already stored in the database for Aminal #A, it should be used here instead of 0.0
606
    $p = $fathers[$a];
607
    $m = $mothers[$a];
608
    if (!$p || !$m) {
609
        $COIs[$a]    = $IC_if_deadend;
610
        $ICknown[$a] = 2;
611
612
        return 0;
613
    }
614
615
    if ($verbose) {
0 ignored issues
show
Bug introduced by
The variable $verbose does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
616
        echo "</center><pre>$nl";
617
    }
618
    pater_side($p, $m, $a, 1); // launch tree exploration
619
    if ($verbose) {
620
        echo "</pre><center>$nl";
621
    }
622
623
    $ICknown[$a] = 1;
624
    $p           = $fathers[$a];
625
    $m           = $mothers[$a];
626
    foreach ($fathers as $i => $pere) {/* siblings share the same COI value */
627
        if ($i <> $a && $pere == $p && $mothers[$i] == $m) {
628
            $COIs[$i]    = $COIs[$a];
629
            $ICknown[$i] = 1;
630
        }
631
    }
632
    // echo "<!-- COI($a) = $COIs[$a] $IDs[$a] ($fathers[$a] x $mothers[$a])-->$nl" ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
633
    return 0;
634
}
635
636
/**
637
 * @param $nb_gen
638
 * @param $nloop
639
 *
640
 * @return int
641
 */
642
function boucle($nb_gen, $nloop)
643
{
644
    global $fathers, $mothers, $nbanims, $listing, $nl, $IDs;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
645
    $nbtot   = 0;
646
    $listing = '';
647
    if ($nloop < ($nb_gen + 20)) {
648
        $nloop = $nb_gen + 20;
649
    }
650
    $list = array(0 => 1); /* initialize list with Anim0 (rank = 1) */
651
    for ($j = 1; $j < $nloop; ++$j) {
652
        $new = 0;
653
        foreach ($list as $i => $rank) {
654 View Code Duplication
            if (false !== ($s = $fathers[$i])) {
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...
655
                if (!$list[$s]) {
656
                    $new = 1;
657
                    if ($j < $nb_gen) {
658
                        ++$nbtot;
659
                    }
660
                }
661
                $list[$s] = $rank + 1;
662
                if ($j < $nb_gen) {
663
                    ++$nbtot;
664
                }
665
                if ($j > $nloop - 10) {
666
                    $listing .= "Loop $j: Animal #$s " . $IDs[$s] . $nl;
667
                }
668
            }
669 View Code Duplication
            if (false !== ($d = $mothers[$i])) {
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...
670
                if (!$list[$d]) {
671
                    $new = 1;
672
                    if ($j < $nb_gen) {
673
                        ++$nbtot;
674
                    }
675
                }
676
                $list[$d] = $rank + 1;
677
                if ($j < $nb_gen) {
678
                    ++$nbtot;
679
                }
680
                if ($j > $nloop - 10) {
681
                    $listing .= "Loop $j: Animal #$d " . $IDs[$d] . $nl;
682
                }
683
            }
684
        }
685
        if (!$new) {
686
            break;
687
        }
688
    }
689
    if ($new) {
0 ignored issues
show
Bug introduced by
The variable $new does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
690
        $nbtot = 0;
691
    } /* Endless loop detected (see listing) */
692
693
    return $nbtot;
694
}
695
696
if (!function_exists('html_accents')) {
697
    /**
698
     * @param $string
699
     * @return mixed
700
     */
701
    function html_accents($string)
702
    {
703
        return $string;
704
    }
705
}
706
707
/**
708
 * @param $ID
709
 *
710
 * @return array
711
 */
712
function set_name($ID)
0 ignored issues
show
Coding Style introduced by
set_name uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
713
{
714
    global $sql2, $sql2bis, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
715
    $name = ' ';
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
716
    $ani  = array();
717
    if ($ID) {
718
        $sqlquery    = 'SELECT ID, NAAM, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID = '$ID'";
719
        $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
720
        $ani         = $GLOBALS['xoopsDB']->fetchBoth($queryresult);
721
        $name        = $ani[1];
722
        if ($sql2bis) { // true for E.R.o'S. only 
723
            $name = html_accents($name);
724
            //$affx = $ani[5] ;  // affix-ID
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
725
            if ($affx) {
726
                $affix  = fetch_record("$sql2bis '$affx'");
0 ignored issues
show
Bug introduced by
The variable $affx does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
727
                $type   = $affix[1];
728
                $affixe = html_accents($affix[0]);
729
                if ($type[0] === 'P') {
730
                    $name = '<i>' . $affixe . '</i>&nbsp;' . $name;
731
                }
732
                if ($type[0] === 'S') {
733
                    $name = $name . '&nbsp;<i>' . $affixe . '</i>';
734
                }
735
            }
736
            $ani[1] = $name;
737
        }
738
    }
739
740
    return $ani;
741
}
742
743
/**
744
 * @param $ems
745
 *
746
 * @return string
747
 */
748
function Ems_($ems)
749
{
750
    if (function_exists('Ems')) {
751
        return Ems($ems);
752
    }
753
    if (!$ems) {
754
        return '&nbsp;';
755
    }
756
    $e   = str_replace(' ', '+', $ems);
757
    $res = '<a href="#" style="text-decoration:none;" onClick="' . "window.open('http://www.somali.asso.fr/eros/decode_ems.php?$e'," . "'', 'resizable=no,width=570,height=370')" . '"' . "><b>$ems</b></a>";
758
759
    return $res;
760
}
761
762
/**
763
 * @param $ID
764
 *
765
 * @return string
766
 */
767
function one_animal($ID)
0 ignored issues
show
Coding Style introduced by
one_animal uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
768
{
769
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
770
    global $sex, $val, $sosa, $detail, $sql3;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
771
    $sosa = 12;
772
    // echo '<div style="position:relative;float:right;width=2.0em;color=white;">' . $sosa . '</div>' ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
773
    $animal = set_name($ID);
774
    list($ID, $name, $sex, $hd, $ems) = $animal;
0 ignored issues
show
Unused Code introduced by
The assignment to $hd is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $ems is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
775
    $sqlquery    = 'select SQL_CACHE count(ID) from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where father = '$ID' or mother = '$ID'";
776
    $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
777
    $nb          = $GLOBALS['xoopsDB']->fetchBoth($queryresult);
778
    $nb_children = $nb[0];
779
    if ($nb_children == 0) {
780
        $nb_children = _MA_PEDIGREE_COI_NO;
781
    }
782
    //$dogid = $animal[0];
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
783
    $content .= "<tr><td><a href=\"dog.php?id=" . $ID . "\">" . stripslashes($name) . '</a>';
0 ignored issues
show
Bug introduced by
The variable $content does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
784
    // if ($nb_enf == 0) echo ' &oslash;' ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
785
    if ($val) {
786
        $content .= $val;
787
    }
788
    if ($sex == 1) {
789
        $geslacht = "<img src=\"assets/images/female.gif\">";
790
    }
791
    if ($sex == 0) {
792
        $geslacht = "<img src=\"assets/images/male.gif\">";
793
    }
794
    $content .= '</td><td>' . $geslacht . '</td><td>' . $nb_children . _MA_PEDIGREE_COI_OFF . '</td></tr>';
0 ignored issues
show
Bug introduced by
The variable $geslacht does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
795
796
    return $content;
797
}
798
799
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  MAIN  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
800
801
$nl = "\n"; // the newline character
802
803
//edit by jc
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
804
//$link = @mysqli_pconnect ($host, $database, $password)
805
//   or   die ("<html><body>Connection to database failed.</body></html>") ;
806
$s      = $_GET['s'];
807
$d      = $_GET['d'];
808
$detail = $_GET['detail'];
809
810
if (isset($si)) {
811
    $s = findId($si);
812
}
813
if (isset($da)) {
814
    $d = findId($da);
815
}
816
//test for variables
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
817
//echo "si=".$si." da=".$da." s=".$s." d=".$d;
818
$utils = $GLOBALS['xoopsDB']->query("select user(), date_format(now(),'%d-%b-%Y')");
819
list($who, $jourj) = $GLOBALS['xoopsDB']->fetchBoth($utils);
820
821
if (isset($IC)) {
822
    $detail = -1;
823
    $a      = $IC;
824
}
825
826
if (!isset($detail)) {
827
    $detail = 0;
828
}
829
830
if (!isset($a)) {
831
    if ($s && !isset($d)) {
832
        $a = $s;
833
        $s = '';
834
    }
835
    if ($d && !isset($s)) {
836
        $a = $d;
837
        $d = '';
838
    }
839
}
840
841
if (isset($a)) {
842
    $sqlquery    = 'select ID, father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID  = '$a'";
843
    $queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
844
    $rowhond     = $GLOBALS['xoopsDB']->fetchBoth($queryresult);
845
    $a           = $rowhond['Id'];
846
    $s           = $rowhond['father'];
847
    $d           = $rowhond['mother'];
848
}
849
$a += 0;
850
$s += 0;
851
$d += 0; // [IDs are numbers]
852
853
$xoopsTpl->assign('ptitle', _MA_PEDIGREE_COI_CKRI);
854
$xoopsTpl->assign('pcontent', strtr(_MA_PEDIGREE_COI_CKRI_CT, array('[animalType]' => $moduleConfig['animalType'])));
855
856
if (!$s && !$d) {
857
    $error = _MA_PEDIGREE_COI_SPANF1 . $a . _MA_PEDIGREE_COI_SPANF2;
858
    $xoopsTpl->assign('COIerror', $error);
859
}
860
861
$maxn_ = 1000;
862
$maxr_ = 9;
863
864
$maxn     = $maxn_;
865
$maxr     = $maxr_;
866
$cinnamon = 0;
867
$chocolat = 0;
868
$dilution = 0;
869
$sexlred  = 0;
870
871
$nivomin = -$maxr; /* Maximal depth of recursion (-10) */
872
$codec   = 0;
873
$gens    = 4; /* 4 gens. for both pedigrees of couple */
874
$litter  = 0;
875
876
// echo "s:".$s."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
877
// echo "d:".$d."<br />";
878
879
$codec1 = $d;
880
$codec2 = $s;
881
$val    = '';
882
883
if (!$s && $d) {
884
    $codec1 = $d;
885
    $codec2 = 0;
886
}
887
if ($codec1 == $codec2) {
888
    $codec2 = 0;
889
}
890
891
$sqlquery    = 'select father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID  = '$codec1'";
892
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
893
$rowhond     = $GLOBALS['xoopsDB']->fetchBoth($queryresult);
894
$a1          = $rowhond['Id'];
895
$s1          = $rowhond['father'];
896
$d1          = $rowhond['mother'];
897
$sex1        = $rowhond['roft'];
898
899
// echo "sqlquery:".$sqlquery."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
900
901
$sqlquery    = 'select father, mother, roft from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " where ID  = '$codec2'";
902
$queryresult = $GLOBALS['xoopsDB']->query($sqlquery);
903
$rowhond     = $GLOBALS['xoopsDB']->fetchBoth($queryresult);
904
$a2          = $rowhond['Id'];
905
$s2          = $rowhond['father'];
906
$d2          = $rowhond['mother'];
907
$sex2        = $rowhond['roft'];
908
909
// echo "sqlquery:".$sqlquery."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
910
911
//if ($sex1 == '0' && $sex2 == '1') { $a3 = $a1 ; $a1 = $a2 ; $a2 = $a3 ; }   /* permute dam and sire */
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
912
$codec1 = $a1;
913
$codec2 = $a2;
914
if (!isset($s1) || !isset($d1) || !isset($s2) || !isset($d2)) {
915
    $xoopsTpl->assign('COIerror', _MA_PEDIGREE_COI_SGPU);
916
}
917
918
$title   = strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $moduleConfig['father'])) . ' (' . stripslashes(showParent($codec2)) . ')' . _MA_PEDIGREE_COI_AND . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $moduleConfig['mother'])) . ' (' . stripslashes(showParent($codec1)) . ')';
919
$content = stripslashes(one_animal($codec2));
920
$content .= stripslashes(one_animal($codec1));
921
$val = '';
922
$xoopsTpl->assign('SADtitle', $title);
923
$xoopsTpl->assign('SADcontent', $content);
924
$xoopsTpl->assign('SADexplain', strtr(_MA_PEDIGREE_COI_SDEX, array('[animalType]' => $moduleConfig['animalType'], '[animalTypes]' => $moduleConfig['animalTypes'], '[children]' => $moduleConfig['children'])));
925
926
$de_cujus = 0;
927
$sire_ID  = $_GET['s'];
928
$dam_ID   = $_GET['d'];
929
$rec      = 'select ID from ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE father = '" . $sire_ID . "' and mother = '" . $dam_ID . "' order by NAAM";
930
$result   = $GLOBALS['xoopsDB']->query($rec);
931
$content  = '';
932
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
933
    $content .= one_animal($row['Id']);
934
}
935
936
$xoopsTpl->assign('COMtitle', strtr(_MA_PEDIGREE_COI_COMTIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'])));
937
$xoopsTpl->assign('COMexplain', strtr(_MA_PEDIGREE_COI_COMEX, array('[animalType]' => $moduleConfig['animalType'], '[children]' => $moduleConfig['children'])));
938
$xoopsTpl->assign('COMcontent', $content);
939
940
if (!isset($nb_gen)) {
941
    $nb_gen = 7;
942
    if ($detail) {
943
        $nb_gen = 9;
944
    }
945
} elseif ($nb_gen < $pedigree) {
946
    $nb_gen = $pedigree;
947
}
948
949
$IDs = array($de_cujus + 0, $codec1 + 0, $codec2 + 0); /* Structuring animal IDs into memory */
950
951
$nbanims = GENEALOGY(); // ************************************************************* //
952
953
for ($i = 0; $i <= $nbanims; ++$i) {
954
    $empty[$i] = 0;
955
}
956
957
foreach ($fathers as $i => $a) {
958
    if ($a) {
959
        $fathers[$i] = $inds[$a];
960
    }
961
} /* Replace parents codes */
962
foreach ($mothers as $i => $a) {
963
    if ($a) {
964
        $mothers[$i] = $inds[$a];
965
    }
966
} /*   by  their  indices  */
967
968
dist_m($mothers[0]); // set "$mater" array (list of all maternal ascendants), for Anim #0
969
970
/* Calculating CONSANGUINITY by dual (paternal & maternal) path method */
971
$f       = $empty;
972
$ICknown = $empty;
973
$deltaf  = $empty;
974
$marked  = $empty;
975
976
/******************  LAUNCHING ALL RECURSIONS  ********************/
977
/*                                                                */
978
CONSANG(-1); /* [-1 is standing for de_cujus]
979
/*                                                                */
980
/******************************************************************/
981
982
$nf = ceil(100 * $COIs[0]);
983
if ($nf >= 55) {
984
    $w = _MA_PEDIGREE_COI_HUGE;
985
} else {
986
    if ($nf >= 35) {
987
        $w = _MA_PEDIGREE_COI_VHIG;
988
    } else {
989
        if ($nf >= 20) {
990
            $w = _MA_PEDIGREE_COI_HIGH;
991
        } else {
992
            if ($nf >= 10) {
993
                $w = _MA_PEDIGREE_COI_MEDI;
994
            } else {
995
                if ($nf >= 05) {
996
                    $w = _MA_PEDIGREE_COI_LOW;
997
                } else {
998
                    if ($nf >= 02) {
999
                        $w = _MA_PEDIGREE_COI_VLOW;
1000
                    } else {
1001
                        if ($nf >= 01) {
1002
                            $w = _MA_PEDIGREE_COI_VVLO;
1003
                        } else {
1004
                            $w = _MA_PEDIGREE_COI_TLTB;
1005
                        }
1006
                    }
1007
                }
1008
            }
1009
        }
1010
    }
1011
}
1012
$w = _MA_PEDIGREE_COI_TVI . ' ' . $w;
1013
1014
$nb_all = 0;
1015
count_all(0, 0); // count all ascendants in flat tree
1016
1017
$nbmax  = (2 << $nb_gen) - 2;
1018
$asctc  = _MA_PEDIGREE_COI_ASTC . $nb_gen . _MA_PEDIGREE_COI_ASTCGEN . $nbmax . ')';
1019
$ascuni = _MA_PEDIGREE_COI_ASDKA . $nb_gen . _MA_PEDIGREE_COI_ASGEN;
1020
$xoopsTpl->assign('ASCtitle', _MA_PEDIGREE_COI_ACTIT);
1021
$xoopsTpl->assign('ASCtc', $asctc);
1022
$xoopsTpl->assign('ASCuni', $ascuni);
1023
$xoopsTpl->assign('ASCall', $nb_all);
1024
$xoopsTpl->assign('ASCani', $nbani);
1025
$xoopsTpl->assign('ASCexplain', _MA_PEDIGREE_COI_ACEX);
1026
1027
$f0 = substr($COIs[0], 0, 8);
1028
if (!$f0) {
1029
    $f0 = 'n.a.';
1030
}
1031
$f1 = 100 * $f0;
1032
1033
$xoopsTpl->assign('COItitle', strtr(_MA_PEDIGREE_COI_COITIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'])));
1034
$xoopsTpl->assign('COIperc', $w);
1035
$xoopsTpl->assign('COIval', $f1);
1036
$xoopsTpl->assign('COIexplain', strtr(_MA_PEDIGREE_COI_COIEX, array('[animalType]' => $moduleConfig['animalType'], '[animalTypes]' => $moduleConfig['animalTypes'], '[children]' => $moduleConfig['children'])));
1037
$xoopsTpl->assign('COIcoi', _MA_PEDIGREE_COI_COI);
1038
$dogid = XoopsRequest::getInt('dogid', 0, 'get');
1039
$query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' SET coi=' . $f1 . ' WHERE ID = ' . $dogid;
1040
$GLOBALS['xoopsDB']->queryF($query);
1041
arsort($deltaf);
1042
$j = 1;
1043
foreach ($deltaf as $i => $v) {
1044
    if ($j > 12) {
1045
        break;
1046
    }
1047
    ++$j;
1048
    $code   = $IDs[$i];
1049
    $v      = substr($v, 0, 7);
1050
    $animal = set_name($IDs[$i]);
1051
    $name   = $animal[1];
1052
    if (!$name) {
1053
        $name = $i . ' [' . $IDs[$i] . ']';
1054
    }
1055
    if ($v > 0.0001 && $v < 1.0) {
1056
        $dogs[] = array('id' => $code, 'name' => stripslashes($name), 'coi' => 100 * $v);
1057
    }
1058
}
1059
1060
$xoopsTpl->assign('TCAtitle', _MA_PEDIGREE_COI_TCATIT);
1061
$xoopsTpl->assign('TCApib', _MA_PEDIGREE_COI_TCApib);
1062
$xoopsTpl->assign('dogs', $dogs);
1063
$xoopsTpl->assign('TCAexplain', strtr(_MA_PEDIGREE_COI_TCAEX, array(
1064
    '[animalType]'  => $moduleConfig['animalType'],
1065
    '[animalTypes]' => $moduleConfig['animalTypes'],
1066
    '[children]'    => $moduleConfig['children'],
1067
    '[mother]'      => $moduleConfig['mother'],
1068
    '[father]'      => $moduleConfig['father']
1069
)));
1070
1071
if ($detail) {
1072
    if ($verbose) {
1073
        $verbose = 0;
1074
    }
1075
    if (count($COIs) > 1) {
1076
        $ICs = $COIs;
1077
        arsort($ICs);
1078
        $j = 1;
1079
        foreach ($ICs as $i => $ic) {
1080
            if ($j > 12) {
1081
                break;
1082
            }
1083
            ++$j;
1084
            $ID   = $IDs[$i];
1085
            $ani  = set_name($ID);
1086
            $name = $ani[1];
1087
            $ic   = substr($ic, 0, 6);
1088
            if ($ic > 0.125 && $i) {
1089
                $mia[] = array('id' => $ID, 'name' => stripslashes($name), 'coi' => 100 * $ic);
1090
            }
1091
        }
1092
    }
1093
    $xoopsTpl->assign('MIAtitle', _MA_PEDIGREE_COI_MIATIT);
1094
    $xoopsTpl->assign('mia', $mia);
1095
    $xoopsTpl->assign('MIAexplain', strtr(_MA_PEDIGREE_COI_MIAEX, array('[animalType]' => $moduleConfig['animalType'])));
1096
1097
    if (!$ICknown[1]) {
1098
        $marked = $empty;
1099
        CONSANG(1);
1100
    } // Sire
1101
    if (!$ICknown[2]) {
1102
        $marked = $empty;
1103
        CONSANG(2);
1104
    } // Dam
1105
    $COR = 2.0 * $COIs[0] / sqrt((1. + $COIs[1]) * (1. + $COIs[2]));
1106
    $COR = substr($COR, 0, 8);
1107
    if (!$COR) {
1108
        $COR = 'n.a.';
1109
    }
1110
    $f1 = substr($COIs[1], 0, 8);
1111
    $f2 = substr($COIs[2], 0, 8);
1112
    if (!$f1) {
1113
        $f1 = 'n.a.';
1114
    }
1115
    if (!$f2) {
1116
        $f2 = 'n.a.';
1117
    }
1118
    $SSDcor  = (100 * $COR);
1119
    $SSDsire = (100 * $f2);
1120
    $SSDdam  = (100 * $f1);
1121
}
1122
1123
$xoopsTpl->assign('SSDtitle', strtr(_MA_PEDIGREE_COI_SSDTIT, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'])));
1124
$xoopsTpl->assign('SSDcortit', _MA_PEDIGREE_COI_SSDcor);
1125
$xoopsTpl->assign('SSDbsd', strtr(_MA_PEDIGREE_COI_SDDbsd, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'])));
1126
$xoopsTpl->assign('SSDcor', $SSDcor);
1127
1128
$xoopsTpl->assign('SSDS', _MA_PEDIGREE_COI_COI . _MA_PEDIGREE_FROM . strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $moduleConfig['father'])));
1129
$xoopsTpl->assign('SSDsire', $SSDsire);
1130
$xoopsTpl->assign('SSDM', _MA_PEDIGREE_COI_COI . _MA_PEDIGREE_FROM . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $moduleConfig['mother'])));
1131
$xoopsTpl->assign('SSDdam', $SSDdam);
1132
1133
// echo "SSDsire : ".$SSDsire."<br />";
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1134
// echo "SSDdam : ".$SSDdam."<br />";
1135
// print_r($COIs);
1136
1137
$xoopsTpl->assign('SSDexplain', strtr(_MA_PEDIGREE_COI_SSDEX, array('[father]' => $moduleConfig['father'], '[mother]' => $moduleConfig['mother'], '[animalType]' => $moduleConfig['animalTypes'])));
1138
$xoopsTpl->assign('TNXtitle', _MA_PEDIGREE_COI_TNXTIT);
1139
$xoopsTpl->assign('TNXcontent', _MA_PEDIGREE_COI_TNXCON);
1140
$xoopsTpl->assign('Name', _MA_PEDIGREE_FLD_NAME);
1141
$xoopsTpl->assign('Gender', _MA_PEDIGREE_FLD_GEND);
1142
$xoopsTpl->assign('Children', strtr(_MA_PEDIGREE_FLD_PUPS, array('[children]' => $moduleConfig['children'])));
1143
1144
//add data to smarty template
1145
$xoopsTpl->assign('explain', _MA_PEDIGREE_EXPLAIN);
1146
1147
//comments and footer
1148
include XOOPS_ROOT_PATH . '/footer.php';
1149