Completed
Push — master ( dac7df...b079db )
by Daniel
03:09
created

ByebyeFactory::createRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
ccs 0
cts 12
cp 0
rs 9.4285
cc 3
eloc 13
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * This file is part of the Ssdp project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Ssdp\Request\Factory;
9
10
use GravityMedia\Ssdp\Options\ByebyeOptions;
11
use GravityMedia\Ssdp\Request\NotifyRequest;
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * Byebye request factory class
16
 *
17
 * @package GravityMedia\Ssdp\Request\Factory
18
 */
19 View Code Duplication
class ByebyeFactory implements FactoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * Create byebye request object
23
     *
24
     * @param ByebyeOptions $options
25
     *
26
     * @throws \RuntimeException
27
     *
28
     * @return RequestInterface
29
     */
30
    public function createRequest($options)
31
    {
32
        if (!$options instanceof ByebyeOptions) {
33
            throw new \RuntimeException('Options must be instance of ' . ByebyeOptions::class);
34
        }
35
36
        if (null === $options->getUniqueServiceName()) {
37
            throw new \RuntimeException('Unique service name not specified.');
38
        }
39
40
        $request = new NotifyRequest();
41
        return $request
42
            ->withRequestTarget('*')
43
            ->withProtocolVersion('1.1')
44
            ->withHeader('HOST', (string)$request->getUri())
45
            ->withHeader('NT', (string)$options->getNotificationType())
46
            ->withHeader('NTS', '"ssdp:byebye"')
47
            ->withHeader('USN', (string)$options->getUniqueServiceName());
48
    }
49
}
50