Completed
Push — master ( e8e08f...3f7cb6 )
by Vitaly
02:53
created

MaterialField::byMaterialID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 15
loc 15
rs 9.4286
cc 2
eloc 11
nc 2
nop 4
1
<?php
2
namespace samsoncms\api;
3
4
use samsonframework\orm\QueryInterface;
5
6
/**
7
 * SamsonCMS additional field value table entity class
8
 * @package samson\cms
9
 */
10
class MaterialField extends \samson\activerecord\materialfield
11
{
12
    /** @var integer Primary key */
13
    public $FieldID;
14
15
    /** @var bool Internal existence flag */
16
    public $Active;
17
18
    /** @var integer Material identifier */
19
    public $MaterialID;
20
21
    /** @var string Additional field value */
22
    public $Value;
23
24
    /** @var string Additional field value */
25
    public $numeric_value;
26
27
    /** @var string Additional field value */
28
    public $key_value;
29
30
    /** @var string Additional field locale */
31
    public $locale;
32
33
    /**
34
     * Get identifiers collection by field identifier and its value.
35
     * Method is optimized for performance.
36
     *
37
     * @param QueryInterface $query Database query instance
38
     * @param string $materialID Additional field identifier
39
     * @param string $fieldValue Additional field value for searching
0 ignored issues
show
Bug introduced by
There is no parameter named $fieldValue. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     * @param array|null $return Variable where request result would be returned
41
     * @param array $materialIDs Collection of material identifiers for filtering query
0 ignored issues
show
Documentation introduced by
There is no parameter named $materialIDs. Did you maybe mean $materialID?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
42
     * @return bool|array True if material entities has been found and $return is passed
43
     *                      or identifiers collection if only two parameters is passed.
44
     */
45
    public static function idsByMaterialId(QueryInterface $query, $materialID, &$return = array())
46
    {
47
        // Get material identifiers by field
48
        $return = $query->entity(CMS::MATERIAL_FIELD_RELATION_ENTITY)
0 ignored issues
show
Bug introduced by
The call to fields() misses a required argument $columnName.

This check looks for function calls that miss required arguments.

Loading history...
49
            ->where('MaterialID', $materialID)
50
            ->where('Active', 1)
51
            ->fields();
52
53
        // If only one argument is passed - return null, otherwise bool
54
        return func_num_args() > 2 ? sizeof($return) : $return;
55
    }
56
57
    /**
58
     * Find additional field value database record by its material and field identifiers.
59
     * This is generic method that should be used in nested classes to find its
60
     * records by some its primary key value.
61
     *
62
     * @param QueryInterface $query Query object instance
63
     * @param string $materialID Material identifier
64
     * @param self[]|null $return Variable to return found database record
65
     * @param string $locale Locale identifier
66
     * @return bool|null|self[]  Field instance or null if 3rd parameter not passed
67
     */
68 View Code Duplication
    public static function byMaterialID(
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...
69
        QueryInterface $query,
70
        $materialID,
71
        &$return = null,
72
        $locale = DEFAULT_LOCALE
73
    ) {
74
        $return = $query->entity(get_called_class())
75
            ->where('MaterialID', $materialID)
76
            ->where('FieldID', $fieldID)
0 ignored issues
show
Bug introduced by
The variable $fieldID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
77
            ->where('locale', $locale)
78
            ->exec();
79
80
        // If only one argument is passed - return null, otherwise bool
81
        return func_num_args() > 1 ? $return == null : $return;
82
    }
83
84
    /**
85
     * Find additional field value database record by its material and field identifiers.
86
     * This is generic method that should be used in nested classes to find its
87
     * records by some its primary key value.
88
     *
89
     * @param QueryInterface $query Query object instance
90
     * @param string $materialID Material identifier
91
     * @param string $fieldID Additional field identifier
92
     * @param self[]|null $return Variable to return found database record
93
     * @param string $locale Locale identifier
94
     * @return bool|null|self[]  Field instance or null if 3rd parameter not passed
95
     */
96 View Code Duplication
    public static function byFieldIDAndMaterialID(
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...
97
        QueryInterface $query,
98
        $materialID,
99
        $fieldID,
100
        &$return = null,
101
        $locale = DEFAULT_LOCALE
102
    ) {
103
        $return = $query->entity(get_called_class())
104
            ->where('MaterialID', $materialID)
105
            ->where('FieldID', $fieldID)
106
            ->where('locale', $locale)
107
            ->exec();
108
109
        // If only one argument is passed - return null, otherwise bool
110
        return func_num_args() > 1 ? $return == null : $return;
111
    }
112
}
113