Test Failed
Pull Request — master (#20)
by
unknown
04:23
created

ModulesController::onConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
    public function onConstruct()
39
    {
40
        $this->model = new Modules();
41
    }
42
43
    /**
44
     * Fetch all Custom Fields of a Module
45
     * @param integer $id
46
     * @return Response
47
     */
48
    public function customFieldsByModulesId(int $id): Response
49
    {
50
        //Verify that module exists
51
        $module = $this->model::findFirst([
52
            'conditions' => 'id = ?0 and apps_id = ?1 and is_deleted = 0',
53
            '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
        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
        $customFields = CustomFields::find([
62
            'conditions' => 'companies_id = ?0 and apps_id = ?1 and is_deleted = 0',
63
            '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
        if (!is_object($customFields)) {
67
            throw new NotFoundHttpException('Custom Fields not found');
68
        }
69
70
        return $this->response($customFields);
71
    }
72
}
73