Passed
Pull Request — master (#18)
by Brian
05:45
created

AppController::add()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.7286

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