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

DiscoverFactory::createRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
crap 6
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\DiscoverOptions;
11
use GravityMedia\Ssdp\Request\SearchRequest;
12
use Psr\Http\Message\RequestInterface;
13
14
/**
15
 * Discover request factory class
16
 *
17
 * @package GravityMedia\Ssdp\Request\Factory
18
 */
19
class DiscoverFactory implements FactoryInterface
20
{
21
    /**
22
     * Create discover request object
23
     *
24
     * @param DiscoverOptions $options
25
     *
26
     * @throws \RuntimeException
27
     *
28
     * @return RequestInterface
29
     */
30
    public function createRequest($options)
31
    {
32
        if (!$options instanceof DiscoverOptions) {
33
            throw new \RuntimeException('Options must be instance of ' . DiscoverOptions::class);
34
        }
35
36
        $request = new SearchRequest();
37
        return $request
38
            ->withRequestTarget('*')
39
            ->withProtocolVersion('1.1')
40
            ->withHeader('HOST', (string)$request->getUri())
41
            ->withHeader('MAN', '"ssdp:discover"')
42
            ->withHeader('MX', (string)$options->getMaximumWaitTime())
43
            ->withHeader('ST', (string)$options->getSearchTarget());
44
    }
45
}
46