Code Duplication    Length = 15-19 lines in 2 locations

src/HasStates.php 2 locations

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