Passed
Push — master ( a22205...112e67 )
by Gabriel
04:04 queued 13s
created

HasExecutionMethodsTrait::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
    /**
13
     * @return bool
14
     */
15
    public function execute()
16
    {
17
        if ($this->submited()) {
18
            return $this->processRequest();
19
        }
20
21
        return false;
22
    }
23
24
    /**
25
     * @return bool
26
     */
27
    public function submited()
28
    {
29
        $request = $this->getAttrib('method') == 'post' ? $_POST : $_GET;
0 ignored issues
show
Bug introduced by
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

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

57
        $this->/** @scrutinizer ignore-call */ 
58
               getDataFromRequest($request);
Loading history...
58
        $this->processValidation();
59
60
        return $this->isValid();
61
    }
62
63
    public function processValidation()
64
    {
65
        $elements = $this->getElements();
0 ignored issues
show
Bug introduced by
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

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

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