Task::garbageCollect()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 0
crap 4
1
<?php
2
3
namespace SymfonyBundles\Fork;
4
5
abstract class Task implements TaskInterface
6
{
7
    /**
8
     * @var int Number of iterations to perform garbage cleaning
9
     */
10
    public const GARBAGE_COLLECT_ITERATIONS = 100;
11
12
    /**
13
     * Performs garbage collection when the iteration limit is reached.
14
     */
15 1
    protected function garbageCollect(): bool
16
    {
17 1
        static $currentIteration = 0;
18
19 1
        if (0 === $currentIteration && false === gc_enabled()) {
20 1
            gc_enable();
21
        }
22
23 1
        if (++$currentIteration >= static::GARBAGE_COLLECT_ITERATIONS) {
24 1
            $currentIteration = 0;
25
26 1
            gc_collect_cycles();
27
28 1
            return true;
29
        }
30
31 1
        return false;
32
    }
33
}
34