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

lmc-eu / matej-client-php / 7536558481

15 Jan 2024 01:31PM UTC coverage: 100.0%. Remained the same
7536558481

push

github

OndraM
Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

712 of 712 relevant lines covered (100.0%)

35.03 hits per line

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

100.0
/src/RequestBuilder/SortingRequestBuilder.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\RequestBuilder;
4

5
use Fig\Http\Message\RequestMethodInterface;
6
use Lmc\Matej\Exception\LogicException;
7
use Lmc\Matej\Model\Command\Interaction;
8
use Lmc\Matej\Model\Command\ItemSorting;
9
use Lmc\Matej\Model\Command\UserMerge;
10
use Lmc\Matej\Model\Request;
11
use Lmc\Matej\Model\Response\SortingResponse;
12

13
/**
14
 * @method SortingResponse send()
15
 */
16
class SortingRequestBuilder extends AbstractRequestBuilder
17
{
18
    protected const ENDPOINT_PATH = '/sorting';
19

20
    /** @var Interaction|null */
21
    private $interactionCommand;
22
    /** @var UserMerge|null */
23
    private $userMergeCommand;
24
    /** @var ItemSorting */
25
    private $sortingCommand;
26

27
    public function __construct(ItemSorting $sortingCommand)
28
    {
29
        $this->sortingCommand = $sortingCommand;
49✔
30
    }
31

32
    /** @return $this */
33
    public function setUserMerge(UserMerge $merge): self
34
    {
35
        $this->userMergeCommand = $merge;
28✔
36

37
        return $this;
28✔
38
    }
39

40
    /** @return $this */
41
    public function setInteraction(Interaction $interaction): self
42
    {
43
        $this->interactionCommand = $interaction;
28✔
44

45
        return $this;
28✔
46
    }
47

48
    public function build(): Request
49
    {
50
        $this->assertInteractionUserId();
42✔
51
        $this->assertUserMergeUserId();
28✔
52

53
        // Build request
54
        return new Request(
21✔
55
            static::ENDPOINT_PATH,
21✔
56
            RequestMethodInterface::METHOD_POST,
21✔
57
            [$this->interactionCommand, $this->userMergeCommand, $this->sortingCommand],
21✔
58
            $this->requestId,
21✔
59
            SortingResponse::class
21✔
60
        );
21✔
61
    }
62

63
    /**
64
     * Assert that interaction user ids are ok:
65
     * - (A,  null,  A)
66
     * - (A, A -> ?, ?)
67
     */
68
    private function assertInteractionUserId(): void
69
    {
70
        if ($this->interactionCommand === null) {
42✔
71
            return;
14✔
72
        }
73

74
        $interactionUserId = $this->interactionCommand->getUserId();
28✔
75

76
        // (A, null, A)
77
        if ($this->userMergeCommand === null && $interactionUserId !== $this->sortingCommand->getUserId()) {
28✔
78
            throw LogicException::forInconsistentUserId($this->sortingCommand, $this->interactionCommand);
7✔
79
        }
80

81
        // (A, A -> ?, ?)
82
        if ($this->userMergeCommand !== null && $interactionUserId !== $this->userMergeCommand->getSourceUserId()) {
21✔
83
            throw LogicException::forInconsistentUserMergeAndInteractionCommand(
7✔
84
                $this->userMergeCommand->getSourceUserId(),
7✔
85
                $interactionUserId
7✔
86
            );
7✔
87
        }
88
    }
89

90
    /**
91
     * Assert user merge id is ok:
92
     * (?, ? -> A, A)
93
     */
94
    private function assertUserMergeUserId(): void
95
    {
96
        if ($this->userMergeCommand !== null
28✔
97
            && $this->userMergeCommand->getUserId() !== $this->sortingCommand->getUserId()) {
28✔
98
            throw LogicException::forInconsistentUserId($this->sortingCommand, $this->userMergeCommand);
7✔
99
        }
100
    }
101
}
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