Code Duplication    Length = 19-19 lines in 2 locations

src/Resources/Messages.php 2 locations

@@ 60-78 (lines=19) @@
57
     * @throws \InvalidArgumentException
58
     * @throws \Throwable
59
     */
60
    public function allBeforeId(string $roomId, string $beforeId = null, string $query = null)
61
    {
62
        $limit = 100;
63
        $route = $this->routeForMessagesIterator($roomId, $limit, $query);
64
65
        do {
66
            if ($beforeId !== null) {
67
                $route->with('beforeId', $beforeId);
68
            }
69
70
            $response = \array_reverse($this->fetch($route));
71
72
            foreach ($response as $message) {
73
                yield $message;
74
            }
75
76
            $beforeId = \count($response) > 0 ? \end($response)['id'] : null;
77
        } while (\count($response) >= $limit);
78
    }
79
80
    /**
81
     * @param string $roomId
@@ 110-128 (lines=19) @@
107
     * @throws \InvalidArgumentException
108
     * @throws \Throwable
109
     */
110
    public function allAfterId(string $roomId, string $afterId = null, string $query = null)
111
    {
112
        $limit = 100;
113
        $route = $this->routeForMessagesIterator($roomId, $limit, $query);
114
115
        do {
116
            if ($afterId !== null) {
117
                $route->with('afterId', $afterId);
118
            }
119
120
            $response = (array)$this->fetch($route);
121
122
            foreach ($response as $message) {
123
                yield $message;
124
            }
125
126
            $afterId = \count($response) > 0 ? end($response)['id'] : null;
127
        } while (\count($response) >= $limit);
128
    }
129
130
    /**
131
     * There is also a way to retrieve a single message using its id.