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

AbstractCustomFieldsModel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 57.69%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 75
ccs 15
cts 26
cp 0.5769
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomFieldsByModel() 0 11 4
A getAllCustomFields() 0 48 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\CustomFields;
5
6
use Gewaer\Models\Modules;
7
8
abstract class AbstractCustomFieldsModel extends \Baka\Database\ModelCustomFields
9
{
10
    /**
11
     * Get all custom fields of the given object
12
     *
13
     * @param  array  $fields
14
     * @return \Phalcon\Mvc\Model
15
     */
16 4
    public function getAllCustomFields(array $fields = [], int $company_id = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $company_id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

16
    public function getAllCustomFields(array $fields = [], /** @scrutinizer ignore-unused */ int $company_id = 0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        //We does it only find names in plural? We need to fix this or make a workaroun
19 4
        if (!$models = Modules::findFirstByName($this->getSource())) {
0 ignored issues
show
Bug introduced by
The method findFirstByName() does not exist on Gewaer\Models\Modules. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        if (!$models = Modules::/** @scrutinizer ignore-call */ findFirstByName($this->getSource())) {
Loading history...
20
            return;
21
        }
22
23 4
        $conditions = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $conditions is dead and can be removed.
Loading history...
24 4
        $fieldsIn = null;
25
26 4
        if (!empty($fields)) {
27
            $fieldsIn = " and name in ('" . implode("','", $fields) . ')';
28
        }
29
30 4
        $conditions = 'modules_id = ? ' . $fieldsIn;
31
32 4
        $bind = [$this->getId(), $this->di->getApp()->getId(), $models->getId(), $this->di->getUserData()->default_company];
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist on Gewaer\CustomFields\AbstractCustomFieldsModel. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method getApp() does not exist on Phalcon\Mvc\Model\Resultset. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $bind = [$this->getId(), $this->di->/** @scrutinizer ignore-call */ getApp()->getId(), $models->getId(), $this->di->getUserData()->default_company];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getUserData() does not exist on Phalcon\Mvc\Model\Resultset. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $bind = [$this->getId(), $this->di->getApp()->getId(), $models->getId(), $this->di->/** @scrutinizer ignore-call */ getUserData()->default_company];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
34
        // $customFieldsValueTable = $this->getSource() . '_custom_fields';
35 4
        $customFieldsValueTable = $this->getSource() . '_custom_fields';
36
37
        //We are to make a new query to replace old gewaer implementation.
38 4
        $result = $this->getReadConnection()->prepare("SELECT l.{$this->getSource()}_id,
1 ignored issue
show
Bug introduced by
The method prepare() does not exist on Phalcon\Db\AdapterInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Phalcon\Db\Adapter. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        $result = $this->getReadConnection()->/** @scrutinizer ignore-call */ prepare("SELECT l.{$this->getSource()}_id,
Loading history...
39
                                               c.id as field_id,
40
                                               c.name,
41
                                               l.value ,
42
                                               c.users_id,
43
                                               l.created_at,
44
                                               l.updated_at
45 4
                                        FROM {$customFieldsValueTable} l,
46
                                             custom_fields c
47
                                        WHERE c.id = l.custom_fields_id
48 4
                                          AND l.{$this->getSource()}_id = ?
49
                                          AND c.apps_id = ?
50
                                          AND c.modules_id = ?
51
                                          AND c.companies_id = ? 
52
                                          AND l.companies_id = c.companies_id");
53
54 4
        $result->execute($bind);
55
56
        // $listOfCustomFields = $result->fetchAll();
57 4
        $listOfCustomFields = [];
58
59 4
        while ($row = $result->fetch(\PDO::FETCH_OBJ)) {
60
            $listOfCustomFields[$row->name] = $row->value;
61
        }
62
63 4
        return $listOfCustomFields;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $listOfCustomFields returns the type array which is incompatible with the documented return type Phalcon\Mvc\Model.
Loading history...
64
    }
65
66
    /**
67
     * Get all custom fields of the given model
68
     *
69
     * @param  array  $fields
70
     * @return \Phalcon\Mvc\Model
71
     */
72
    public function getCustomFieldsByModel($modelName)
73
    {
74
        if (!$module = Modules::findFirstByName($modelName)) {
75
            return;
76
        }
77
        $allFields = [];
78
        if ($fields = \Incursio\Models\CustomFields::findByModulesId($module->id)->toArray()) {
0 ignored issues
show
Bug introduced by
The type Incursio\Models\CustomFields 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...
79
            foreach ($fields as $field) {
80
                array_push($allFields, $field['name']);
81
            }
82
            return $allFields;
83
        }
84
    }
85
}
86