Passed
Push — master ( 08b4be...8d11b6 )
by IRFA
01:57 queued 10s
created

Roulette   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 32
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonItem() 0 3 1
A get() 0 22 5
A itemDropUp() 0 3 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 jsonItem($dt){
14
 		$data['data'] = ['item' => $dt];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
15
 		return json_encode($data);
16
 	}
17
 	protected static function itemDropUp($item_list, $items, $rate)
18
 	{
19
 		return self::_itemDropUp($item_list, $items, $rate);
20
 	}
21
	protected static function get($items) {
22
		if (is_array($items))
23
		{
24
			$max = 0;
25
			foreach ($items as $key => $value) {
26
				$max += $value;
27
				$items[$key] = $max;
28
			}
29
30
			$random = mt_rand(1, $max);
31
32
				foreach ($items as $item => $max)
33
				{
34
					if ($random <= $max) {
35
						break;
36
					}
37
				}
38
				 return $item;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item seems to be defined by a foreach iteration on line 32. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
39
		} else {
40
				throw new Exception('Parameter must be an array.');
41
42
				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...
43
		}
44
	}
45
	
46
}