ListAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A execute() 0 21 2
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service\Action;
13
14
use Cake\Filesystem\Folder;
15
use Cake\Utility\Inflector;
16
17
/**
18
 * Class ListAction
19
 *
20
 * @package CakeDC\Api\Service\Action
21
 */
22
class ListAction extends Action
23
{
24
25
    /**
26
     * Initialize an action instance
27
     *
28
     * @param array $config Configuration options passed to the constructor
29
     * @return void
30
     */
31 2
    public function initialize(array $config)
32
    {
33 2
        parent::initialize($config);
34 2
        $this->Auth->allow($this->getName());
35 2
    }
36
37
    /**
38
     * Execute action.
39
     *
40
     * @return mixed
41
     */
42 2
    public function execute()
43
    {
44 2
        $path = APP . 'Model' . DS . 'Table';
45 2
        $folder = new Folder($path);
46 2
        $tables = $folder->find('.*\.php');
47 2
        $services = collection($tables)
48
            ->map(function ($item) {
49 2
                preg_match('/^(.*)Table\.php/', $item, $replacedMatch);
50 2
                if (empty($replacedMatch[1])) {
51
                    return null;
52
                }
53
54 2
                return Inflector::underscore($replacedMatch[1]);
55 2
            })
56 2
            ->filter(function ($item) {
57 2
                return !empty($item);
58 2
            })
59 2
            ->toArray();
60
61 2
        return $services;
62
    }
63
}
64