Code Duplication    Length = 12-16 lines in 3 locations

src/Field.php 1 location

@@ 51-62 (lines=12) @@
48
     * @param self $return Variable to return found database record
49
     * @return bool|null|self  Field instance or null if 3rd parameter not passed
50
     */
51
    public static function byNameOrID(QueryInterface $query, $nameOrID, self & $return = null)
52
    {
53
        // Create id or URL condition
54
        $idOrUrl = new Condition('OR');
55
        $idOrUrl->add('FieldID', $nameOrID)->add('Name', $nameOrID);
56
57
        // Perform query
58
        $return = $query->entity(get_called_class())->where($idOrUrl)->first();
59
60
        // If only one argument is passed - return null, otherwise bool
61
        return func_num_args() > 1 ? $return == null : $return;
62
    }
63
64
    /**
65
     * If this field has defined key=>value set.

src/MaterialField.php 2 locations

@@ 68-82 (lines=15) @@
65
     * @param string $locale Locale identifier
66
     * @return bool|null|self[]  Field instance or null if 3rd parameter not passed
67
     */
68
    public static function byMaterialID(
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)
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.
@@ 96-111 (lines=16) @@
93
     * @param string $locale Locale identifier
94
     * @return bool|null|self[]  Field instance or null if 3rd parameter not passed
95
     */
96
    public static function byFieldIDAndMaterialID(
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