SitewideContentSubsites   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateRowAttributes() 0 3 1
A updateColumns() 0 26 6
1
<?php
2
3
namespace SilverStripe\SiteWideContentReport\Model;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\Subsites\Model\Subsite;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Subsites\Model\Subsite was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * Provides subsite integration for sitewide content report.
10
 *
11
 * Requires https://github.com/silverstripe/silverstripe-subsites
12
 *
13
 * Class SitewideContentSubsites
14
 * @package SilverStripe\SiteWideContentReport\Model
15
 */
16
class SitewideContentSubsites extends Extension
17
{
18
    /**
19
     * Update columns to include subsite details.
20
     *
21
     * @param string $itemType (i.e 'Pages' or 'Files')
22
     * @param array  $columns  Columns
23
     */
24
    public function updateColumns($itemType, &$columns)
25
    {
26
        // Skip single subsite setups
27
        if (!Subsite::get()->count()) {
28
            return;
29
        }
30
31
        // Set title
32
        $mainSiteLabel = _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.MainSite', 'Main Site');
33
        if ($itemType !== 'Pages') {
34
            $mainSiteLabel .= ' '._t(
35
                'SilverStripe\\SiteWideContentReport\\SitewideContentReport.AccessFromAllSubsites',
36
                '(accessible by all subsites)'
37
            );
38
        }
39
40
        // Add subsite name
41
        $columns['SubsiteName'] = [
42
            'title' => _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.Subsite', 'Subsite'),
43
            'datasource' => function ($item) use ($mainSiteLabel) {
44
                $subsite = $item->Subsite();
45
46
                if ($subsite && $subsite->exists() && $subsite->Title) {
47
                    return $subsite->Title;
48
                } else {
49
                    return $mainSiteLabel;
50
                }
51
            },
52
        ];
53
    }
54
55
    /**
56
     * @param $total
57
     * @param $index
58
     * @param $record
59
     * @param $attributes
60
     */
61
    public function updateRowAttributes($total, $index, $record, &$attributes)
0 ignored issues
show
Unused Code introduced by
The parameter $total is not used and could be removed. ( Ignorable by Annotation )

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

61
    public function updateRowAttributes(/** @scrutinizer ignore-unused */ $total, $index, $record, &$attributes)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $index is not used and could be removed. ( Ignorable by Annotation )

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

61
    public function updateRowAttributes($total, /** @scrutinizer ignore-unused */ $index, $record, &$attributes)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        $attributes['data-subsite-id'] = $record->SubsiteID;
64
    }
65
}
66