Passed
Push — master ( 1d0ea2...0f9d68 )
by Kacper
05:34
created

DelegateTokenFactory::setRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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