Passed
Push — master ( 454cf7...0d52c3 )
by Kacper
02:57
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 $params
39
     *
40
     * @return Token|null
41
     */
42 1
    public function create($params)
43
    {
44 1
        $callable = $this->_callable;
45 1
        return $callable($this->_factory, $params);
46
    }
47
48 1
    public function setRule($rule)
49
    {
50 1
        $this->_factory->setRule($rule);
51 1
    }
52
53 1
    public function setClass($class)
54
    {
55 1
        $this->_factory->setClass($class);
56 1
    }
57
58 1
    public function setBase($base)
59
    {
60 1
        $this->_factory->setBase($base);
61 1
    }
62
63 1
    public function setOffset($offset)
64
    {
65 1
        $this->_factory->setOffset($offset);
66 1
    }
67
68 1
    public function setType($type)
69
    {
70 1
        $this->_factory->setType($type);
71
    }
72
}