Issues (138)

src/Traits/HasExecutionMethodsTrait.php (5 issues)

Labels
Severity
1
<?php
2
3
namespace Nip\Form\Traits;
4
5
/**
6
 * Trait HasExecutionMethodsTrait
7
 * @package Nip\Form\Traits
8
 */
9
trait HasExecutionMethodsTrait
10
{
11
    /**
12
     * @return bool
13
     */
14
    public function execute()
15
    {
16
        if ($this->submited()) {
17
            return $this->processRequest();
18
        }
19
20
        return false;
21
    }
22
23
    /**
24
     * @return bool
25
     */
26
    public function submited()
27
    {
28
        $this->initializeIfNotInitialized();
0 ignored issues
show
It seems like initializeIfNotInitialized() 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

28
        $this->/** @scrutinizer ignore-call */ 
29
               initializeIfNotInitialized();
Loading history...
29
30
        $request = $this->getAttrib('method') == 'post' ? $_POST : $_GET;
0 ignored issues
show
It seems like getAttrib() 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

30
        $request = $this->/** @scrutinizer ignore-call */ getAttrib('method') == 'post' ? $_POST : $_GET;
Loading history...
31
        if (count($request)) {
32
            return true;
33
        }
34
35
        return false;
36
    }
37
38
    /**
39
     * @return bool
40
     */
41
    public function processRequest()
42
    {
43
        if ($this->validate()) {
44
            $this->process();
45
46
            return true;
47
        }
48
49
        return false;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function validate()
56
    {
57
        $this->initializeIfNotInitialized();
58
59
        $request = $this->getAttrib('method') == 'post' ? $_POST : $_GET;
60
        $this->getDataFromRequest($request);
0 ignored issues
show
It seems like getDataFromRequest() 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

60
        $this->/** @scrutinizer ignore-call */ 
61
               getDataFromRequest($request);
Loading history...
61
        $this->processValidation();
62
63
        return $this->isValid();
64
    }
65
66
    public function processValidation()
67
    {
68
        $elements = $this->getElements();
0 ignored issues
show
It seems like getElements() 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

68
        /** @scrutinizer ignore-call */ 
69
        $elements = $this->getElements();
Loading history...
69
        if (is_array($elements)) {
70
            foreach ($elements as $name => $element) {
71
                $element->validate();
72
            }
73
        }
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isValid()
80
    {
81
        return count($this->getErrors()) > 0 ? false : true;
0 ignored issues
show
It seems like getErrors() 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

81
        return count($this->/** @scrutinizer ignore-call */ getErrors()) > 0 ? false : true;
Loading history...
82
    }
83
84
    public function process()
85
    {
86
        $this->initializeIfNotInitialized();
87
    }
88
}
89