1
|
|
|
<?php namespace Mbh\Collection\Traits; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MBHFramework |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/MBHFramework/mbh-framework |
7
|
|
|
* @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos |
8
|
|
|
* @license https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
trait Capacity |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var integer internal capacity |
15
|
|
|
*/ |
16
|
|
|
private $capacity = self::MIN_CAPACITY; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Returns the current capacity. |
20
|
|
|
* |
21
|
|
|
* @return int |
22
|
|
|
*/ |
23
|
|
|
public function capacity(): int |
24
|
|
|
{ |
25
|
|
|
return $this->capacity; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Ensures that enough memory is allocated for a specified capacity. This |
30
|
|
|
* potentially reduces the number of reallocations as the size increases. |
31
|
|
|
* |
32
|
|
|
* @param int $capacity The number of values for which capacity should be |
33
|
|
|
* allocated. Capacity will stay the same if this value |
34
|
|
|
* is less than or equal to the current capacity. |
35
|
|
|
*/ |
36
|
|
|
public function allocate(int $capacity) |
37
|
|
|
{ |
38
|
|
|
$this->capacity = max($capacity, $this->capacity); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return the structures growth factor. |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
protected function getGrowthFactor(): float |
45
|
|
|
{ |
46
|
|
|
return 2; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return float to multiply by when decreasing capacity. |
51
|
|
|
*/ |
52
|
|
|
protected function getDecayFactor(): float |
53
|
|
|
{ |
54
|
|
|
return 0.5; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return float the ratio between size and capacity when capacity should be |
59
|
|
|
* decreased. |
60
|
|
|
*/ |
61
|
|
|
protected function getTruncateThreshold(): float |
62
|
|
|
{ |
63
|
|
|
return 0.25; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Checks and adjusts capacity if required. |
68
|
|
|
*/ |
69
|
|
|
protected function checkCapacity() |
70
|
|
|
{ |
71
|
|
|
if ($this->shouldIncreaseCapacity()) { |
72
|
|
|
$this->increaseCapacity(); |
73
|
|
|
} else { |
74
|
|
|
if ($this->shouldDecreaseCapacity()) { |
75
|
|
|
$this->decreaseCapacity(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Called when capacity should be increased to accommodate new values. |
82
|
|
|
*/ |
83
|
|
|
protected function increaseCapacity() |
84
|
|
|
{ |
85
|
|
|
$this->capacity = max($this->count(), $this->capacity * $this->getGrowthFactor()); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Called when capacity should be decrease if it drops below a threshold. |
90
|
|
|
*/ |
91
|
|
|
protected function decreaseCapacity() |
92
|
|
|
{ |
93
|
|
|
$this->capacity = max(self::MIN_CAPACITY, $this->capacity * $this->getDecayFactor()); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return whether capacity should be increased. |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
protected function shouldDecreaseCapacity(): bool |
100
|
|
|
{ |
101
|
|
|
return count($this) <= $this->capacity * $this->getTruncateThreshold(); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return whether capacity should be increased. |
106
|
|
|
*/ |
107
|
|
|
protected function shouldIncreaseCapacity(): bool |
108
|
|
|
{ |
109
|
|
|
return count($this) >= $this->capacity; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths