Passed
Pull Request — master (#37)
by Brian
05:49 queued 02:39
created

AppController::add()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.9102

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 8
cts 13
cp 0.6153
crap 4.9102
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 object|null The form object.
27
     */
28
    public $JiraForm = null;
29
30
    /**
31
     * Initialize method
32
     *
33
     * @return void
34
     */
35 2
    public function initialize(): void
36
    {
37 2
        parent::initialize();
38
39 2
        $this->humanName = __('Task');
40 2
        $this->JiraForm = new JiraForm();
41
    }
42
43
    /**
44
     * The html form.
45
     *
46
     * @return null|\Cake\Http\Response Redirects on success.
47
     */
48 1
    public function add(): ?\Cake\Http\Response
49
    {
50 1
        $errors = [];
51 1
        if ($this->getRequest()->is('post')) {
52
            if ($this->JiraForm->execute($this->getRequest()->getData())) {
53
                $this->Flash->success(__('The {0} has been saved.', [$this->humanName]));
54
55
                return $this->redirect(['action' => 'thankyou', '?' => ['type' => $this->humanName]]);
56
            } else {
57
                $errors = $this->JiraForm->getErrors();
58
                $this->Flash->error(__('There was a problem saving the {0}.', [$this->humanName]));
59
            }
60
        }
61
62 1
        if ($this->getRequest()->is('get')) {
63 1
            $this->JiraForm->setData($this->JiraForm->getFormData());
64
        }
65
66 1
        $this->set([
67 1
            'form' => $this->JiraForm,
68
            'errors' => $errors,
69
        ]);
70
71 1
        return null;
72
    }
73
74
    /**
75
     * The thank you page after they've submitted their report.
76
     *
77
     * @return void
78
     */
79
    public function thankyou(): void
80
    {
81
    }
82
}
83