Code Duplication    Length = 44-44 lines in 2 locations

src/Client/Http/CreatePersistentSubscriptionRequestFactory.php 1 location

@@ 10-53 (lines=44) @@
7
use RayRutjes\GetEventStore\PersistentSubscriptionSettings;
8
use RayRutjes\GetEventStore\StreamId;
9
10
final class CreatePersistentSubscriptionRequestFactory implements RequestFactoryInterface
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

src/Client/Http/UpdatePersistentSubscriptionRequestFactory.php 1 location

@@ 10-53 (lines=44) @@
7
use RayRutjes\GetEventStore\PersistentSubscriptionSettings;
8
use RayRutjes\GetEventStore\StreamId;
9
10
final class UpdatePersistentSubscriptionRequestFactory implements RequestFactoryInterface
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
            'POST',
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