Issues (1369)

classes/Bonus/ValueBonused.php (3 issues)

1
<?php
2
/**
3
 * Created by Gorlum 01.12.2017 8:34
4
 */
5
6
namespace Bonus;
7
8
use \SN;
0 ignored issues
show
The type \SN 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...
9
10
class ValueBonused {
11
12
  public $base = 0;
13
  public $value = 0;
14
  public $snId = 0;
15
  public $context = [];
16
17
18
  /**
19
   * @var BonusListAtom $bonusList
20
   */
21
  protected $bonusList;
22
23
  /**
24
   * [(int)$sourceUnitSnId] => (float)bonusValue
25
   *
26
   * @var float[] $bonusValues
27
   */
28
  public $bonusValues = [];
29
30
  /**
31
   * @var BonusCatalog $bonusCatalog
32
   */
33
  protected $bonusCatalog;
34
35
  protected $calculated = false;
36
37
  /**
38
   * ValueBonused constructor.
39
   *
40
   * @param int       $unitSnId
41
   * @param int|float $baseValue
42
   * @param array     $context
43
   */
44
  public function __construct($unitSnId, $baseValue, $context = []) {
0 ignored issues
show
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

44
  public function __construct($unitSnId, $baseValue, /** @scrutinizer ignore-unused */ $context = []) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    $this->snId = $unitSnId;
46
47
    $this->base = $baseValue;
48
    $this->value = $this->base;
49
    $this->bonusValues = [];
50
51
    $this->bonusCatalog = \SN::$gc->bonusCatalog;
52
  }
53
54
55
  /**
56
   * @param array $context - Context list of locations: [LOC_xxx => (data)]
57
   *
58
   * @return float|int
59
   */
60
  public function getValue($context = []) {
61
    // Context can differ. However - it shouldn't
62
    if ($this->calculated && $this->context == $context) {
63
      return $this->value;
64
    }
65
66
67
    $this->context = $context;
68
    $this->value = $this->base;
69
    $this->bonusValues = [];
70
    $this->calculated = true;
71
72
    $this->bonusList = $this->bonusCatalog->getBonusListAtom($this->snId);
73
    if (!$this->bonusList instanceof BonusListAtom) {
74
      return $this->base;
75
    }
76
77
    $this->applyBonuses($context);
78
79
    return $this->value;
80
  }
81
82
  /**
83
   * Calculates real bonus values within supplied context
84
   *
85
   * @param array $context - Context list of locations: [LOC_xxx => (data)]
86
   */
87
  protected function applyBonuses($context = []) {
88
    $this->bonusValues = [BONUS_NONE => $this->base];
89
    if (!$this->bonusList instanceof BonusListAtom) {
0 ignored issues
show
$this->bonusList is always a sub-type of Bonus\BonusListAtom.
Loading history...
90
      return;
91
    }
92
93
    foreach ($this->bonusList->getBonusAtoms() as $unitId => $bonusAtom) {
94
      $amount = SN::$gc->valueStorage->getValue($unitId, $context);
95
96
      $this->bonusValues[$unitId] = $bonusAtom->adjustValue($this->value, $amount, $this->base);
97
    }
98
99
// TODO - проследить, что бы ниже не было отрицательных значений
100
//            $mercenary_level = $mercenary_bonus < 0 && $mercenary_level * $mercenary_bonus < -90 ? -90 / $mercenary_bonus : $mercenary_level;
101
//            $value += $base_value * $mercenary_level * $mercenary_bonus / 100;
102
  }
103
104
}
105