Code Duplication    Length = 28-28 lines in 2 locations

common/models/Post.php 2 locations

@@ 304-331 (lines=28) @@
301
     * @param bool $sameTerm
302
     * @return array|null|Post
303
     */
304
    public function getNextPost($sameType = true, $sameTerm = false)
305
    {
306
        /* @var $query \yii\db\ActiveQuery */
307
        $query = static::find()
308
            ->from(['post' => $this->tableName()])
309
            ->andWhere(['>', 'post.id', $this->id])
310
            ->andWhere(['status' => 'publish'])
311
            ->orderBy(['post.id' => SORT_ASC]);
312
313
        if ($sameType) {
314
            $query->andWhere(['type' => $this->type]);
315
        }
316
317
        if ($sameTerm) {
318
            $query->innerJoinWith([
319
                'terms' => function ($query) {
320
                    /* @var $query \yii\db\ActiveQuery */
321
                    $query->from(['term' => Term::tableName()])->andWhere([
322
                        'IN',
323
                        'term.id',
324
                        implode(',', ArrayHelper::getColumn($this->terms, 'id')),
325
                    ]);
326
                },
327
            ]);
328
        }
329
330
        return $query->one();
331
    }
332
333
    /**
334
     * @param bool $sameType
@@ 360-387 (lines=28) @@
357
     * @param bool $sameTerm
358
     * @return array|null|Post
359
     */
360
    public function getPrevPost($sameType = true, $sameTerm = false)
361
    {
362
        /* @var $query \yii\db\ActiveQuery */
363
        $query = static::find()
364
            ->from(['post' => $this->tableName()])
365
            ->andWhere(['<', 'post.id', $this->id])
366
            ->andWhere(['status' => 'publish'])
367
            ->orderBy(['post.id' => SORT_DESC]);
368
369
        if ($sameType) {
370
            $query->andWhere(['type' => $this->type]);
371
        }
372
373
        if ($sameTerm) {
374
            $query->innerJoinWith([
375
                'terms' => function ($query) {
376
                    /* @var $query \yii\db\ActiveQuery */
377
                    $query->from(['term' => Term::tableName()])->andWhere([
378
                        'IN',
379
                        'term.id',
380
                        implode(',', ArrayHelper::getColumn($this->terms, 'id')),
381
                    ]);
382
                },
383
            ]);
384
        }
385
386
        return $query->one();
387
    }
388
389
    /**
390
     * @param bool $sameType