Completed
Push — ezp25003-trash_subitems_count_... ( 8a8898 )
by André
34:44
created

PurgeForContentHttpCacheSlot::purgeHttpCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\MVC\Symfony\Cache\Http\SignalSlot;
12
13
use eZ\Publish\Core\SignalSlot\Signal;
14
15
/**
16
 * An abstract HTTP Cache purging Slot that purges cache for a Content.
17
 *
18
 * Will by default use the contentId property of the signal object, as it is the most common. Override the
19
 * extractContentId() method in your own signal to use a different property.
20
 */
21
abstract class PurgeForContentHttpCacheSlot extends HttpCacheSlot
22
{
23
    /**
24
     * Purges all caches.
25
     *
26
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
27
     *
28
     * @return mixed
29
     */
30
    protected function purgeHttpCache(Signal $signal)
31
    {
32
        return $this->httpCacheClearer->purgeForContent($this->extractContentId($signal), $this->extractLocationIds($signal));
33
    }
34
35
    /**
36
     * Default implementation that returns the contentId property's value.
37
     *
38
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
39
     *
40
     * @return mixed Content ID
41
     */
42
    protected function extractContentId(Signal $signal)
43
    {
44
        return $signal->contentId;
0 ignored issues
show
Documentation introduced by
The property contentId does not exist on object<eZ\Publish\Core\SignalSlot\Signal>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
45
    }
46
47
    /**
48
     * Default implementation that returns the signal location property values.
49
     *
50
     * This is extracted and provided to purgeForContent in case content is trashed where affected location is no longer returned by API.
51
     *
52
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
53
     *
54
     * @return array Location ID's
55
     */
56
    protected function extractLocationIds(Signal $signal)
57
    {
58
        $locationIds = [];
59
        if (isset($signal->locationId)) {
60
            $locationIds[] = $signal->locationId;
0 ignored issues
show
Documentation introduced by
The property locationId does not exist on object<eZ\Publish\Core\SignalSlot\Signal>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
        }
62
63
        if (isset($signal->parentLocationId)) {
64
            $locationIds[] = $signal->parentLocationId;
0 ignored issues
show
Documentation introduced by
The property parentLocationId does not exist on object<eZ\Publish\Core\SignalSlot\Signal>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
        }
66
67
        return $locationIds;
68
    }
69
}
70