GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TableController   C
last analyzed

Complexity

Total Complexity 56

Size/Duplication

Total Lines 573
Duplicated Lines 25.31 %

Coupling/Cohesion

Components 1
Dependencies 23

Importance

Changes 0
Metric Value
wmc 56
lcom 1
cbo 23
dl 145
loc 573
rs 5.5199
c 0
b 0
f 0

51 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityManager() 0 7 2
A changesAction() 0 4 1
A bootstrapAction() 0 3 1
A additionalParamsAction() 0 3 1
A ajaxadditionalParamsAction() 9 9 1
A javascriptEventsAction() 0 3 1
A ajaxJavascriptEventsAction() 9 9 1
A arrayAction() 0 3 1
A ajaxArrayAction() 0 20 1
A doctrineAction() 0 3 1
A ajaxDoctrineAction() 0 32 2
A callableAction() 0 3 1
A ajaxCallableAction() 9 9 1
A columnFilteringAction() 0 3 1
A ajaxColumnFilteringAction() 9 9 1
A editableAction() 0 3 1
A ajaxEditableAction() 9 9 1
A updateRowAction() 0 9 1
A csvExportAction() 0 3 1
A ajaxCsvExportAction() 9 9 1
A separatableAction() 0 3 1
A ajaxSeparatableAction() 0 12 1
A variableAttrRowAction() 0 4 1
A newPluginConditionAction() 0 4 1
A ajaxNewPluginConditionAction() 9 9 1
A baseAction() 0 3 1
A ajaxBaseAction() 9 9 1
A mapperAction() 0 4 1
A ajaxMapperAction() 10 10 1
A linkAction() 0 4 1
A ajaxLinkAction() 9 9 1
A templateAction() 0 4 1
A ajaxTemplateAction() 9 9 1
A attrAction() 0 4 1
A ajaxAttrAction() 9 9 1
A conditionAction() 0 4 1
A ajaxConditionAction() 9 9 1
A mixAction() 0 4 1
A ajaxMixAction() 9 9 1
A advanceAction() 0 4 1
A ajaxAdvanceAction() 10 10 1
A dataTableAction() 0 13 1
A ajaxDataTableAction() 0 14 1
A htmlResponse() 0 7 1
A jsonResponse() 0 11 2
A getCustomerTable() 0 8 2
A institutionRequestsAction() 0 3 1
A ajaxInstitutionRequestsAction() 8 8 1
A getInstitutionRequests() 0 4 1
A getDbAdapter() 0 8 2
A getSource() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TableController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TableController, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * ZfTable ( Module for Zend Framework 2)
4
 *
5
 * @copyright Copyright (c) 2013 Piotr Duda [email protected]
6
 * @license   MIT License
7
 */
