Passed
Push — 4 ( eae0ff...3ed7c8 )
by Steve
64:51 queued 12s
created

FluentExtension::assignFixedTopPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\Elemental\TopPage;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use DNADesign\Elemental\Models\ElementalArea;
7
use Page;
0 ignored issues
show
Bug introduced by
The type Page 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...
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\ORM\Queries\SQLUpdate;
10
use TractorCow\Fluent\State\FluentState;
0 ignored issues
show
Bug introduced by
The type TractorCow\Fluent\State\FluentState 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...
11
12
/**
13
 * Class FluentExtension
14
 *
15
 * Use in place of @see DataExtension if you use the Fluent module for page localisation.
16
 * Be sure to also update @see TestState to use this extension
17
 *
18
 * @link https://github.com/tractorcow-farm/silverstripe-fluent
19
 * @property string $TopPageLocale
20
 * @property BaseElement|ElementalArea|$this $owner
21
 * @package DNADesign\Elemental\TopPage
22
 */
23
class FluentExtension extends DataExtension
24
{
25
    /**
26
     * @var array
27
     */
28
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
29
        'TopPageLocale' => 'Varchar',
30
    ];
31
32
    /*
33
     * @inheritdoc
34
     */
35
    protected function assignTopPage(Page $page): void
36
    {
37
        parent::assignTopPage($page);
38
39
        $this->owner->TopPageLocale = FluentState::singleton()->getLocale();
0 ignored issues
show
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\BaseElement. Since you implemented __set, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\ElementalArea. Since you implemented __set, consider adding a @property annotation.
Loading history...
40
    }
41
42
    /*
43
     * @inheritdoc
44
     */
45
    protected function clearTopPage(): void
46
    {
47
        parent::clearTopPage();
48
49
        $this->owner->TopPageLocale = null;
0 ignored issues
show
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\ElementalArea. Since you implemented __set, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\BaseElement. Since you implemented __set, consider adding a @property annotation.
Loading history...
50
    }
51
52
    /*
53
     * @inheritdoc
54
     */
55
    protected function assignFixedTopPage(): void
56
    {
57
        parent::assignFixedTopPage();
58
59
        $this->owner->TopPageLocale = FluentState::singleton()->getLocale();
0 ignored issues
show
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\BaseElement. Since you implemented __set, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property TopPageLocale does not exist on DNADesign\Elemental\Models\ElementalArea. Since you implemented __set, consider adding a @property annotation.
Loading history...
60
    }
61
62
    /*
63
     * @inheritdoc
64
     */
65
    protected function saveChanges(array $extraData = []): void
66
    {
67
        /** @var DataObject|FluentExtension $owner */
68
        $owner = $this->owner;
69
        $extraData['"TopPageLocale"'] = $owner->TopPageLocale;
70
71
        parent::saveChanges($extraData);
72
    }
73
}
74