Passed
Push — fix-9163 ( 64dde5...3df94b )
by Sam
17:47 queued 10:54
created

GridFieldStateAware::getStateManager()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace SilverStripe\Forms\GridField;
5
6
use SilverStripe\Core\Injector\Injector;
7
8
/**
9
 * A trait that makes a class able to consume and use a {@link GridFieldStateManagerInterface}
10
 * implementation
11
 */
12
trait GridFieldStateAware
13
{
14
    /**
15
     * @var GridFieldStateManagerInterface
16
     */
17
    protected $stateManager;
18
19
    /**
20
     * @param GridFieldStateManagerInterface $manager
21
     * @return self
22
     */
23
    public function setStateManager(GridFieldStateManagerInterface $manager): self
24
    {
25
        $this->stateManager = $manager;
26
27
        return $this;
28
    }
29
30
    /**
31
     * Fallback on the direct Injector access, but allow a custom implementation
32
     * to be applied
33
     *
34
     * @return GridFieldStateManagerInterface
35
     */
36
    public function getStateManager(): GridFieldStateManagerInterface
37
    {
38
        return $this->stateManager ?: Injector::inst()->get(GridFieldStateManagerInterface::class);
39
    }
40
}
41