Completed
Pull Request — master (#1)
by Raymond
02:20
created

buildRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %
Metric Value
dl 11
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace RayRutjes\GetEventStore\Client\Http;
4
5
use GuzzleHttp\Psr7\Request;
6
use Psr\Http\Message\RequestInterface;
7
use RayRutjes\GetEventStore\PersistentSubscriptionSettings;
8
use RayRutjes\GetEventStore\StreamId;
9
10 View Code Duplication
final class CreatePersistentSubscriptionRequestFactory implements RequestFactoryInterface
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...
11
{
12
    /**
13
     * @var StreamId
14
     */
15
    private $streamId;
16
17
    /**
18
     * @var string
19
     */
20
    private $groupName;
21
22
    /**
23
     * @var PersistentSubscriptionSettings
24
     */
25
    private $settings;
26
27
    /**
28
     * @param StreamId                       $streamId
29
     * @param string                         $groupName
30
     * @param PersistentSubscriptionSettings $settings
31
     */
32
    public function __construct(StreamId $streamId, string $groupName, PersistentSubscriptionSettings $settings)
33
    {
34
        $this->streamId = $streamId;
35
        $this->groupName = $groupName;
36
        $this->settings = $settings;
37
    }
38
39
    /**
40
     * @return RequestInterface
41
     */
42
    public function buildRequest(): RequestInterface
43
    {
44
        return new Request(
45
            'PUT',
46
            sprintf('subscriptions/%s/%s', $this->streamId->toString(), $this->groupName),
47
            [
48
                RequestHeader::CONTENT_TYPE => ContentType::JSON,
49
            ],
50
            json_encode($this->settings->toArray())
51
        );
52
    }
53
}
54