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

ByebyeFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 31
loc 31
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createRequest() 19 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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