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

DelegateTokenFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 47
ccs 15
cts 18
cp 0.8333
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setType() 0 3 1
A setClass() 0 3 1
A setBase() 0 3 1
A setRule() 0 3 1
A __construct() 0 4 2
A create() 0 4 1
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