Code Duplication    Length = 26-27 lines in 2 locations

src/DB.php 2 locations

@@ 179-204 (lines=26) @@
176
     * @return array|bool Fetched data or false if not connected
177
     * @throws \Longman\TelegramBot\Exception\TelegramException
178
     */
179
    public static function selectTelegramUpdate($limit = null)
180
    {
181
        if (!self::isDbConnected()) {
182
            return false;
183
        }
184
185
        try {
186
            $sql = '
187
                SELECT `id`
188
                FROM `' . TB_TELEGRAM_UPDATE . '`
189
                ORDER BY `id` DESC
190
            ';
191
192
            if ($limit !== null) {
193
                $sql .= 'LIMIT :limit';
194
            }
195
196
            $sth = self::$pdo->prepare($sql);
197
            $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
198
            $sth->execute();
199
200
            return $sth->fetchAll(PDO::FETCH_ASSOC);
201
        } catch (PDOException $e) {
202
            throw new TelegramException($e->getMessage());
203
        }
204
    }
205
206
    /**
207
     * Fetch message(s) from DB
@@ 214-240 (lines=27) @@
211
     * @return array|bool Fetched data or false if not connected
212
     * @throws \Longman\TelegramBot\Exception\TelegramException
213
     */
214
    public static function selectMessages($limit = null)
215
    {
216
        if (!self::isDbConnected()) {
217
            return false;
218
        }
219
220
        try {
221
            $sql = '
222
                SELECT *
223
                FROM `' . TB_MESSAGE . '`
224
                WHERE `update_id` != 0
225
                ORDER BY `message_id` DESC
226
            ';
227
228
            if ($limit !== null) {
229
                $sql .= 'LIMIT :limit';
230
            }
231
232
            $sth = self::$pdo->prepare($sql);
233
            $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
234
            $sth->execute();
235
236
            return $sth->fetchAll(PDO::FETCH_ASSOC);
237
        } catch (PDOException $e) {
238
            throw new TelegramException($e->getMessage());
239
        }
240
    }
241
242
    /**
243
     * Convert from unix timestamp to timestamp