Code Duplication    Length = 15-19 lines in 2 locations

src/HasStates.php 2 locations

@@ 92-110 (lines=19) @@
89
        }
90
    }
91
92
    public function scopeWhereState(Builder $builder, string $field, $states): Builder
93
    {
94
        self::getStateConfig();
95
96
        /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */
97
        $stateConfig = self::getStateConfig()[$field] ?? null;
98
99
        if (! $stateConfig) {
100
            throw InvalidConfig::unknownState($field, $this);
101
        }
102
103
        $abstractStateClass = $stateConfig->stateClass;
104
105
        $stateNames = collect((array) $states)->map(function ($state) use ($abstractStateClass) {
106
            return $abstractStateClass::resolveStateName($state);
107
        });
108
109
        return $builder->whereIn($field, $stateNames);
110
    }
111
112
    public function scopeWhereNotState(Builder $builder, string $field, $states): Builder
113
    {
@@ 112-126 (lines=15) @@
109
        return $builder->whereIn($field, $stateNames);
110
    }
111
112
    public function scopeWhereNotState(Builder $builder, string $field, $states): Builder
113
    {
114
        /** @var \Spatie\ModelStates\StateConfig|null $stateConfig */
115
        $stateConfig = self::getStateConfig()[$field] ?? null;
116
117
        if (! $stateConfig) {
118
            throw InvalidConfig::unknownState($field, $this);
119
        }
120
121
        $stateNames = collect((array) $states)->map(function ($state) use ($stateConfig) {
122
            return $stateConfig->stateClass::resolveStateName($state);
123
        });
124
125
        return $builder->whereNotIn($field, $stateNames);
126
    }
127
128
    /**
129
     * @param \Spatie\ModelStates\State|string $state