Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

ScheduledFlushDiscoverer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A scheduleFlush() 0 11 2
A shouldFlush() 0 7 2
A __construct() 0 3 1
A getFlush() 0 6 1
1
<?php
2
3
namespace SilverStripe\Core\Startup;
4
5
use SilverStripe\Core\Kernel;
6
7
/**
8
 * Checks the manifest cache for flush being scheduled in a
9
 * previous request
10
 */
11
class ScheduledFlushDiscoverer implements FlushDiscoverer
12
{
13
    /**
14
     * Active kernel
15
     *
16
     * @var Kernel
17
     */
18
    protected $kernel;
19
20
    public function __construct(Kernel $kernel)
21
    {
22
        $this->kernel = $kernel;
23
    }
24
25
    /**
26
     * Returns the flag whether the manifest flush
27
     * has been scheduled in previous requests
28
     *
29
     * @return bool unix timestamp
30
     */
31
    protected function getFlush()
32
    {
33
        $classLoader = $this->kernel->getClassLoader();
34
        $classManifest = $classLoader->getManifest();
35
36
        return (bool) $classManifest->isFlushScheduled();
37
    }
38
39
    /**
40
     * @internal This method is not a part of public API and will be deleted without a deprecation warning
41
     *
42
     * This method is here so that scheduleFlush functionality implementation is kept close to the check
43
     * implementation.
44
     */
45
    public static function scheduleFlush(Kernel $kernel)
46
    {
47
        $classLoader = $kernel->getClassLoader();
48
        $classManifest = $classLoader->getManifest();
49
50
        if (!$classManifest->isFlushScheduled()) {
51
            $classManifest->scheduleFlush();
52
            return true;
53
        }
54
55
        return false;
56
    }
57
58
    public function shouldFlush()
59
    {
60
        if ($this->getFlush()) {
61
            return true;
62
        }
63
64
        return null;
65
    }
66
}
67