Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( a6a1be...553b87 )
by Dan
09:17
created

get_amount()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 12
nop 0
dl 0
loc 26
rs 9.5222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
function checkPortTradeable($port, $player) {
4
	if ($port->getSectorID() != $player->getSectorID()) {
5
		return 'That port is not in this sector!';
6
	}
7
	if (!$port->exists()) {
8
		return 'There is no port in this sector!';
9
	}
10
	if ($player->getRelation($port->getRaceID()) <= RELATIONS_WAR) {
11
		return 'We will not trade with our enemies!';
12
	}
13
	if ($port->getReinforceTime() > TIME) {
14
		return 'We are still repairing damage caused during the last raid.';
15
	}
16
	return true;
17
}
18
19
function check_bargain_number($amount, $ideal_price, $offered_price, $bargain_price, &$container) {
20
	global $var, $player;
21
22
	$port = $player->getSectorPort();
23
	
24
	// increase current number of tries
25
	$container['number_of_bargains'] = isset($var['number_of_bargains']) ? $var['number_of_bargains'] + 1 : 1;
26
27
	if (isset($var['overall_number_of_bargains'])) {
28
		// lose relations for bad bargain
29
		$player->decreaseRelationsByTrade($amount, $port->getRaceID());
30
		$player->increaseHOF(1, array('Trade', 'Results', 'Fail'), HOF_PUBLIC);
31
		// transfer values
32
		transfer('overall_number_of_bargains');
33
34
		// does we have enough of it?
35
		if ($container['number_of_bargains'] > $container['overall_number_of_bargains']) {
36
			$player->decreaseRelationsByTrade($amount, $port->getRaceID());
37
			$player->increaseHOF(1, array('Trade', 'Results', 'Epic Fail'), HOF_PUBLIC);
38
			create_error('You don\'t want to accept my offer? I\'m sick of you! Get out of here!');
39
		}
40
41
		$port_off = round($offered_price * 100 / $ideal_price);
42
		$trader_off = round($bargain_price * 100 / $ideal_price);
43
44
		// get relative numbers!
45
		// be carefull! one of this value is negative!
46
		$port_off_rel = 100 - $port_off;
47
		$trader_off_rel = 100 - $trader_off;
48
49
		// only do something, if we are more off than the trader
50
		if (abs($port_off_rel) > abs($trader_off_rel)) {
51
			// get a random number between
52
			// (port_off) and (100 +/- $trader_off_rel)
53
			if (100 + $trader_off_rel < $port_off) {
54
				$offer_modifier = mt_rand(100 + $trader_off_rel, $port_off);
0 ignored issues
show
Bug introduced by
$port_off of type double is incompatible with the type integer expected by parameter $max of mt_rand(). ( Ignorable by Annotation )

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

54
				$offer_modifier = mt_rand(100 + $trader_off_rel, /** @scrutinizer ignore-type */ $port_off);
Loading history...
Bug introduced by
100 + $trader_off_rel of type double is incompatible with the type integer expected by parameter $min of mt_rand(). ( Ignorable by Annotation )

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

54
				$offer_modifier = mt_rand(/** @scrutinizer ignore-type */ 100 + $trader_off_rel, $port_off);
Loading history...
55
			} else {
56
				$offer_modifier = mt_rand($port_off, 100 + $trader_off_rel);
57
			}
58
59
			$container['offered_price'] = round($container['ideal_price'] * $offer_modifier / 100);
60
		}
61
	} else {
62
		$container['overall_number_of_bargains'] = mt_rand(2, 5);
63
	}
64
}
65