Code Duplication    Length = 15-15 lines in 4 locations

src/Model.php 4 locations

@@ 1115-1129 (lines=15) @@
1112
     *
1113
     * @return Relation
1114
     */
1115
    public function hasOne($model, $foreignKey = '', $localKey = '')
1116
    {
1117
        // the default local key would look like `user_id`
1118
        // for a model named User
1119
        if (!$foreignKey) {
1120
            $inflector = Inflector::get();
1121
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1122
        }
1123
1124
        if (!$localKey) {
1125
            $localKey = self::DEFAULT_ID_PROPERTY;
1126
        }
1127
1128
        return new HasOne($model, $foreignKey, $localKey, $this);
1129
    }
1130
1131
    /**
1132
     * Creates the child side of a One-To-One or One-To-Many relationship.
@@ 1140-1154 (lines=15) @@
1137
     *
1138
     * @return Relation
1139
     */
1140
    public function belongsTo($model, $foreignKey = '', $localKey = '')
1141
    {
1142
        if (!$foreignKey) {
1143
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1144
        }
1145
1146
        // the default local key would look like `user_id`
1147
        // for a model named User
1148
        if (!$localKey) {
1149
            $inflector = Inflector::get();
1150
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1151
        }
1152
1153
        return new BelongsTo($model, $foreignKey, $localKey, $this);
1154
    }
1155
1156
    /**
1157
     * Creates the parent side of a Many-To-One or Many-To-Many relationship.
@@ 1165-1179 (lines=15) @@
1162
     *
1163
     * @return Relation
1164
     */
1165
    public function hasMany($model, $foreignKey = '', $localKey = '')
1166
    {
1167
        // the default local key would look like `user_id`
1168
        // for a model named User
1169
        if (!$foreignKey) {
1170
            $inflector = Inflector::get();
1171
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1172
        }
1173
1174
        if (!$localKey) {
1175
            $localKey = self::DEFAULT_ID_PROPERTY;
1176
        }
1177
1178
        return new HasMany($model, $foreignKey, $localKey, $this);
1179
    }
1180
1181
    /**
1182
     * Creates the child side of a Many-To-Many relationship.
@@ 1190-1204 (lines=15) @@
1187
     *
1188
     * @return Relation
1189
     */
1190
    public function belongsToMany($model, $foreignKey = '', $localKey = '')
1191
    {
1192
        if (!$foreignKey) {
1193
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1194
        }
1195
1196
        // the default local key would look like `user_id`
1197
        // for a model named User
1198
        if (!$localKey) {
1199
            $inflector = Inflector::get();
1200
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1201
        }
1202
1203
        return new BelongsToMany($model, $foreignKey, $localKey, $this);
1204
    }
1205
1206
    /////////////////////////////
1207
    // Events