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

UpdateFactory::createRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
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 20
loc 20
ccs 0
cts 13
cp 0
rs 9.4285
cc 3
eloc 14
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\UpdateOptions;
11
use GravityMedia\Ssdp\Request\NotifyRequest;
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * Update request factory class
16
 *
17
 * @package GravityMedia\Ssdp\Request\Factory
18
 */
19 View Code Duplication
class UpdateFactory 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 update request object
23
     *
24
     * @param UpdateOptions $options
25
     *
26
     * @throws \RuntimeException
27
     *
28
     * @return RequestInterface
29
     */
30
    public function createRequest($options)
31
    {
32
        if (!$options instanceof UpdateOptions) {
33
            throw new \RuntimeException('Options must be instance of ' . UpdateOptions::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('LOCATION', (string)$options->getDescriptionUrl())
46
            ->withHeader('NT', (string)$options->getNotificationType())
47
            ->withHeader('NTS', '"ssdp:update"')
48
            ->withHeader('USN', (string)$options->getUniqueServiceName());
49
    }
50
}
51