Code Duplication    Length = 12-22 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/Material.php 2 locations

@@ 81-102 (lines=22) @@
78
     * @return bool|array True if material entities has been found and $return is passed
79
     *                      or collection of identifiers if only two parameters is passed.
80
     */
81
    public static function idsByNavigationID(
82
        QueryInterface $query,
83
        $navigationID,
84
        &$return = array(),
85
        $materialIDs = null
86
    ) {
87
        // Prepare query
88
         $query->entity(CMS::MATERIAL_NAVIGATION_RELATION_ENTITY)
89
            ->where('StructureID', $navigationID)
90
            ->where('Active', 1);
91
92
        // Add material identifier filter if passed
93
        if (isset($materialIDs)) {
94
            $query->where('MaterialID', $materialIDs);
95
        }
96
97
        // Perform database query and get only material identifiers collection
98
        $return = $query->fields('MaterialID');
99
100
        // If only one argument is passed - return null, otherwise bool
101
        return func_num_args() > 2 ? $return == null : $return;
102
    }
103
104
    /**
105
     * Get self[] by field identifier and its value.
@@ 139-153 (lines=15) @@
136
     * @return bool|self[] True if material entities has been found and $return is passed
137
     *                      or self[] if only two parameters is passed.
138
     */
139
    public static function byNavigationID(QueryInterface $query, $navigationID, &$return = array())
140
    {
141
        /** @var array $materialIds Collection of entity identifiers filtered by additional field */
142
        $materialIds = null;
143
        if (static::idsByNavigationID($query, $navigationID, $materialIds)) {
144
            $return = $query->entity(get_called_class())
145
                ->where('MaterialID', $materialIds)
146
                ->where('Active', 1)
147
                ->where('Published', 1)
148
                ->exec();
149
        }
150
151
        // If only one argument is passed - return null, otherwise bool
152
        return func_num_args() > 2 ? $return == null : $return;
153
    }
154
155
    /**
156
     * Get current entity instances collection by navigation identifier.