Code Duplication    Length = 15-15 lines in 4 locations

src/Model.php 4 locations

@@ 1126-1140 (lines=15) @@
1123
     *
1124
     * @return Relation\Relation
1125
     */
1126
    public function hasOne($model, $foreignKey = '', $localKey = '')
1127
    {
1128
        // the default local key would look like `user_id`
1129
        // for a model named User
1130
        if (!$foreignKey) {
1131
            $inflector = Inflector::get();
1132
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1133
        }
1134
1135
        if (!$localKey) {
1136
            $localKey = self::DEFAULT_ID_PROPERTY;
1137
        }
1138
1139
        return new HasOne($model, $foreignKey, $localKey, $this);
1140
    }
1141
1142
    /**
1143
     * Creates the child side of a One-To-One or One-To-Many relationship.
@@ 1151-1165 (lines=15) @@
1148
     *
1149
     * @return Relation\Relation
1150
     */
1151
    public function belongsTo($model, $foreignKey = '', $localKey = '')
1152
    {
1153
        if (!$foreignKey) {
1154
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1155
        }
1156
1157
        // the default local key would look like `user_id`
1158
        // for a model named User
1159
        if (!$localKey) {
1160
            $inflector = Inflector::get();
1161
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1162
        }
1163
1164
        return new BelongsTo($model, $foreignKey, $localKey, $this);
1165
    }
1166
1167
    /**
1168
     * Creates the parent side of a Many-To-One or Many-To-Many relationship.
@@ 1176-1190 (lines=15) @@
1173
     *
1174
     * @return Relation\Relation
1175
     */
1176
    public function hasMany($model, $foreignKey = '', $localKey = '')
1177
    {
1178
        // the default local key would look like `user_id`
1179
        // for a model named User
1180
        if (!$foreignKey) {
1181
            $inflector = Inflector::get();
1182
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1183
        }
1184
1185
        if (!$localKey) {
1186
            $localKey = self::DEFAULT_ID_PROPERTY;
1187
        }
1188
1189
        return new HasMany($model, $foreignKey, $localKey, $this);
1190
    }
1191
1192
    /**
1193
     * Creates the child side of a Many-To-Many relationship.
@@ 1201-1215 (lines=15) @@
1198
     *
1199
     * @return Relation\Relation
1200
     */
1201
    public function belongsToMany($model, $foreignKey = '', $localKey = '')
1202
    {
1203
        if (!$foreignKey) {
1204
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1205
        }
1206
1207
        // the default local key would look like `user_id`
1208
        // for a model named User
1209
        if (!$localKey) {
1210
            $inflector = Inflector::get();
1211
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1212
        }
1213
1214
        return new BelongsToMany($model, $foreignKey, $localKey, $this);
1215
    }
1216
1217
    /////////////////////////////
1218
    // Events