<commit_before><?php

/*
 * This file is part of the Behat Testwork.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Behat\Testwork\Call\Handler\Exception;

use Behat\Testwork\Call\Handler\ExceptionHandler;
use Throwable;

/**
 * Handles class not found exceptions.
 *
 * @see ExceptionHandler
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class ClassNotFoundHandler implements ExceptionHandler
{
    const PATTERN = "/^Class '([^']+)' not found$/";

    /**
     * {@inheritdoc}
     */
    final public function supportsException($exception)
    {
        if (!$exception instanceof Throwable) {
            return false;
        }

        return null !== $this->extractNonExistentClass($exception);
    }

    /**
     * {@inheritdoc}
     */
    final public function handleException($exception)
    {
        $this->handleNonExistentClass($this->extractNonExistentClass($exception));

        return $exception;
    }

    /**
     * Override to handle non-existent class name.
     *
     * @param string $class
     */
    abstract protected function handleNonExistentClass($class);

    /**
     * Extracts missing class name from the exception.
     *
     * @param Throwable $exception
     *
     * @return null|string
     */
    private function extractNonExistentClass(Throwable $exception)
    {
        if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) {
            return $matches[1];
        }

        return null;
    }
}<commit_msg>Switch to more specific Error in default exception handlers<commit_after><?php

/*
 * This file is part of the Behat Testwork.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Behat\Testwork\Call\Handler\Exception;

use Behat\Testwork\Call\Handler\ExceptionHandler;
use Error;

/**
 * Handles class not found exceptions.
 *
 * @see ExceptionHandler
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class ClassNotFoundHandler implements ExceptionHandler
{
    const PATTERN = "/^Class '([^']+)' not found$/";

    /**
     * {@inheritdoc}
     */
    final public function supportsException($exception)
    {
        if (!$exception instanceof Error) {
            return false;
        }

        return null !== $this->extractNonExistentClass($exception);
    }

    /**
     * {@inheritdoc}
     */
    final public function handleException($exception)
    {
        $this->handleNonExistentClass($this->extractNonExistentClass($exception));

        return $exception;
    }

    /**
     * Override to handle non-existent class name.
     *
     * @param string $class
     */
    abstract protected function handleNonExistentClass($class);

    /**
     * Extracts missing class name from the exception.
     *
     * @param Error $exception
     *
     * @return null|string
     */
    private function extractNonExistentClass(Error $exception)
    {
        if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) {
            return $matches[1];
        }

        return null;
    }
}
{'fraction_non_alphanumeric': 0.11972704714640199, 'fraction_numerical': 0.0012406947890818859, 'mean_word_length': 2.652321630804077, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '532898', 'n_tokens_mistral': 896, 'n_tokens_neox': 875, 'n_words': 242}