Passed
Push — master ( c23f2d...27e589 )
by Gabriel
11:22 queued 11s
created

CanInitializeTrait::initAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace Nip\Form\Traits;
5
6
7
/**
8
 * Trait CanInitializeTrait
9
 * @package Nip\Form\Traits
10
 */
11
trait CanInitializeTrait
12
{
13
14
    /**
15
     * Is the form prepared ?
16
     *
17
     * @var bool
18
     */
19
    protected $initialized = false;
20
21
    /**
22
     * @deprecated use initialize()
23
     */
24
    public function init()
25
    {
26
        return $this->initialize();
27
    }
28
29
    /**
30
     * @return $this
31
     */
32
    public function initialize()
33
    {
34
        if ($this->initialized()) {
35
            return $this;
36
        }
37
38
        $this->initAction();
39
        $this->postInit();
40
        $this->initialized(true);
41
        return $this;
42
    }
43
44
    /**
45
     * @param null $initialized
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $initialized is correct as it would always require null to be passed?
Loading history...
46
     * @return bool
47
     */
48
    protected function initialized($initialized = null): bool
49
    {
50
        if (is_bool($initialized)) {
0 ignored issues
show
introduced by
The condition is_bool($initialized) is always false.
Loading history...
51
            $this->initialized = $initialized;
52
        }
53
        return $this->initialized;
54
    }
55
56
    protected function initAction()
57
    {
58
        if (function_exists('current_url')) {
59
            $this->setAction(current_url());
0 ignored issues
show
Bug introduced by
It seems like setAction() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

59
            $this->/** @scrutinizer ignore-call */ 
60
                   setAction(current_url());
Loading history...
60
        }
61
    }
62
63
    public function postInit()
64
    {
65
    }
66
}