<?php

namespace CouponsPlus\App\Handlers;

use Exception;
use CouponsPlus\Original\Environment\Env;
use CouponsPlus\Original\Events\Handler\EventHandler;

use function foo\func;

Class ErrorThrowerOnDevelopmentHandler extends EventHandler
{
    protected $numberOfArguments = 1;
    protected $priority = 10;

    /**
     * @throws Exception
     */
    public function execute()
    {
        /**
         * Causes issue on the frontend, only used in specific parts of the dev env
         */
        return;
        if (Env::settings()->environment !== 'development') {
            return;
        }


        /**
         * This is dev, let's break it if on a front-end or back-end page
         */
        if ((function_exists('get_current_screen') && get_current_screen()) || is_page()) {
            return ;
        }

        add_filter(
            'woocommerce_coupon_error', function (string $message) {

            throw new \Exception(
                esc_html('Error thrown by woocommerce_coupon_error on development environment: ' . $message)
            );
        });
    }
}