Passed
Push — 1.x-dev ( 86e6f1...f6cce7 )
by Brian
04:10
created

AppController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 76.19%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 67
ccs 16
cts 21
cp 0.7619
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 24 4
A thankyou() 0 2 1
A initialize() 0 8 1
1
<?php
2
3
/**
4
 * AppController
5
 */
6
7
namespace Fr3nch13\Jira\Controller;
8
9
use App\Controller\AppController as BaseController;
10
use Fr3nch13\Jira\Form\AppForm as JiraForm;
11
12
/**
13
 * App Controller
14
 *
15
 * The base controller for the jira plugin.
16
 *
17
 * -----------------------------
18
 * Inherited:
19
 *
20
 * {@inheritdoc}
21
 *
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
34
     */
35
    public $JiraForm;
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->modelClass = false;
47
48 2
        $this->humanName = __('Task');
49 2
        $this->JiraForm = new JiraForm();
50 2
    }
51
52
    /**
53
     * The html form.
54
     *
55
     * @return \Cake\Http\Response|null Redirects on success.
56
     */
57 1
    public function add(): ?\Cake\Http\Response
58
    {
59 1
        $errors = [];
60 1
        if ($this->getRequest()->is('post')) {
61
            if ($this->JiraForm->execute($this->getRequest()->getData())) {
62
                $this->Flash->success(__('The {0} has been saved.', [$this->humanName]));
63
64
                return $this->redirect(['action' => 'thankyou', '?' => ['type' => $this->humanName]]);
65
            } else {
66
                $errors = $this->JiraForm->getErrors();
67
                $this->Flash->error(__('There was a problem saving the {0}.', [$this->humanName]));
68
            }
69
        }
70
71 1
        if ($this->getRequest()->is('get')) {
72 1
            $this->JiraForm->setData($this->JiraForm->getFormData());
73
        }
74
75 1
        $this->set([
76 1
            'form' => $this->JiraForm,
77 1
            'errors' => $errors,
78
        ]);
79
80 1
        return null;
81
    }
82
83
    /**
84
     * The thank you page after they've submitted their report.
85
     *
86
     * @return void
87
     */
88 1
    public function thankyou(): void
89
    {
90
        //
91 1
    }
92
}
93