Passed
Push — master ( 6139d1...678a4c )
by Petr
13:22 queued 10:27
created

FilesSingleton   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 41
ccs 13
cts 15
cp 0.8667
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getFilesAccessor() 0 6 2
A setFileAccessor() 0 3 1
A getInstance() 0 6 2
A __clone() 0 2 1
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\File;
4
5
6
use kalanis\kw_files\Interfaces\IProcessFiles;
7
use kalanis\kw_mapper\MapperException;
8
9
10
/**
11
 * Class FilesSingleton
12
 * @package kalanis\kw_mapper\Storage\File
13
 * Singleton to access files across the mappers
14
 */
15
class FilesSingleton
16
{
17
    /** @var self|null */
18
    protected static $instance = null;
19
    /** @var IProcessFiles|null */
20
    private $filesAccessor = null;
21
22 8
    public static function getInstance(): self
23
    {
24 8
        if (empty(static::$instance)) {
25 1
            static::$instance = new self();
26
        }
27 8
        return static::$instance;
28
    }
29
30 1
    protected function __construct()
31
    {
32 1
    }
33
34
    /**
35
     * @codeCoverageIgnore why someone would run that?!
36
     */
37
    private function __clone()
38
    {
39
    }
40
41 7
    public function setFileAccessor(?IProcessFiles $files): void
42
    {
43 7
        $this->filesAccessor = $files;
44 7
    }
45
46
    /**
47
     * @throws MapperException
48
     * @return IProcessFiles
49
     */
50 7
    public function getFilesAccessor(): IProcessFiles
51
    {
52 7
        if (empty($this->filesAccessor)) {
53 1
            throw new MapperException('You must set the files accessor - instance of *IProcessFiles* - first!');
54
        }
55 6
        return $this->filesAccessor;
56
    }
57
}
58