Code Duplication    Length = 15-15 lines in 4 locations

src/Model.php 4 locations

@@ 1043-1057 (lines=15) @@
1040
     *
1041
     * @return Relation
1042
     */
1043
    public function hasOne($model, $foreignKey = '', $localKey = '')
1044
    {
1045
        // the default local key would look like `user_id`
1046
        // for a model named User
1047
        if (!$foreignKey) {
1048
            $inflector = Inflector::get();
1049
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1050
        }
1051
1052
        if (!$localKey) {
1053
            $localKey = self::DEFAULT_ID_PROPERTY;
1054
        }
1055
1056
        return new HasOne($model, $foreignKey, $localKey, $this);
1057
    }
1058
1059
    /**
1060
     * Creates the child side of a One-To-One or One-To-Many relationship.
@@ 1068-1082 (lines=15) @@
1065
     *
1066
     * @return Relation
1067
     */
1068
    public function belongsTo($model, $foreignKey = '', $localKey = '')
1069
    {
1070
        if (!$foreignKey) {
1071
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1072
        }
1073
1074
        // the default local key would look like `user_id`
1075
        // for a model named User
1076
        if (!$localKey) {
1077
            $inflector = Inflector::get();
1078
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1079
        }
1080
1081
        return new BelongsTo($model, $foreignKey, $localKey, $this);
1082
    }
1083
1084
    /**
1085
     * Creates the parent side of a Many-To-One or Many-To-Many relationship.
@@ 1093-1107 (lines=15) @@
1090
     *
1091
     * @return Relation
1092
     */
1093
    public function hasMany($model, $foreignKey = '', $localKey = '')
1094
    {
1095
        // the default local key would look like `user_id`
1096
        // for a model named User
1097
        if (!$foreignKey) {
1098
            $inflector = Inflector::get();
1099
            $foreignKey = strtolower($inflector->underscore(static::modelName())).'_id';
1100
        }
1101
1102
        if (!$localKey) {
1103
            $localKey = self::DEFAULT_ID_PROPERTY;
1104
        }
1105
1106
        return new HasMany($model, $foreignKey, $localKey, $this);
1107
    }
1108
1109
    /**
1110
     * Creates the child side of a Many-To-Many relationship.
@@ 1118-1132 (lines=15) @@
1115
     *
1116
     * @return Relation
1117
     */
1118
    public function belongsToMany($model, $foreignKey = '', $localKey = '')
1119
    {
1120
        if (!$foreignKey) {
1121
            $foreignKey = self::DEFAULT_ID_PROPERTY;
1122
        }
1123
1124
        // the default local key would look like `user_id`
1125
        // for a model named User
1126
        if (!$localKey) {
1127
            $inflector = Inflector::get();
1128
            $localKey = strtolower($inflector->underscore($model::modelName())).'_id';
1129
        }
1130
1131
        return new BelongsToMany($model, $foreignKey, $localKey, $this);
1132
    }
1133
1134
    /////////////////////////////
1135
    // Events