Passed
Branch 4 (f3d551)
by Simon
03:46
created

SiteTreeExtension::updateCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Firesphere\GoogleAPI\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\ReadonlyField;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Class PageExtension
11
 *
12
 * @property \SilverStripe\CMS\Model\SiteTree|\Firesphere\GoogleAPI\Extensions\SiteTreeExtension $owner
13
 * @property int $VisitCount
14
 * @property string $LastAnalyticsUpdate
15
 */
16
class SiteTreeExtension extends DataExtension
17
{
18
    private static $db = [
19
        'VisitCount'          => 'Int',
20
        'LastAnalyticsUpdate' => 'Date'
21
    ];
22
23
    public function updateCMSFields(FieldList $fields)
24
    {
25
        if ($this->owner->LastAnalyticsUpdate) {
26
            $fields->addFieldToTab('Root.Analytics', ReadonlyField::create('VisitCount', 'Visit count'));
0 ignored issues
show
Bug introduced by
'VisitCount' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

26
            $fields->addFieldToTab('Root.Analytics', ReadonlyField::create(/** @scrutinizer ignore-type */ 'VisitCount', 'Visit count'));
Loading history...
27
            $fields->addFieldToTab('Root.Analytics', ReadonlyField::create('LastAnalyticsUpdate', 'Last update from Google'));
28
        } else {
29
            $fields->removeByName(array_keys(static::$db));
0 ignored issues
show
Bug introduced by
Since $db is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $db to at least protected.
Loading history...
30
        }
31
    }
32
}
33