Passed
Push — master ( 8b5b84...34c143 )
by IRFA
01:51
created

Roulette::get()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 22
rs 9.5222
cc 5
nc 7
nop 1
1
<?php 
2
/* 
3
	Author:Irfa Ardiansyah <[email protected]>
4
	Simple Items Gatcha with PHP
5
*/
6
namespace Irfa\Gatcha\Roulette;
7
8
use Exception;
9
use Irfa\Gatcha\Roulette\RateUp;
10
11
class Roulette extends RateUp {
12
 	
13
 	protected static function itemDropUp($item_list, $items, $rate)
14
 	{
15
 		return self::_itemDropUp($item_list, $items, $rate);
16
 	}
17
	protected static function get($items) {
18
		if (is_array($items))
19
		{
20
			$max = 0;
21
			foreach ($items as $key => $value) {
22
				$max += $value;
23
				$items[$key] = $max;
24
			}
25
26
			$random = mt_rand(1, $max);
27
28
				foreach ($items as $item => $max)
29
				{
30
					if ($random <= $max) {
31
						break;
32
					}
33
				}
34
				 return $item;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item seems to be defined by a foreach iteration on line 28. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
35
		} else {
36
				throw new Exception('Parameter must be an array.');
37
38
				return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
39
		}
40
	}
41
	
42
}