Code Duplication    Length = 15-19 lines in 2 locations

src/HasStates.php 2 locations

@@ 107-125 (lines=19) @@
104
        }
105
    }
106
107
    public function scopeWhereState(Builder $builder, string $field, $states): Builder
108
    {
109
        self::getStateConfig();
110
111
        /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */
112
        $stateConfig = self::getStateConfig()[$field] ?? null;
113
114
        if (! $stateConfig) {
115
            throw InvalidConfig::unknownState($field, $this);
116
        }
117
118
        $abstractStateClass = $stateConfig->stateClass;
119
120
        $stateNames = collect((array) $states)->map(function ($state) use ($abstractStateClass) {
121
            return $abstractStateClass::resolveStateName($state);
122
        });
123
124
        return $builder->whereIn($field, $stateNames);
125
    }
126
127
    public function scopeWhereNotState(Builder $builder, string $field, $states): Builder
128
    {
@@ 127-141 (lines=15) @@
124
        return $builder->whereIn($field, $stateNames);
125
    }
126
127
    public function scopeWhereNotState(Builder $builder, string $field, $states): Builder
128
    {
129
        /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */
130
        $stateConfig = self::getStateConfig()[$field] ?? null;
131
132
        if (! $stateConfig) {
133
            throw InvalidConfig::unknownState($field, $this);
134
        }
135
136
        $stateNames = collect((array) $states)->map(function ($state) use ($stateConfig) {
137
            return $stateConfig->stateClass::resolveStateName($state);
138
        });
139
140
        return $builder->whereNotIn($field, $stateNames);
141
    }
142
143
    /**
144
     * @param \Spatie\ModelStates\State|string $state