Completed
Push — master ( 4b4fe2...87ee03 )
by Nicolaas
07:25
created

updateCacheKeyFragments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
class DynamicCacheSecureAndFlushable extends Extension implements flushable
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function updateEnabled(&$enabled)
6
    {
7
        // Disable caching for this request if a user is logged in
8
        if (Member::currentUserID()) {
9
            $enabled = false;
10
        }
11
12
        // Disable caching for this request if in dev mode
13
        elseif (Director::isDev()) {
14
            $enabled = false;
15
        }
16
17
        // Disable caching if the request is in dev mode
18
        else {
19
            $session = Session::get_all();
20
            if ($session && count($session)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $session of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
21
                $enabled = false;
22
            }
23
        }
24
    }
25
26
    public function updateCacheKeyFragments(array &$fragments)
27
    {
28
        $fragments[] = Member::currentUserID();
29
    }
30
31
    public static function flush()
32
    {
33
        DynamicCache::inst()->clear();
34
    }
35
}
36