Test Failed
Pull Request — master (#20)
by
unknown
03:44
created

ModulesController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 54
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A customFieldsByModulesId() 0 23 3
A onConstruct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Api\Controllers;
6
7
use Gewaer\Models\Modules;
8
use Gewaer\CustomFields\CustomFields;
9
use Phalcon\Http\Response;
10
11
/**
12
 * Class LanguagesController
13
 *
14
 * @package Gewaer\Api\Controllers
15
 *
16
 */
17
class ModulesController extends BaseController
18
{
19
    /*
20
     * fields we accept to create
21
     *
22
     * @var array
23
     */
24
    protected $createFields = ['apps_id', 'name'];
25
26
    /*
27
     * fields we accept to create
28
     *
29
     * @var array
30
     */
31
    protected $updateFields = ['apps_id', 'name'];
32
33
    /**
34
     * set objects
35
     *
36
     * @return void
37
     */
38 3
    public function onConstruct()
39
    {
40 3
        $this->model = new Modules();
41 3
    }
42
43
    /**
44
     * Fetch all Custom Fields of a Module
45
     * @param integer $id
46
     * @return Response
47
     */
48 1
    public function customFieldsByModulesId(int $id): Response
49
    {
50
        //Verify that module exists
51 1
        $module = $this->model::findFirst([
52 1
            'conditions' => 'id = ?0 and apps_id = ?1 and is_deleted = 0',
53 1
            'bind' => [$id, $this->app->getId()]
0 ignored issues
show
Bug Best Practice introduced by
The property app does not exist on Gewaer\Api\Controllers\ModulesController. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
        ]);
55
56 1
        if (!is_object($module)) {
57
            throw new NotFoundHttpException('Module not found');
0 ignored issues
show
Bug introduced by
The type Gewaer\Api\Controllers\NotFoundHttpException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
        }
59
60
        //List all Custom Fields by module_id, apps and companies
61 1
        $customFields = CustomFields::find([
62 1
            'conditions' => 'companies_id = ?0 and apps_id = ?1 and is_deleted = 0',
63 1
            'bind' => [$this->userData->default_company, $this->app->getId()]
0 ignored issues
show
Bug Best Practice introduced by
The property userData does not exist on Gewaer\Api\Controllers\ModulesController. Since you implemented __get, consider adding a @property annotation.
Loading history...
64
        ]);
65
66 1
        if (!is_object($customFields)) {
67
            throw new NotFoundHttpException('Custom Fields not found');
68
        }
69
70 1
        return $this->response($customFields);
71
    }
72
}
73