Test Failed
Push — master ( 6bac61...6350a6 )
by Kirill
03:02
created

Store   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A memoize() 0 8 2
A has() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
use Railt\Io\Readable;
13
use Railt\Reflection\Contracts\Document;
14
15
/**
16
 * Class Store
17
 */
18
class Store
19
{
20
    /**
21
     * @var array|Document[]
22
     */
23
    private $documents = [];
24
25
    /**
26
     * @param Readable $file
27
     * @param \Closure $otherwise
28
     * @return Document
29
     */
30
    public function memoize(Readable $file, \Closure $otherwise): Document
31
    {
32
        if ($this->has($file)) {
33
            return $this->documents[$file->getHash()];
34
        }
35
36
        return $this->documents[$file->getHash()] = $otherwise($file);
37
    }
38
39
    /**
40
     * @param Readable $file
41
     * @return bool
42
     */
43
    public function has(Readable $file): bool
44
    {
45
        return isset($this->documents[$file->getHash()]);
46
    }
47
}
48