Code Duplication    Length = 12-16 lines in 3 locations

src/Field.php 1 location

@@ 42-53 (lines=12) @@
39
     * @param self $return Variable to return found database record
40
     * @return bool|null|self  Field instance or null if 3rd parameter not passed
41
     */
42
    public static function byNameOrID(QueryInterface $query, $nameOrID, self & $return = null)
43
    {
44
        // Create id or URL condition
45
        $idOrUrl = new Condition('OR');
46
        $idOrUrl->add('FieldID', $nameOrID)->add('Name', $field);
47
48
        // Perform query
49
        $return = $query->className('field')->cond($idOrUrl)->first();
50
51
        // If only one argument is passed - return null, otherwise bool
52
        return func_num_args() > 1 ? $return == null : $return;
53
    }
54
55
    /** @return string Get additional field value field name depending on its type */
56
    public function valueFieldName()

src/MaterialField.php 1 location

@@ 24-39 (lines=16) @@
21
     * @param string $locale Locale identifier
22
     * @return bool|null|self  Field instance or null if 3rd parameter not passed
23
     */
24
    public static function byFieldIDAndMaterialID(
25
        QueryInterface $query,
26
        $materialID,
27
        $fieldID,
28
        self & $return = null,
29
        $locale = DEFAULT_LOCALE
30
    ) {
31
        $return = $query->className(__CLASS__)
32
            ->cond('MaterialID', $materialID)
33
            ->cond('FieldID', $fieldID)
34
            ->cond('locale', $locale)
35
            ->first();
36
37
        // If only one argument is passed - return null, otherwise bool
38
        return func_num_args() > 1 ? $return == null : $return;
39
    }
40
}
41

src/Material.php 1 location

@@ 134-148 (lines=15) @@
131
     * @return bool|self[] True if material entities has been found and $return is passed
132
     *                      or self[] if only two parameters is passed.
133
     */
134
    public static function byNavigationID(QueryInterface $query, $navigationID, &$return = array())
135
    {
136
        /** @var array $materialIds Collection of entity identifiers filtered by additional field */
137
        $materialIds = null;
138
        if (static::idsByNavigationID($query, $navigationID, $materialIds)) {
139
            $return = $query->entity(get_called_class())
140
                ->where('MaterialID', $materialIds)
141
                ->where('Active', 1)
142
                ->where('Published', 1)
143
                ->exec();
144
        }
145
146
        // If only one argument is passed - return null, otherwise bool
147
        return func_num_args() > 2 ? $return == null : $return;
148
    }
149
150
    public static function byNavigationIdAndFieldValue(QueryInterface $query, $navigationID, $fieldID, $fieldValue, &$return = array())
151
    {