Passed
Push — develop ( 762d9d...ba9baa )
by Andrew
09:55
created

ApiController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionGetRedirects() 0 5 1
A beforeAction() 0 7 2
1
<?php
2
/**
3
 * Retour plugin for Craft CMS 3.x
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2018 nystudio107
10
 */
11
12
namespace nystudio107\retour\controllers;
13
14
use nystudio107\retour\Retour;
15
use craft\web\Controller;
16
17
/**
18
 * @author    nystudio107
19
 * @package   Retour
20
 * @since     3.1.39
21
 */
22
class ApiController extends Controller
23
{
24
    // Constants
25
    // =========================================================================
26
27
    // Protected Properties
28
    // =========================================================================
29
30
    /**
31
     * @inheritdoc
32
     */
33
    protected $allowAnonymous = [
34
        'get-redirects',
35
    ];
36
37
    // Public Methods
38
    // =========================================================================
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function beforeAction($action)
44
    {
45
        if (!Retour::$settings->enableApiEndpoint) {
46
            $this->allowAnonymous = false;
47
        }
48
49
        return parent::beforeAction($action);
50
    }
51
52
    /**
53
     * @param null $siteId
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $siteId is correct as it would always require null to be passed?
Loading history...
54
     * @return \yii\web\Response
55
     */
56
    public function actionGetRedirects($siteId = null)
57
    {
58
        $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId);
59
60
        return $this->asJson($redirects ?? []);
61
    }
62
}
63