Completed
Push — develop ( 90d434...5a25e9 )
by Michael
02:38
created

AbstractAdapter::setMainframe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Crummy\Phlack\Bot\Mainframe\Adapter;
4
5
use Crummy\Phlack\Bot\BotInterface;
6
use Crummy\Phlack\Bot\Mainframe\Mainframe;
7
use Crummy\Phlack\Common\Matcher\MatcherInterface;
8
use Crummy\Phlack\WebHook\Converter\ConverterInterface;
9
use Crummy\Phlack\WebHook\Converter\StringConverter;
10
11
class AbstractAdapter implements AdapterInterface
12
{
13
    /** @var Mainframe */
14
    protected $mainframe;
15
16
    /** @var StringConverter|ConverterInterface */
17
    protected $converter;
18
19
    /**
20
     * @param Mainframe          $mainframe
21
     * @param ConverterInterface $converter
22
     */
23 6
    public function __construct(Mainframe $mainframe, ConverterInterface $converter = null)
24
    {
25 6
        $this->setMainframe($mainframe);
26 6
        $this->converter = $converter ?: new StringConverter();
27 6
    }
28
29
    /**
30
     * @param Mainframe $mainframe
31
     *
32
     * @return self
33
     */
34 6
    public function setMainframe(Mainframe $mainframe)
35
    {
36 6
        $this->mainframe = $mainframe;
37
38 6
        return $this;
39
    }
40
41
    /**
42
     * @return \Crummy\Phlack\WebHook\Converter\ConverterInterface
43
     */
44
    public function getConverter()
45
    {
46
        return $this->converter;
47
    }
48
49
    /**
50
     * @param BotInterface              $bot
51
     * @param MatcherInterface|callable $matcher
52
     * @param int                       $priority
53
     *
54
     * @return self
55
     */
56
    public function attach(BotInterface $bot, $matcher = null, $priority = 0)
57
    {
58
        $this->mainframe->attach($bot, $matcher, $priority);
59
60
        return $this;
61
    }
62
}
63