<commit_before><?php

namespace App\Containers\AppSection\User\Actions;

use App\Containers\AppSection\Authentication\Tasks\CreateUserByCredentialsTask;
use App\Containers\AppSection\Authorization\Tasks\AssignRolesToUserTask;
use App\Containers\AppSection\User\Models\User;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Exceptions\Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

class CreateAdminAction extends Action
{
    /**
     * @throws CreateResourceFailedException
     * @throws Throwable
     */
    public function run(array $data): User
    {
        DB::beginTransaction();

        try {
            $admin = app(CreateUserByCredentialsTask::class)->run($data);
            app(AssignRolesToUserTask::class)->run($admin, [config('appSection-authorization.admin_role')]);
            $admin->email_verified_at = now();
            $admin->save();

            DB::commit();

            return $admin;
        } catch (Exception $exception) {
            DB::rollBack();

            throw $exception;
        }
    }
}<commit_msg>refactor<commit_after><?php

namespace App\Containers\AppSection\User\Actions;

use App\Containers\AppSection\Authentication\Tasks\CreateUserByCredentialsTask;
use App\Containers\AppSection\Authorization\Tasks\AssignRolesToUserTask;
use App\Containers\AppSection\User\Models\User;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Exceptions\Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

class CreateAdminAction extends Action
{
    /**
     * @throws CreateResourceFailedException
     * @throws Throwable
     */
    public function run(array $data): User
    {
        try {
            DB::beginTransaction();

            $admin = app(CreateUserByCredentialsTask::class)->run($data);
            app(AssignRolesToUserTask::class)->run($admin, [config('appSection-authorization.admin_role')]);
            $admin->email_verified_at = now();
            $admin->save();

            DB::commit();

            return $admin;
        } catch (Exception $exception) {
            DB::rollBack();

            throw $exception;
        }
    }
}
{'fraction_non_alphanumeric': 0.11916407292129835, 'fraction_numerical': 0.0, 'mean_word_length': 3.128440366972477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5998429', 'n_tokens_mistral': 630, 'n_tokens_neox': 638, 'n_words': 100}