Test Setup Failed
Branch master (8ee063)
by giu
05:00
created

OrganizationsController::add()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 0
1
<?php
2
namespace App\Controller;
3
4
use App\Controller\AppController;
5
6
/**
7
 * Organizations Controller
8
 *
9
 * @property \App\Model\Table\OrganizationsTable $Organizations
10
 *
11
 * @method \App\Model\Entity\Organization[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
12
 */
13
class OrganizationsController extends AppController
14
{
15
16
    /**
17
     * Index method
18
     *
19
     * @return \Cake\Http\Response|void
20
     */
21
    public function index()
22
    {
23
        $this->paginate = [
24
            'contain' => ['Users']
25
        ];
26
        $organizations = $this->paginate($this->Organizations);
27
28
        $this->set(compact('organizations'));
29
    }
30
31
    /**
32
     * View method
33
     *
34
     * @param string|null $id Organization id.
35
     * @return \Cake\Http\Response|void
36
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
37
     */
38
    public function view($id = null)
39
    {
40
        $organization = $this->Organizations->get($id, [
41
            'contain' => ['Users']
42
        ]);
43
44
        $this->set('organization', $organization);
45
    }
46
47
    /**
48
     * Add method
49
     *
50
     * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
51
     */
52 View Code Duplication
    public function add()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $organization = $this->Organizations->newEntity();
55
        if ($this->request->is('post')) {
56
            $organization = $this->Organizations->patchEntity($organization, $this->request->getData());
57
            if ($this->Organizations->save($organization)) {
58
                $this->Flash->success(__('The organization has been saved.'));
59
60
                return $this->redirect(['action' => 'index']);
61
            }
62
            $this->Flash->error(__('The organization could not be saved. Please, try again.'));
63
        }
64
        $users = $this->Organizations->Users->find('list', ['limit' => 200]);
65
        $this->set(compact('organization', 'users'));
66
    }
67
68
    /**
69
     * Edit method
70
     *
71
     * @param string|null $id Organization id.
72
     * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
73
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
74
     */
75 View Code Duplication
    public function edit($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $organization = $this->Organizations->get($id, [
78
            'contain' => []
79
        ]);
80
        if ($this->request->is(['patch', 'post', 'put'])) {
81
            $organization = $this->Organizations->patchEntity($organization, $this->request->getData());
82
            if ($this->Organizations->save($organization)) {
83
                $this->Flash->success(__('The organization has been saved.'));
84
85
                return $this->redirect(['action' => 'index']);
86
            }
87
            $this->Flash->error(__('The organization could not be saved. Please, try again.'));
88
        }
89
        $users = $this->Organizations->Users->find('list', ['limit' => 200]);
90
        $this->set(compact('organization', 'users'));
91
    }
92
93
    /**
94
     * Delete method
95
     *
96
     * @param string|null $id Organization id.
97
     * @return \Cake\Http\Response|null Redirects to index.
98
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
99
     */
100
    public function delete($id = null)
101
    {
102
        $this->request->allowMethod(['post', 'delete']);
103
        $organization = $this->Organizations->get($id);
104
        if ($this->Organizations->delete($organization)) {
105
            $this->Flash->success(__('The organization has been deleted.'));
106
        } else {
107
            $this->Flash->error(__('The organization could not be deleted. Please, try again.'));
108
        }
109
110
        return $this->redirect(['action' => 'index']);
111
    }
112
}
113