Code Duplication    Length = 15-15 lines in 4 locations

src/Model.php 4 locations

@@ 1137-1151 (lines=15) @@
1134
     *
1135
     * @return Relation\Relation
1136
     */
1137
    public function hasOne($model, $foreignKey = '', $localKey = '')
1138
    {
1139
        // the default local key would look like `user_id`
1140
        // for a model named User
1141
        if (!$foreignKey) {
1142
            $inflector = Inflector::get();
1143
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1144
        }
1145
1146
        if (!$localKey) {
1147
            $localKey = self::DEFAULT_ID_PROPERTY;
1148
        }
1149
1150
        return new HasOne($model, $foreignKey, $localKey, $this);
1151
    }
1152
1153
    /**
1154
     * Creates the child side of a One-To-One or One-To-Many relationship.
@@ 1162-1176 (lines=15) @@
1159
     *
1160
     * @return Relation\Relation
1161
     */
1162
    public function belongsTo($model, $foreignKey = '', $localKey = '')
1163
    {
1164
        if (!$foreignKey) {
1165
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1166
        }
1167
1168
        // the default local key would look like `user_id`
1169
        // for a model named User
1170
        if (!$localKey) {
1171
            $inflector = Inflector::get();
1172
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1173
        }
1174
1175
        return new BelongsTo($model, $foreignKey, $localKey, $this);
1176
    }
1177
1178
    /**
1179
     * Creates the parent side of a Many-To-One or Many-To-Many relationship.
@@ 1187-1201 (lines=15) @@
1184
     *
1185
     * @return Relation\Relation
1186
     */
1187
    public function hasMany($model, $foreignKey = '', $localKey = '')
1188
    {
1189
        // the default local key would look like `user_id`
1190
        // for a model named User
1191
        if (!$foreignKey) {
1192
            $inflector = Inflector::get();
1193
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1194
        }
1195
1196
        if (!$localKey) {
1197
            $localKey = self::DEFAULT_ID_PROPERTY;
1198
        }
1199
1200
        return new HasMany($model, $foreignKey, $localKey, $this);
1201
    }
1202
1203
    /**
1204
     * Creates the child side of a Many-To-Many relationship.
@@ 1212-1226 (lines=15) @@
1209
     *
1210
     * @return Relation\Relation
1211
     */
1212
    public function belongsToMany($model, $foreignKey = '', $localKey = '')
1213
    {
1214
        if (!$foreignKey) {
1215
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1216
        }
1217
1218
        // the default local key would look like `user_id`
1219
        // for a model named User
1220
        if (!$localKey) {
1221
            $inflector = Inflector::get();
1222
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1223
        }
1224
1225
        return new BelongsToMany($model, $foreignKey, $localKey, $this);
1226
    }
1227
1228
    /////////////////////////////
1229
    // Events