Completed
Pull Request — develop (#33)
by Michael
02:17
created

Packet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 76.47%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 5
c 4
b 2
f 0
lcom 0
cbo 2
dl 0
loc 43
ccs 13
cts 17
cp 0.7647
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 4 2
A __toString() 0 4 1
A __construct() 0 7 1
A setDefaultOptions() 0 10 1
1
<?php
2
3
namespace Crummy\Phlack\Bot\Mainframe;
4
5
use Crummy\Phlack\Common\Encodable;
6
use Crummy\Phlack\Common\Event;
7
use Crummy\Phlack\Common\OptionsResolver;
8
9
class Packet extends Event implements Encodable
10
{
11
    /**
12
     * @param array $options
13
     */
14 1
    public function __construct(array $options = [])
15
    {
16 1
        $resolver = new OptionsResolver();
17 1
        $this->setDefaultOptions($resolver);
18
19 1
        parent::__construct($resolver->resolve($options));
20 1
    }
21
22
    /**
23
     * @param OptionsResolver $resolver
24
     */
25 1
    protected function setDefaultOptions(OptionsResolver $resolver)
26
    {
27 1
        $resolver->setRequired(['command']);
28 1
        $resolver->setDefaults(['output' => null]);
29
30 1
        $resolver->setTypesAllowed([
31 1
            'command' => '\Crummy\Phlack\WebHook\CommandInterface',
32 1
            'output'  => ['\Crummy\Phlack\WebHook\Reply\Reply', 'null'],
33 1
        ]);
34 1
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function jsonSerialize()
40
    {
41
        return $this['output'] instanceof Encodable ? $this['output']->jsonSerialize() : $this['output'];
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function __toString()
48
    {
49
        return json_encode($this);
50
    }
51
}
52