Passed
Branch master (0828fa)
by Gabor
03:19
created

StorageInjectorTrait::getApplicationStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Data\Traits;
15
16
use WebHemi\Data\StorageInterface;
17
use WebHemi\Data\Storage;
18
19
/**
20
 * Trait StorageTrait
21
 */
22
trait StorageInjectorTrait
23
{
24
    /** @var StorageInterface[] */
25
    protected $dataStorages = [];
26
27
    /**
28
     * Add Storage instances to internal library.
29
     *
30
     * @param StorageInterface[] ...$dataStorages
31
     */
32
    protected function addStorageInstances(array $dataStorages) : void
33
    {
34
        foreach ($dataStorages as $instance) {
35
            if ($instance instanceof StorageInterface) {
36
                $storageClass = get_class($instance);
37
38
                $this->dataStorages[$storageClass] = $instance;
39
            }
40
        }
41
    }
42
43
    /**
44
     * @return null|Storage\ApplicationStorage
45
     */
46
    protected function getApplicationStorage() : ? Storage\ApplicationStorage
47
    {
48
        return $this->dataStorages[Storage\ApplicationStorage::class] ?? null;
49
    }
50
51
    /**
52
     * @return null|Storage\Filesystem\FilesystemStorage
53
     */
54
    protected function getFilesystemStorage() : ? Storage\Filesystem\FilesystemStorage
55
    {
56
        return $this->dataStorages[Storage\Filesystem\FilesystemStorage::class] ?? null;
57
    }
58
59
    /**
60
     * @return null|Storage\Filesystem\FilesystemCategoryStorage
61
     */
62
    protected function getFilesystemCategoryStorage() : ? Storage\Filesystem\FilesystemCategoryStorage
63
    {
64
        return $this->dataStorages[Storage\Filesystem\FilesystemCategoryStorage::class] ?? null;
65
    }
66
67
    /**
68
     * @return null|Storage\Filesystem\FilesystemDirectoryStorage
69
     */
70
    protected function getFilesystemDirectoryStorage() : ? Storage\Filesystem\FilesystemDirectoryStorage
71
    {
72
        return $this->dataStorages[Storage\Filesystem\FilesystemDirectoryStorage::class] ?? null;
73
    }
74
75
    /**
76
     * @return null|Storage\Filesystem\FilesystemDocumentStorage
77
     */
78
    protected function getFilesystemDocumentStorage() : ? Storage\Filesystem\FilesystemDocumentStorage
79
    {
80
        return $this->dataStorages[Storage\Filesystem\FilesystemDocumentStorage::class] ?? null;
81
    }
82
83
    /**
84
     * @return null|Storage\Filesystem\FilesystemTagStorage
85
     */
86
    protected function getFilesystemTagStorage() : ? Storage\Filesystem\FilesystemTagStorage
87
    {
88
        return $this->dataStorages[Storage\Filesystem\FilesystemTagStorage::class] ?? null;
89
    }
90
91
    /**
92
     * @return null|Storage\User\UserStorage
93
     */
94
    protected function getUserStorage() : ? Storage\User\UserStorage
95
    {
96
        return $this->dataStorages[Storage\User\UserStorage::class] ?? null;
97
    }
98
99
    /**
100
     * @return null|Storage\User\UserMetaStorage
101
     */
102
    protected function getUserMetaStorage() : ? Storage\User\UserMetaStorage
103
    {
104
        return $this->dataStorages[Storage\User\UserMetaStorage::class] ?? null;
105
    }
106
}
107