Issues (8)

src/Roulette/Roulette.php (5 issues)

1
<?php 
2
/* 
3
	Author:Irfa Ardiansyah <[email protected]>
4
	Simple Items Gatcha with PHP
5
	v2.1
6
	https://github.com/irfaardy/php-gacha
7
*/
8
namespace Irfa\Gatcha\Roulette;
9
10
use Exception;
11
use Irfa\Gatcha\Roulette\RateUp;
12
13
class Roulette extends RateUp {
14
15
 	 /**
16
     * encode to Json.
17
     *
18
     * @param string $dt
19
     * @return json
0 ignored issues
show
The type Irfa\Gatcha\Roulette\json was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     */
21
 	protected static function jsonItem($dt) {
22
 		$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...
23
 		return json_encode($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return json_encode($data) returns the type string which is incompatible with the documented return type Irfa\Gatcha\Roulette\json.
Loading history...
24
 	}
25
26
 	 /**
27
     * Add drop up rate to items.
28
     *
29
     * @param mixed $item_list
30
     * @param array $items
31
     * @param float $rate
32
     * @return array
33
     */
34
 	protected static function itemDropUp($item_list, $items, $rate)
35
 	{
36
 		return self::_itemDropUp($item_list, $items, $rate);
37
 	}
38
39
 	 /**
40
     * Get Item.
41
     *
42
     * @param array $item
43
     * @return string
44
     */
45
	protected static function get($items) {
46
		if (is_array($items))
47
		{
48
			$max = 0;
49
			foreach ($items as $key => $value) {
50
				$max += $value;
51
				$items[$key] = $max;
52
			}
53
54
			$random = mt_rand(1, $max);
55
56
				foreach ($items as $item => $max)
57
				{
58
					if ($random <= $max) {
59
						break;
60
					}
61
				}
62
				 return $item;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item seems to be defined by a foreach iteration on line 56. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
63
		} else {
64
				throw new Exception('Parameter must be an array.');
65
66
				return false;
0 ignored issues
show
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...
67
		}
68
	}
69
	
70
}