AbstractStorage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A setDataDirectory() 0 10 2
1
<?php
2
/**
3
 * @author Serhii Nekhaienko <[email protected]>
4
 * @license GPL
5
 * @copyright Serhii Nekhaienko &copy 2018
6
 * @version 4.0.0
7
 * @project endorphin-studio/browser-detector
8
 */
9
10
namespace EndorphinStudio\Detector\Storage;
11
12
use EndorphinStudio\Detector\Exception\StorageException;
13
14
/**
15
 * Abstract storage of config
16
 * Class AbstractStorage
17
 * @package EndorphinStudio\Detector\Storage
18
 */
19
abstract class AbstractStorage implements StorageInterface
20
{
21
    /**
22
     * @var array List with config data
23
     */
24
    protected $config;
25
26
    /**
27
     * @var string Path to data directory
28
     */
29
    protected $dataDirectory;
30
31
    /**
32
     * Set data directory
33
     * @param string $directory
34
     * @throws StorageException
35
     */
36
    public function setDataDirectory(string $directory)
37
    {
38
        if (!is_dir($directory)) {
39
            $exception = new StorageException(sprintf(StorageException::DIRECTORY_NOT_FOUND, $directory));
40
            $exception->setDirectory($exception);
41
            $exception->setProvider(static::class);
42
            throw $exception;
43
        }
44
45
        $this->dataDirectory = $directory;
46
    }
47
48
    /**
49
     * Get array of data
50
     * @return array Data
51
     */
52
    public abstract function getConfig(): array;
53
}