Total Complexity | 6 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
|
81 | 4 | } |
|
82 | } |
||
83 |