GoogleShoppingFeedController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
3
namespace Sunnysideup\EcommerceGoogleShoppingFeed\Controllers;
4
5
use SilverStripe\Control\ContentNegotiator;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Core\ClassInfo;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\View\SSViewer;
10
use Sunnysideup\EcommerceGoogleShoppingFeed\Api\ProductCollectionForGoogleShoppingFeed;
11
12
/**
13
 * Controller for displaying the xml feed.
14
 *
15
 * <code>
16
 * http://site.com/shoppingfeed.xml
17
 * </code>
18
 *
19
 */
20
class GoogleShoppingFeedController extends Controller
21
{
22
    /**
23
     * @var array
24
     */
25
    private static $allowed_actions = [
26
        'index',
27
    ];
28
29
    private static $api_class = ProductCollectionForGoogleShoppingFeed::class;
30
31
    /**
32
     * Specific controller action for displaying a particular list of links
33
     * for a class.
34
     *
35
     * @return mixed
36
     */
37
    public function index()
38
    {
39
        Config::modify()->set(SSViewer::class, 'set_source_file_comments', false);
40
        Config::modify()->set(ContentNegotiator::class, 'enabled', false);
41
        // response header
42
        $header = $this->getResponse();
43
        $header->addHeader('Pragma', 'no-cache');
44
        $header->addHeader('Expires', 0);
45
        $header->addHeader('Content-Type', $this->getContentType());
0 ignored issues
show
Bug introduced by
The method getContentType() does not exist on Sunnysideup\EcommerceGoo...eShoppingFeedController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $header->addHeader('Content-Type', $this->/** @scrutinizer ignore-call */ getContentType());
Loading history...
46
        $header->addHeader('Content-Disposition', 'attachment; filename=' . $this->getFilename());
47
        $header->addHeader('X-Robots-Tag', 'noindex');
48
49
        return $this->renderWith(ClassInfo::shortName(static::class));
50
    }
51
52
    protected function getFileName(): string
53
    {
54
        return 'shoppingfeed.' . $this->getExtension();
0 ignored issues
show
Bug introduced by
The method getExtension() does not exist on Sunnysideup\EcommerceGoo...eShoppingFeedController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        return 'shoppingfeed.' . $this->/** @scrutinizer ignore-call */ getExtension();
Loading history...
55
    }
56
}
57