8
9
namespace ZfTable\Controller;
10
11
use Zend\Mvc\Controller\AbstractActionController;
12
use ZfTable\Example\TableExample;
13
use Zend\View\Model\ViewModel;
14
use Zend\Db\ResultSet\ResultSet;
15
use ZfTable\Params\AdapterDataTables;
16
use ZfTable\Options\ModuleOptions;
17
use ZfTable\AbstractTable;
18
use Doctrine\ORM\EntityManager;
19
20
class TableController extends AbstractActionController
21
{
22
23
    /**
24
     *
25
     * @var ResultSet
26
     */
27
    protected $resultSet;
28
29
    /**
30
     *
31
     * @var
32
     */
33
    protected $customerTable;
34
35
    /**
36
     *
37
     * @var \Zend\Db\Adapter\Adapter
38
     */
39
    protected $dbAdapter;
40
41
    /**
42
     *
43
     * @var ModuleOptions
44
     */
45
    protected $moduleOptions;
46
47
48
49
50
     /**
51
     * @var \Doctrine\ORM\EntityManager
52
     */
53
    protected $em;
54
55
    /**
56
     *
57
     * @return \Doctrine\ORM\EntityManager
58
     */
59
    public function getEntityManager()
60
    {
61
        if (null === $this->em) {
62
            $this->em = $this->getServiceLocator()->get('doctrine.entitymanager.zftable_default');
63
        }
64
        return $this->em;
65
    }
66
67
    public function changesAction()
68
    {
69
70
    }
71
72
    public function bootstrapAction()
73
    {
74
    }
75
76
    /**
77
     * ********* Additional Params *******************
78
     * ***********************************
79
     */
80
    public function additionalParamsAction()
81
    {
82
    }
83 View Code Duplication
    public function ajaxadditionalParamsAction()
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...
84
    {
85
        $table = new TableExample\AdditionalParams();
86
        $table->setAdapter($this->getDbAdapter())
87
                ->setSource($this->getSource())
88
                ->setParamAdapter($this->getRequest()->getPost())
89
        ;
90
        return $this->htmlResponse($table->render());
91
    }
92
93
    /**
94
     * ********* Javascript Events *******************
95
     * ***********************************
96
     */
97
    public function javascriptEventsAction()
98
    {
99
    }
100 View Code Duplication
    public function ajaxJavascriptEventsAction()
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...
101
    {
102
        $table = new TableExample\JavascriptEvents();
103
        $table->setAdapter($this->getDbAdapter())
104
                ->setSource($this->getSource())
105
                ->setParamAdapter($this->getRequest()->getPost())
106
        ;
107
        return $this->htmlResponse($table->render());
108
    }
109
110
111
    /**
112
     * ********* Array Adapter *******************
113
     * *****************************************
114
     */
115
    public function arrayAction()
116
    {
117
    }
118
119
    public function ajaxArrayAction()
120
    {
121
        $table = new TableExample\ArrayAdapter();
122
123
        $sql = new \Zend\Db\Sql\Sql($this->getDbAdapter());
124
125
        $stmt = $sql->prepareStatementForSqlObject($this->getSource());
126
        $res = $stmt->execute();
127
128
        $resultSet = new \Zend\Db\ResultSet\ResultSet();
129
        $resultSet->initialize($res);
130
131
        $source = $resultSet->toArray();
132
133
        $table->setAdapter($this->getDbAdapter())
134
                ->setSource($source)
135
                ->setParamAdapter($this->getRequest()->getPost())
136
        ;
137
        return $this->htmlResponse($table->render());
138
    }
139
140
141
    /**
142
     * ********* Doctrine Adapter *******************
143
     * *****************************************
144
     */
145
    public function doctrineAction()
146
    {
147
    }
148
    public function ajaxDoctrineAction()
149
    {
150
        $table = new TableExample\Doctrine();
151
        $form = $table->getForm();
152
153
        //I don't know if it necesary to validate that request is POST
154
        $request = $this->getRequest();
155
156
        $filter = $table->getFilter();
157
        $form->setInputFilter($filter);
158
        $form->setData($request->getPost());
159
160
        //Optional
161
        if ($form->isValid()) {
162
            $em = $this->getEntityManager();
163
            $queryBuilder = $em->createQueryBuilder();
164
            $queryBuilder->add('select', 'p , q')
165
                ->add('from', '\ZfTable\Entity\Customer q')
166
                ->leftJoin('q.product', 'p')
167
            ;
168
169
            $table->setAdapter($this->getDbAdapter())
170
                ->setSource($queryBuilder)
171
                ->setParamAdapter($this->getRequest()->getPost())
172
            ;
173
174
            return $this->htmlResponse($table->render());
175
        } else {
176
            //Indication the wrong data currently not supported
177
        }
178
179
    }
180
181
182
    /**
183
     * ********* Callable *******************
184
     * *****************************************
185
     */
186
    public function callableAction()
187
    {
188
    }
189 View Code Duplication
    public function ajaxCallableAction()
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...
190
    {
191
        $table = new TableExample\CallableTable();
192
        $table->setAdapter($this->getDbAdapter())
193
                ->setSource($this->getSource())
194
                ->setParamAdapter($this->getRequest()->getPost())
195
        ;
196
        return $this->htmlResponse($table->render());
197
    }
198
199
200
201
    /**
202
     * ********* Column filtering *******************
203
     * ***********************************
204
     */
205
    public function columnFilteringAction()
206
    {
207
    }
208 View Code Duplication
    public function ajaxColumnFilteringAction()
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...
209
    {
210
        $table = new TableExample\ColumnFiltering();
211
        $table->setAdapter($this->getDbAdapter())
212
                ->setSource($this->getSource())
213
                ->setParamAdapter($this->getRequest()->getPost())
214
        ;
215
        return $this->htmlResponse($table->render());
216
    }
217
218
219
    /**
220
     * ********* Editable tabble *******************
221
     * ***********************************
222
     */
223
    public function editableAction()
224
    {
225
    }
226 View Code Duplication
    public function ajaxEditableAction()
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...
227
    {
228
        $table = new TableExample\Editable();
229
        $table->setAdapter($this->getDbAdapter())
230
                ->setSource($this->getSource())
231
                ->setParamAdapter($this->getRequest()->getPost())
232
        ;
233
        return $this->htmlResponse($table->render());
234
    }
235
236
    public function updateRowAction()
237
    {
238
        $param = $this->getRequest()->getPost();
239
        $this->getCustomerTable()->update(
240
            array($param['column'] => $param['value']),
241
            array('idcustomer' => $param['row'])
242
        );
243
        return $this->jsonResponse(array('success' => 1));
244
    }
245
246
247
    /**
248
     * ********* Export To CSV *******************
249
     * *****************************************
250
     */
251
    public function csvExportAction()
252
    {
253
    }
254 View Code Duplication
    public function ajaxCsvExportAction()
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...
255
    {
256
        $table = new TableExample\CsvExport();
257
        $table->setAdapter($this->getDbAdapter())
258
                ->setSource($this->getSource())
259
                ->setParamAdapter($this->getRequest()->getPost())
260
        ;
261
        return $this->htmlResponse($table->render());
262
    }
263
264
    /**
265
     * ********* SEPARATABLE *******************
266
     * *****************************************
267
     */
268
    public function separatableAction()
269
    {
270
    }
271
    public function ajaxSeparatableAction()
272
    {
273
        $source = $this->getSource();
274
        $source->order('city ASC');
275
276
        $table = new TableExample\Separatable();
277
        $table->setAdapter($this->getDbAdapter())
278
                ->setSource($source)
279
                ->setParamAdapter($this->getRequest()->getPost())
280
        ;
281
        return $this->htmlResponse($table->render());
282
    }
283
284
    /**
285
     * ********* Variable Row Attr *******************
286
     * *****************************************
287
     */
288
    public function variableAttrRowAction()
289
    {
290
291
    }
292
293
    /**
294
     * ********* New plugin condition *******************
295
     * *****************************************
296
     */
297
    public function newPluginConditionAction()
298
    {
299
300
    }
301 View Code Duplication
    public function ajaxNewPluginConditionAction()
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...
302
    {
303
        $table = new TableExample\NewPluginCondition();
304
        $table->setAdapter($this->getDbAdapter())
305
                ->setSource($this->getSource())
306
                ->setParamAdapter($this->getRequest()->getPost())
307
        ;
308
        return $this->htmlResponse($table->render());
309
    }
310
311
312
313
    /**
314
     * ********* Base *******************
315
     * ***********************************
316
     */
317
    public function baseAction()
318
    {
319
    }
320 View Code Duplication
    public function ajaxBaseAction()
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...
321
    {
322
        $table = new TableExample\Base();
323
        $table->setAdapter($this->getDbAdapter())
324
                ->setSource($this->getSource())
325
                ->setParamAdapter($this->getRequest()->getPost())
326
        ;
327
        return $this->htmlResponse($table->render());
328
    }
329
330
331
    /**
332
     * ********* Mapper *******************
333
     * ***********************************
334
     */
335
    public function mapperAction()
336
    {
337
338
    }
339
340 View Code Duplication
    public function ajaxMapperAction()
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...
341
    {
342
        $table = new TableExample\Mapper();
343
        $table->setAdapter($this->getDbAdapter())
344
                ->setSource($this->getSource())
345
                ->setParamAdapter($this->getRequest()->getPost())
346
        ;
347
        return $this->htmlResponse($table->render());
348
349
    }
350
351
    /**
352
     * ********* Link *******************
353
     * ***********************************
354
     */
355
    public function linkAction()
356
    {
357
358
    }
359
360 View Code Duplication
    public function ajaxLinkAction()
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...
361
    {
362
        $table = new TableExample\Link();
363
        $table->setAdapter($this->getDbAdapter())
364
                ->setSource($this->getSource())
365
                ->setParamAdapter($this->getRequest()->getPost())
366
        ;
367
        return $this->htmlResponse($table->render());
368
    }
369
370
371
     /**
372
     * ********* Template *******************
373
     * ***********************************
374
     */
375
    public function templateAction()
376
    {
377
378
    }
379
380 View Code Duplication
    public function ajaxTemplateAction()
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...
381
    {
382
        $table = new TableExample\Template();
383
        $table->setAdapter($this->getDbAdapter())
384
                ->setSource($this->getSource())
385
                ->setParamAdapter($this->getRequest()->getPost())
386
        ;
387
        return $this->htmlResponse($table->render());
388
    }
389
390
391
     /**
392
     * ********* Attr *******************
393
     * ***********************************
394
     */
395
    public function attrAction()
396
    {
397
398
    }
399
400 View Code Duplication
    public function ajaxAttrAction()
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...
401
    {
402
        $table = new TableExample\Attr();
403
        $table->setAdapter($this->getDbAdapter())
404
                ->setSource($this->getSource())
405
                ->setParamAdapter($this->getRequest()->getPost())
406
        ;
407
        return $this->htmlResponse($table->render());
408
    }
409
410
411
    /**
412
     * ********* Condition *******************
413
     * ***********************************
414
     */
415
    public function conditionAction()
416
    {
417
418
    }
419
420 View Code Duplication
    public function ajaxConditionAction()
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...
421
    {
422
        $table = new TableExample\Condition();
423
        $table->setAdapter($this->getDbAdapter())
424
                ->setSource($this->getSource())
425
                ->setParamAdapter($this->getRequest()->getPost())
426
        ;
427
        return $this->htmlResponse($table->render());
428
    }
429
430
431
    /**
432
     * ********* Mix *******************
433
     * ***********************************
434
     */
435
    public function mixAction()
436
    {
437
438
    }
439
440 View Code Duplication
    public function ajaxMixAction()
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...
441
    {
442
        $table = new TableExample\Mix();
443
        $table->setAdapter($this->getDbAdapter())
444
                ->setSource($this->getSource())
445
                ->setParamAdapter($this->getRequest()->getPost())
446
        ;
447
        return $this->htmlResponse($table->render());
448
    }
449
450
     /**
451
     * ********* Advance *******************
452
     * ***********************************
453
     */
454
    public function advanceAction()
455
    {
456
457
    }
458
459 View Code Duplication
    public function ajaxAdvanceAction()
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...
460
    {
461
        $table = new TableExample\Advance();
462
        $table->setAdapter($this->getDbAdapter())
463
                ->setSource($this->getSource())
464
                ->setParamAdapter($this->getRequest()->getPost())
465
        ;
466
        return $this->htmlResponse($table->render('custom', 'custom-b3'));
467
468
    }
469
470
471
472
473
474
475
476
    /************************************************ */
477
    /*************** EXAMPLE DATA TABLE ************* */
478
479
    public function dataTableAction()
480
    {
481
        $source = $this->getSource();
482
        $table = new TableExample\DataTable();
483
        $table->setAdapter($this->getDbAdapter())
484
                ->setSource($source)
485
                ->setParamAdapter(new AdapterDataTables($this->getRequest()->getPost()))
486
        ;
487
488
        return new ViewModel(array(
489
            'tableDataTable' => $table,
490
        ));
491
    }
492
493
    public function ajaxDataTableAction()
494
    {
495
        $source = $this->getSource();
496
        $table = new TableExample\DataTable();
497
        $table->setAdapter($this->getDbAdapter())
498
                ->setSource($source)
499
                ->setParamAdapter(new AdapterDataTables($this->getRequest()->getPost()))
500
        ;
501
502
        $response = $this->getResponse();
503
        $response->setStatusCode(200);
504
        $response->setContent($table->render('dataTableJson'));
505
        return $response;
506
    }
507
508
509
    public function htmlResponse($html)
510
    {
511
        $response = $this->getResponse();
512
        $response->setStatusCode(200);
513
        $response->setContent($html);
514
        return $response;
515
    }
516
517
    public function jsonResponse($data)
518
    {
519
        if (!is_array($data)) {
520
            throw new \InvalidArgumentException('$data param must be array');
521
        }
522
523
        $response = $this->getResponse();
524
        $response->setStatusCode(200);
525
        $response->setContent(json_encode($data));
526
        return $response;
527
    }
528
529
530
    /**
531
     *
532
     * @return \ZfTable\Example\Model\CustomerTable
533
     *
534
     */
535
    public function getCustomerTable()
536
    {
537
        if (!$this->customerTable) {
538
            $sm = $this->getServiceLocator();
539
            $this->customerTable = $sm->get('ZfTable\Example\Model\CustomerTable');
540
        }
541
        return $this->customerTable;
542
    }
543
544
    /**********************My codes*********************/
545
546
547
548
    public function institutionRequestsAction()
549
    {
550
    }
551
552 View Code Duplication
    public function ajaxInstitutionRequestsAction()
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...
553
    {
554
        $table = new TableExample\InstitutionRequests();
555
        $table->setAdapter($this->getDbAdapter())
556
                ->setSource($this->getInstitutionRequests())
557
                ->setParamAdapter($this->getRequest()->getPost());
558
        return $this->htmlResponse($table->render());
559
    }
560
561
    /**
562
     * @return \Zend\Db\Sql\Select Type
563
     */
564
    private function getInstitutionRequests()
565
    {
566
        return $this->getCustomerTable()->fetchAllInstitutionRequests();
567
    }
568
569
570
571
    /**
572
     *
573
     * @return \Zend\Db\Adapter\Adapter
574
     */
575
    public function getDbAdapter()
576
    {
577
        if (!$this->dbAdapter) {
578
            $sm = $this->getServiceLocator();
579
            $this->dbAdapter = $sm->get('zfdb_adapter');
580
        }
581
        return $this->dbAdapter;
582
    }
583
584
    /**
585
     *
586
     * @return \Zend\Db\Sql\Select
587
     */
588
    private function getSource()
589
    {
590
        return $this->getCustomerTable()->fetchAllSelect();
591
    }
592
}
593