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

FilesSingleton::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
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