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

Prefixer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A importable() 0 6 1
A resolvePath() 0 6 1
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
12
/**
13
 * Namespace importer provides ability to include multiple elements using common namespace prefix.
14
 *
15
 * Example: namespace:folder/* => namespace:folder/name
16
 */
17
class Prefixer implements ImporterInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $prefix = '';
23
24
    /**
25
     * @var string
26
     */
27
    private $target = '';
28
29
    /**
30
     * @param string $prefix
31
     * @param string $target
32
     */
33
    public function __construct($prefix, $target)
34
    {
35
        $this->prefix = $prefix;
36
        $this->target = $target;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function importable($element, array $token)
43
    {
44
        $element = strtolower($element);
45
46
        return strpos($element, $this->prefix) === 0;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function resolvePath($element, array $token)
53
    {
54
        $element = substr($element, strlen($this->prefix));
55
56
        return str_replace('*', str_replace('.', '/', $element), $this->target);
57
    }
58
}