Entities/Permissions/Model/PermissionsEntityMapper.php
public function create(string $title, ?string $description, ?array $roleIds, bool $active): int
    {
        // add top role if not already there, as it is assigned to all permissions
        if ($roleIds === null || !in_array(TOP_ROLE, $roleIds)) {
            $roleIds[] = (RolesTableMapper::getInstance())->getTopRoleId();
        }

        // insert administrator then administrator_roles in a transaction
        pg_query("BEGIN");

        try {
            $permissionId = $this->permissionsTableMapper->callInsert($title, $description, $active);
        } catch (Exceptions\QueryFailureException $e) {
            pg_query("ROLLBACK");
            throw $e;
        }

        try {
            $this->insertPermissionRoles((int) $permissionId, $roleIds);
        } catch (Exceptions\QueryFailureException $e) {
            pg_query("ROLLBACK");
            throw $e;
        }

        pg_query("COMMIT");
        return $permissionId;
    }
public function create(string $title, ?string $description, ?array $roleIds, bool $active): int
    {
        // add top role if not already there, as it is assigned to all permissions
        if ($roleIds === null || !in_array(TOP_ROLE, $roleIds)) {
            $roleIds[] = (RolesTableMapper::getInstance())->getTopRoleId();
        }

        // insert administrator then administrator_roles in a transaction
        pg_query("BEGIN");

        try {
            $permissionId = $this->permissionsTableMapper->callInsert($title, $description, $active);
        } catch (Exceptions\QueryFailureException $e) {
            pg_query("ROLLBACK");
            throw $e;
        }

        try {
            $this->insertPermissionRoles((int) $permissionId, $roleIds);
        } catch (Exceptions\QueryFailureException $e) {
            pg_query("ROLLBACK");
            throw $e;
        }

        pg_query("COMMIT");
        return $permissionId;
    }
any validation should be done prior