StorageTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A flush() 0 8 3
A flushByTag() 0 10 3
A isValidTag() 0 4 1
A isValidEntryIdentifier() 0 7 2
1
<?php
2
3
/**
4
 * AppserverIo\Storage\StorageTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      http://github.com/appserver-io/storage
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Storage;
22
23
/**
24
 * A trait implementation providing basic storage functionality.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2015 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      http://github.com/appserver-io/storage
30
 * @link      http://www.appserver.io
31
 */
32
trait StorageTrait
33
{
34
35
    /**
36
     * (non-PHPdoc)
37
     *
38
     * @return void
39
     * @see \AppserverIo\Storage\StorageInterface::flush()
40
     */
41
    public function flush()
42
    {
43
        if ($allKeys = $this->getAllKeys()) {
0 ignored issues
show
Bug introduced by
It seems like getAllKeys() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
            foreach ($allKeys as $key) {
45
                $this->remove($key);
0 ignored issues
show
Bug introduced by
It seems like remove() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
46
            }
47
        }
48
    }
49
50
    /**
51
     * (non-PHPdoc)
52
     *
53
     * @param string $tag The tag the entries must have
54
     *
55
     * @return void
56
     * @see \AppserverIo\Storage\StorageInterface::flushByTag()
57
     */
58
    public function flushByTag($tag)
59
    {
60
        $tagData = $this->get($tag);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
        if (is_array($tagData)) {
62
            foreach ($tagData as $cacheKey) {
63
                $this->remove($cacheKey);
0 ignored issues
show
Bug introduced by
It seems like remove() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
64
            }
65
            $this->remove($tag);
0 ignored issues
show
Bug introduced by
It seems like remove() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
66
        }
67
    }
68
69
    /**
70
     * (non-PHPdoc)
71
     *
72
     * @param string $tag A tag to be checked for validity
73
     *
74
     * @return boolean
75
     * @see \AppserverIo\Storage\StorageInterface::isValidTag()
76
     */
77
    public function isValidTag($tag)
78
    {
79
        return $this->isValidEntryIdentifier($tag);
80
    }
81
82
    /**
83
     * (non-PHPdoc)
84
     *
85
     * @param string $identifier An identifier to be checked for validity
86
     *
87
     * @return boolean
88
     * @see \AppserverIo\Storage\StorageInterface::isValidEntryIdentifier()
89
     */
90
    public function isValidEntryIdentifier($identifier)
91
    {
92
        if (preg_match('^[0-9A-Za-z_]+$', $identifier) === 1) {
93
            return true;
94
        }
95
        return false;
96
    }
97
}
98