Completed
Branch dbal-improvement (06db1a)
by Anton
03:59
created

Bundler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A importable() 0 10 3
A resolvePath() 0 10 3
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Stempler\Importers;
9
10
use Spiral\Stempler\ImporterInterface;
11
use Spiral\Stempler\Supervisor;
12
13
/**
14
 * Share all template importers with given supervisor.
15
 */
16
class Bundler implements ImporterInterface
17
{
18
    /**
19
     * Importers fetched from bundle file.
20
     *
21
     * @var ImporterInterface[]
22
     */
23
    protected $importers = [];
24
25
    /**
26
     * @param Supervisor $supervisor
27
     * @param string     $path
28
     * @param array      $token
29
     */
30
    public function __construct(Supervisor $supervisor, $path, array $token = [])
31
    {
32
        $node = $supervisor->createNode($path, $token);
33
        $supervisor = $node->supervisor();
34
35
        if ($supervisor instanceof Supervisor) {
36
            $this->importers = $supervisor->getImporters();
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function importable($element, array $token)
44
    {
45
        foreach ($this->importers as $importer) {
46
            if ($importer->importable($element, $token)) {
47
                return true;
48
            }
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function resolvePath($element, array $token)
58
    {
59
        foreach ($this->importers as $importer) {
60
            if ($importer->importable($element, $token)) {
61
                return $importer->resolvePath($element, $token);
62
            }
63
        }
64
65
        return null;
66
    }
67
}