AppController::add()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 2
b 0
f 0
nc 5
nop 0
dl 0
loc 24
ccs 15
cts 15
cp 1
crap 4
rs 9.7998
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * AppController
6
 */
7
8
namespace Fr3nch13\Jira\Controller;
9
10
use App\Controller\AppController as BaseController;
11
use Fr3nch13\Jira\Form\AppForm as JiraForm;
12
13
/**
14
 * App Controller
15
 *
16
 * The base controller for the jira plugin.
17
 */
18
class AppController extends BaseController
19
{
20
    /**
21
     * @var string Human name of this object.
22
     */
23
    public $humanName = '';
24
25
    /**
26
     * @var \Fr3nch13\Jira\Form\AppForm The form object.
27
     */
28
    public $JiraForm;
29
30
    /**
31
     * Initialize method
32
     *
33
     * @return void
34
     */
35 16
    public function initialize(): void
36
    {
37 16
        parent::initialize();
38
39 16
        $this->humanName = __('Report');
40 16
        $this->JiraForm = new JiraForm();
41
    }
42
43
    /**
44
     * The html form.
45
     *
46
     * @return null|\Cake\Http\Response Redirects on success.
47
     */
48 12
    public function add(): ?\Cake\Http\Response
49
    {
50 12
        $errors = [];
51 12
        if ($this->getRequest()->is('post')) {
52 8
            if ($this->JiraForm->execute($this->getRequest()->getData())) {
53 4
                $this->Flash->success(__('The {0} has been saved.', [$this->humanName]));
54
55 4
                return $this->redirect(['action' => 'thankyou', '?' => ['type' => $this->humanName]]);
56
            } else {
57 4
                $errors = $this->JiraForm->getErrors();
58 4
                $this->Flash->error(__('There was a problem saving the {0}.', [$this->humanName]));
59
            }
60
        }
61
62 8
        if ($this->getRequest()->is('get')) {
63 4
            $this->JiraForm->setData($this->JiraForm->getFormData());
64
        }
65
66 8
        $this->set([
67 8
            'form' => $this->JiraForm,
68 8
            'errors' => $errors,
69 8
        ]);
70
71 8
        return null;
72
    }
73
74
    /**
75
     * The thank you page after they've submitted their report.
76
     *
77
     * @return void
78
     */
79 4
    public function thankyou(): void
80
    {
81 4
    }
82
}
83