Completed
Push — master ( 29545d...bdb788 )
by Kacper
04:24
created

DelegateTokenFactory::setOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Parser;
17
18
19
use Kadet\Highlighter\Parser\Token\Token;
20
21
class DelegateTokenFactory implements TokenFactoryInterface
22
{
23
    private $_callable;
24
    private $_factory;
25
26
    /**
27
     * DelegateTokenFactory constructor.
28
     *
29
     * @param callable (TokenFactoryInterface $factory, array $params) $function
30
     * @param TokenFactoryInterface|null                               $factory
31
     */
32 2
    public function __construct(callable $function, TokenFactoryInterface $factory = null) {
33 2
        $this->_factory  = $factory ?: new TokenFactory(Token::class);
34 2
        $this->_callable = $function;
35 2
    }
36
37
    /**
38
     * @param       $name
39
     * @param array $params
40
     *
41
     * @return Token|null
42
     */
43 1
    public function create($name, $params = [])
44
    {
45 1
        $callable = $this->_callable;
46 1
        return $callable($this->_factory, $params);
47
    }
48
49 1
    public function setRule($rule)
50
    {
51 1
        $this->_factory->setRule($rule);
52 1
    }
53
54 1
    public function setClass($class)
55
    {
56 1
        $this->_factory->setClass($class);
57 1
    }
58
59 1
    public function setBase($base)
60
    {
61 1
        $this->_factory->setBase($base);
62 1
    }
63
64 1
    public function setType($type)
65
    {
66 1
        $this->_factory->setType($type);
67 1
    }
68
}
69