Feedback   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 15%

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
rs 10
ccs 3
cts 20
cp 0.15

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onLoad() 0 4 1
B onSubmitted() 0 31 4
1
<?php 
2
3
namespace Helmut\Forms\Plugins\Feedback;
4
5
use Helmut\Forms\Plugin;
6
7
class Feedback extends Plugin {
8
9 134
    public function onLoad($form)
10
    {
11 134
        $form->addButton('feedback_trigger_'.$form->id);
12 134
    }
13
14
    public function onSubmitted($form) 
15
    {
16
        $request = $form->getRequest();
17
18
        if ($request->get('feedback_trigger_'.$form->id)) {
19
20
            $field = $form->field($request->get('name'));
21
22
            if ( ! is_null($field)) {
23
24
                $field->setFromRequest($request);
25
                
26
                $field->runValidations();
27
28
                $response = [
29
                    'id' => $field->id, 
30
                    'valid' => $field->valid(), 
31
                    'error_id' => 'feedback_errors_'.$field->id,
32
                    'error' => '', 
33
                ];
34
35
                if ( ! $field->valid()) {
36
                    $response['error'] = $form->renderFieldErrors($field);
37
                }
38
39
                header('Content-Type: application/json');
40
                echo json_encode($response);
41
                exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method onSubmitted() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
42
            }
43
        }
44
    }
45
46
}