Passed
Push — master ( 5d8af1...e44bd6 )
by Petr
09:24
created

FilesSingleton   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 39
ccs 12
cts 12
cp 1
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
    protected static ?FilesSingleton $instance = null;
18
    private ?IProcessFiles $filesAccessor = null;
19
20 8
    public static function getInstance(): self
21
    {
22 8
        if (empty(static::$instance)) {
23 1
            static::$instance = new self();
24
        }
25 8
        return static::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::instance could return the type null which is incompatible with the type-hinted return kalanis\kw_mapper\Storage\File\FilesSingleton. Consider adding an additional type-check to rule them out.
Loading history...
26
    }
27
28 1
    protected function __construct()
29
    {
30 1
    }
31
32
    /**
33
     * @codeCoverageIgnore why someone would run that?!
34
     */
35
    private function __clone()
36
    {
37
    }
38
39 7
    public function setFileAccessor(?IProcessFiles $files): void
40
    {
41 7
        $this->filesAccessor = $files;
42
    }
43
44
    /**
45
     * @throws MapperException
46
     * @return IProcessFiles
47
     */
48 7
    public function getFilesAccessor(): IProcessFiles
49
    {
50 7
        if (empty($this->filesAccessor)) {
51 1
            throw new MapperException('You must set the files accessor - instance of *IProcessFiles* - first!');
52
        }
53 6
        return $this->filesAccessor;
54
    }
55
}
56