Issues (138)

src/Traits/CanInitializeTrait.php (3 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\Form\Traits;
6
7
/**
8
 * Trait CanInitializeTrait
9
 * @package Nip\Form\Traits
10
 */
11
trait CanInitializeTrait
12
{
13
    /**
14
     * Is the form prepared ?
15
     *
16
     * @var bool
17
     */
18
    protected $initialized = false;
19
20
21
    public function initializeIfNotInitialized()
22
    {
23
        if ($this->initialized !== false) {
24
            return;
25
        }
26
27
        if (method_exists($this, 'init')) {
28
            $this->init();
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Form\Traits\CanInitializeTrait::init() has been deprecated: use initialize() ( Ignorable by Annotation )

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

28
            /** @scrutinizer ignore-deprecated */ $this->init();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
29
        } else {
30
            $this->initialize();
31
        }
32
33
        if (method_exists($this, 'postInit')) {
34
            $this->postInit();
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Form\Traits\CanInitializeTrait::postInit() has been deprecated: use initialize() ( Ignorable by Annotation )

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

34
            /** @scrutinizer ignore-deprecated */ $this->postInit();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
35
        } else {
36
            $this->initialized();
37
        }
38
39
        $this->initialized = true;
40
    }
41
42
    /**
43
     * @deprecated use initialize()
44
     */
45
    public function init()
46
    {
47
        $this->initialize();
48
    }
49
50
    /**
51
     * @return void
52
     */
53
    public function initialize()
54
    {
55
        $this->initAction();
56
    }
57
58
    /**
59
     * @deprecated use initialize()
60
     */
61
    public function postInit()
62
    {
63
        $this->initialized();
64
    }
65
66
    protected function initialized()
67
    {
68
    }
69
70
    protected function initAction()
71
    {
72
        if (function_exists('current_url')) {
73
            $this->setAction(current_url());
0 ignored issues
show
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

73
            $this->/** @scrutinizer ignore-call */ 
74
                   setAction(current_url());
Loading history...
74
        }
75
    }
76
}
77