• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prooph / event-store-client / 9555551525

17 Jun 2024 10:16PM UTC coverage: 70.262% (-1.1%) from 71.395%
9555551525

push

github

prolic
update coveralls repo token

3466 of 4933 relevant lines covered (70.26%)

67.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/ClientOperations/DeleteStreamOperation.php
1
<?php
2

3
/**
4
 * This file is part of `prooph/event-store-client`.
5
 * (c) 2018-2024 Alexander Miertsch <kontakt@codeliner.ws>
6
 * (c) 2018-2024 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Prooph\EventStoreClient\ClientOperations;
15

16
use Amp\DeferredFuture;
17
use Google\Protobuf\Internal\Message;
18
use Prooph\EventStore\DeleteResult;
19
use Prooph\EventStore\Exception\AccessDenied;
20
use Prooph\EventStore\Exception\InvalidTransaction;
21
use Prooph\EventStore\Exception\StreamDeleted;
22
use Prooph\EventStore\Exception\UnexpectedOperationResult;
23
use Prooph\EventStore\Exception\WrongExpectedVersion;
24
use Prooph\EventStore\Position;
25
use Prooph\EventStore\UserCredentials;
26
use Prooph\EventStoreClient\Messages\ClientMessages\DeleteStream;
27
use Prooph\EventStoreClient\Messages\ClientMessages\DeleteStreamCompleted;
28
use Prooph\EventStoreClient\Messages\ClientMessages\OperationResult;
29
use Prooph\EventStoreClient\SystemData\InspectionDecision;
30
use Prooph\EventStoreClient\SystemData\InspectionResult;
31
use Prooph\EventStoreClient\SystemData\TcpCommand;
32
use Psr\Log\LoggerInterface as Logger;
33

34
/**
35
 * @internal
36
 * @extends AbstractOperation<DeleteStreamCompleted, DeleteResult>
37
 */
38
class DeleteStreamOperation extends AbstractOperation
39
{
40
    public function __construct(
41
        Logger $logger,
42
        DeferredFuture $deferred,
43
        private readonly bool $requireMaster,
44
        private readonly string $stream,
45
        private readonly int $expectedVersion,
46
        private readonly bool $hardDelete,
47
        ?UserCredentials $userCredentials
48
    ) {
49
        parent::__construct(
92✔
50
            $logger,
92✔
51
            $deferred,
92✔
52
            $userCredentials,
92✔
53
            TcpCommand::DeleteStream,
92✔
54
            TcpCommand::DeleteStreamCompleted,
92✔
55
            DeleteStreamCompleted::class
92✔
56
        );
92✔
57
    }
58

59
    protected function createRequestDto(): Message
60
    {
61
        $message = new DeleteStream();
91✔
62
        $message->setEventStreamId($this->stream);
91✔
63
        $message->setExpectedVersion($this->expectedVersion);
91✔
64
        $message->setHardDelete($this->hardDelete);
91✔
65
        $message->setRequireMaster($this->requireMaster);
91✔
66

67
        return $message;
91✔
68
    }
69

70
    /**
71
     * @param DeleteStreamCompleted $response
72
     * @return InspectionResult
73
     */
74
    public function inspectResponse(Message $response): InspectionResult
75
    {
76
        switch ($response->getResult()) {
91✔
77
            case OperationResult::Success:
78
                $this->succeed($response);
78✔
79

80
                return new InspectionResult(InspectionDecision::EndOperation, 'Success');
78✔
81
            case OperationResult::PrepareTimeout:
82
                return new InspectionResult(InspectionDecision::Retry, 'PrepareTimeout');
×
83
            case OperationResult::CommitTimeout:
84
                return new InspectionResult(InspectionDecision::Retry, 'CommitTimeout');
×
85
            case OperationResult::ForwardTimeout:
86
                return new InspectionResult(InspectionDecision::Retry, 'ForwardTimeout');
×
87
            case OperationResult::WrongExpectedVersion:
88
                $this->fail(WrongExpectedVersion::with(
1✔
89
                    $this->stream,
1✔
90
                    $this->expectedVersion
1✔
91
                ));
1✔
92

93
                return new InspectionResult(InspectionDecision::EndOperation, 'WrongExpectedVersion');
1✔
94
            case OperationResult::StreamDeleted:
95
                $exception = StreamDeleted::with($this->stream);
1✔
96
                $this->fail($exception);
1✔
97

98
                return new InspectionResult(InspectionDecision::EndOperation, 'StreamDeleted');
1✔
99
            case OperationResult::InvalidTransaction:
100
                $exception = new InvalidTransaction();
×
101
                $this->fail($exception);
×
102

103
                return new InspectionResult(InspectionDecision::EndOperation, 'InvalidTransaction');
×
104
            case OperationResult::AccessDenied:
105
                $exception = AccessDenied::toStream($this->stream);
12✔
106
                $this->fail($exception);
12✔
107

108
                return new InspectionResult(InspectionDecision::EndOperation, 'AccessDenied');
12✔
109
            default:
110
                throw new UnexpectedOperationResult();
×
111
        }
112
    }
113

114
    /**
115
     * @param DeleteStreamCompleted $response
116
     * @return DeleteResult
117
     */
118
    protected function transformResponse(Message $response): DeleteResult
119
    {
120
        /** @psalm-suppress DocblockTypeContradiction */
121
        return new DeleteResult(
78✔
122
            new Position(
78✔
123
                (int) ($response->getCommitPosition() ?? -1),
78✔
124
                (int) ($response->getCommitPosition() ?? -1)
78✔
125
            )
78✔
126
        );
78✔
127
    }
128

129
    public function name(): string
130
    {
131
        return 'DeleteStream';
91✔
132
    }
133

134
    public function __toString(): string
135
    {
136
        return \sprintf(
91✔
137
            'Stream: %s, ExpectedVersion: %d, RequireMaster: %s, HardDelete: %s',
91✔
138
            $this->stream,
91✔
139
            $this->expectedVersion,
91✔
140
            $this->requireMaster ? 'yes' : 'no',
91✔
141
            $this->hardDelete ? 'yes' : 'no'
91✔
142
        );
91✔
143
    }
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc