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

GlobalContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A fromDocument() 0 4 1
A __toString() 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\Backend\Context;
11
12
use Railt\Reflection\Contracts\Definition\TypeDefinition;
13
use Railt\Reflection\Contracts\Document;
14
use Railt\SDL\Exception\TypeNotFoundException;
15
16
/**
17
 * Class GlobalContext
18
 */
19
class GlobalContext extends AbstractContext
20
{
21
    /**
22
     * @param string $type
23
     * @param array $variables
24
     * @return TypeDefinition
25
     * @throws TypeNotFoundException
26
     */
27
    public function get(string $type, array $variables = []): TypeDefinition
28
    {
29
        if ($this->has($type)) {
30
            return $this->types[$type]->make($variables);
31
        }
32
33
        throw new TypeNotFoundException(\sprintf('Type %s not found or could not be loaded', $type));
34
    }
35
36
    /**
37
     * @param Document $document
38
     * @return DocumentContext
39
     */
40
    public function fromDocument(Document $document): DocumentContext
41
    {
42
        return new DocumentContext($this, $document);
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function __toString(): string
49
    {
50
        return ':global';
51
    }
52
}
53