Completed
Pull Request — master (#1)
by Bogdan
06:53 queued 03:12
created

SourceModulesRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 27
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 4 1
A get() 0 8 2
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Modules\Repositories;
17
18
19
use League\Flysystem\FilesystemInterface;
20
use Pinepain\JsSandbox\Modules\SourceModuleBuilder;
21
use Pinepain\JsSandbox\Modules\SourceModuleBuilderInterface;
22
use UnexpectedValueException;
23
24
25
class SourceModulesRepository implements SourceModulesRepositoryInterface
26
{
27
    /**
28
     * @var FilesystemInterface
29
     */
30
    private $filesystem;
31
32
33
    public function __construct(FilesystemInterface $filesystem)
34
    {
35
        $this->filesystem = $filesystem;
36
    }
37
38
    public function has(string $id): bool
39
    {
40
        return $this->filesystem->has($id);
41
    }
42
43
    public function get(string $id): SourceModuleBuilderInterface
44
    {
45
        if (!$this->has($id)) {
46
            throw new UnexpectedValueException('Source module not found');
47
        }
48
49
        return new SourceModuleBuilder($this->filesystem);
50
    }
51
}
52