ContainerTrait::setContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bdf\Form\Util;
4
5
use Bdf\Form\Child\ChildInterface;
6
use Bdf\Form\ElementInterface;
7
use WeakReference;
8
9
/**
10
 * Implements get and set container methods for an element
11
 */
12
trait ContainerTrait
13
{
14
    /**
15
     * @var WeakReference<ChildInterface>|null
16
     */
17
    private $container;
18
19
20
    /**
21
     * @see ElementInterface::container()
22
     */
23 351
    final public function container(): ?ChildInterface
24
    {
25 351
        return $this->container ? $this->container->get() : null;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @return static
32
     * @see ElementInterface::setContainer()
33
     */
34 335
    final public function setContainer(ChildInterface $container): ElementInterface
35
    {
36 335
        $element = clone $this;
37 335
        $element->container = WeakReference::create($container);
38
39 335
        return $element;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $element returns the type Bdf\Form\Util\ContainerTrait which is incompatible with the type-hinted return Bdf\Form\ElementInterface.
Loading history...
40
    }
41
}
42