Completed
Push — master ( 87a78f...b306f9 )
by André
97:52 queued 72:52
created

PurgeForContentHttpCacheSlot::extractLocationIds()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
cc 3
eloc 7
nc 4
nop 1
rs 9.4285
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));
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\MVC\Symf...rger::purgeForContent() has been deprecated with message: in 6.5, design flaw on deleted/trashed content, use purge() when content does not exist for now. See EZP-25696 for potential future feature to solve this.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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