RegistryImportFeedController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unsanitiseClassName() 0 3 1
A latest() 0 11 3
1
<?php
2
3
namespace SilverStripe\Registry;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\ORM\FieldType\DBHTMLText;
8
use SilverStripe\Registry\RegistryDataInterface;
9
10
class RegistryImportFeedController extends Controller
11
{
12
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
13
        'latest',
14
    ];
15
16
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
17
        '$Action/$ModelClass' => 'handleAction',
18
    ];
19
20
    /**
21
     * Get an RSS feed of the latest data imports that were made for this registry model. This will only
22
     * return a valid result for classes that exist and implement the {@link RegistryDataInterface} interface.
23
     *
24
     * @param HTTPRequest $request
25
     * @return DBHTMLText
26
     */
27
    public function latest($request)
28
    {
29
        $feed = RegistryImportFeed::create();
30
        $modelClass = $this->unsanitiseClassName($request->param('ModelClass'));
31
32
        if (!class_exists($modelClass) || !(singleton($modelClass) instanceof RegistryDataInterface)) {
33
            return $this->httpError(404);
34
        }
35
36
        $feed->setModelClass($modelClass);
37
        return $feed->getLatest()->outputToBrowser();
38
    }
39
40
    /**
41
     * See {@link \SilverStripe\Admin\ModelAdmin::unsanitiseClassName}
42
     */
43
    protected function unsanitiseClassName($class)
44
    {
45
        return str_replace('-', '\\', $class);
46
    }
47
}
48