SoftLimitTrait::memoryLimitReached()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 13
ccs 4
cts 7
cp 0.5714
crap 3.7085
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Cli;
6
7
trait SoftLimitTrait
8
{
9
    abstract protected function getMemoryLimit(): int;
10
11 5
    protected function memoryLimitReached(): bool
12
    {
13 5
        $limit = $this->getMemoryLimit();
14
15 5
        if ($limit !== 0) {
16
            $usage = memory_get_usage(true);
17
18
            if ($usage >= $limit) {
19
                return true;
20
            }
21
        }
22
23 5
        return false;
24
    }
25
}
26