<commit_before><?php namespace GeneaLabs\LaravelGovernor\Listeners;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
use GeneaLabs\LaravelGovernor\Role;

class CreatedListener
{
    /**
     * @SuppressWarnings(PHPMD.StaticAccess)
     */
    public function handle(string $event, array $models)
    {
        if (str_contains($event, "Hyn\Tenancy\Models\Website")
            || str_contains($event, "Hyn\Tenancy\Models\Hostname")
        ) {
            return;
        }

        collect($models)
            ->filter(function ($model) {
                return $model instanceof Model
                    && get_class($model) === config('genealabs-laravel-governor.models.auth');
            })
            ->each(function ($model) {
                try {
                    $model->roles()->attach('Member');
                } catch (Exception $exception) {
                    $roleClass = config("genealabs-laravel-governor.models.role");
                    (new $roleClass)->firstOrCreate([
                        'name' => 'Member',
                        'description' => 'Represents the baseline registered user. Customize permissions as best suits your site.',
                    ]);
                    $model->roles()->attach('Member');
                }
            });<commit_msg>Fix registration of new member<commit_after><?php namespace GeneaLabs\LaravelGovernor\Listeners;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
use GeneaLabs\LaravelGovernor\Role;

class CreatedListener
{
    /**
     * @SuppressWarnings(PHPMD.StaticAccess)
     */
    public function handle(string $event, array $models)
    {
        if (str_contains($event, "Hyn\Tenancy\Models\Website")
            || str_contains($event, "Hyn\Tenancy\Models\Hostname")
        ) {
            return;
        }

        collect($models)
            ->filter(function ($model) {
                return $model instanceof Model
                    && get_class($model) === config('genealabs-laravel-governor.models.auth');
            })
            ->each(function ($model) {
                try {
                    $model->roles()->syncWithoutDetaching('Member');
                } catch (Exception $exception) {
                    $roleClass = config("genealabs-laravel-governor.models.role");
                    (new $roleClass)->firstOrCreate([
                        'name' => 'Member',
                        'description' => 'Represents the baseline registered user. Customize permissions as best suits your site.',
                    ]);
                    $model->roles()->attach('Member');
                }
            });
{'fraction_non_alphanumeric': 0.12551058299294468, 'fraction_numerical': 0.0, 'mean_word_length': 1.7975077881619939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '502516', 'n_tokens_mistral': 712, 'n_tokens_neox': 689, 'n_words': 124}