Code Duplication    Length = 15-15 lines in 4 locations

src/Model.php 4 locations

@@ 1158-1172 (lines=15) @@
1155
     *
1156
     * @return Relation\Relation
1157
     */
1158
    public function hasOne($model, $foreignKey = '', $localKey = '')
1159
    {
1160
        // the default local key would look like `user_id`
1161
        // for a model named User
1162
        if (!$foreignKey) {
1163
            $inflector = Inflector::get();
1164
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1165
        }
1166
1167
        if (!$localKey) {
1168
            $localKey = self::DEFAULT_ID_PROPERTY;
1169
        }
1170
1171
        return new HasOne($model, $foreignKey, $localKey, $this);
1172
    }
1173
1174
    /**
1175
     * Creates the child side of a One-To-One or One-To-Many relationship.
@@ 1183-1197 (lines=15) @@
1180
     *
1181
     * @return Relation\Relation
1182
     */
1183
    public function belongsTo($model, $foreignKey = '', $localKey = '')
1184
    {
1185
        if (!$foreignKey) {
1186
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1187
        }
1188
1189
        // the default local key would look like `user_id`
1190
        // for a model named User
1191
        if (!$localKey) {
1192
            $inflector = Inflector::get();
1193
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1194
        }
1195
1196
        return new BelongsTo($model, $foreignKey, $localKey, $this);
1197
    }
1198
1199
    /**
1200
     * Creates the parent side of a Many-To-One or Many-To-Many relationship.
@@ 1208-1222 (lines=15) @@
1205
     *
1206
     * @return Relation\Relation
1207
     */
1208
    public function hasMany($model, $foreignKey = '', $localKey = '')
1209
    {
1210
        // the default local key would look like `user_id`
1211
        // for a model named User
1212
        if (!$foreignKey) {
1213
            $inflector = Inflector::get();
1214
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1215
        }
1216
1217
        if (!$localKey) {
1218
            $localKey = self::DEFAULT_ID_PROPERTY;
1219
        }
1220
1221
        return new HasMany($model, $foreignKey, $localKey, $this);
1222
    }
1223
1224
    /**
1225
     * Creates the child side of a Many-To-Many relationship.
@@ 1233-1247 (lines=15) @@
1230
     *
1231
     * @return Relation\Relation
1232
     */
1233
    public function belongsToMany($model, $foreignKey = '', $localKey = '')
1234
    {
1235
        if (!$foreignKey) {
1236
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1237
        }
1238
1239
        // the default local key would look like `user_id`
1240
        // for a model named User
1241
        if (!$localKey) {
1242
            $inflector = Inflector::get();
1243
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1244
        }
1245
1246
        return new BelongsToMany($model, $foreignKey, $localKey, $this);
1247
    }
1248
1249
    /////////////////////////////
1250
    // Events