<commit_before><?php

namespace LapaLabs\MediaBundle\Validator\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\UrlValidator;

/**
 * Class YouTubeResourceUrlValidator
 *
 * @author <NAME> <<EMAIL>>
 */
class YouTubeResourceUrlValidator extends UrlValidator
{
    /**
     * {@inheritdoc}
     */
    public function validate($value, Constraint $constraint)
    {
        $parsedUrl = parse_url($value);

        if (isset($parsedUrl['host'])) {
            parent::validate($value, $constraint);

            switch (strtolower($parsedUrl['host'])) {
                case 'youtube.com':
                case 'm.youtube.com':
                case 'www.youtube.com':
                    // https://www.youtube.com/watch?v=YKwDcLUXlvU

                    if (false
                        or false === isset($parsedUrl['query'])
                        or false === isset($parsedUrl['path'])
                        or 0 !== strcmp('/watch', $parsedUrl['path'])
                        or parse_str($parsedUrl['query'], $output)
                        or false === isset($output['v'])
                        or 11 !== strlen($output['v'])
                    ) {
                        $this->context->buildViolation($constraint->hostMessage)
                            ->setParameter('%host%', $this->formatValue($parsedUrl['host']))
                            ->addViolation();
                    }

                    break;
                case 'youtu.be':
                    // https://youtu.be/YKwDcLUXlvU<commit_msg>Ignore empty string or value validating<commit_after><?php

namespace LapaLabs\MediaBundle\Validator\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\UrlValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
 * Class YouTubeResourceUrlValidator
 *
 * @author <NAME> <<EMAIL>>
 */
class YouTubeResourceUrlValidator extends UrlValidator
{
    /**
     * {@inheritdoc}
     */
    public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof YouTubeResourceUrl) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\YouTubeResourceUrl');
        }

        if (null === $value) {
            return;
        }

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        $value = (string) $value;
        if ('' === $value) {
            return;
        }

        $parsedUrl = parse_url($value);
        if (isset($parsedUrl['host'])) {
            parent::validate($value, $constraint);

            switch (strtolower($parsedUrl['host'])) {
                case 'youtube.com':
                case 'm.youtube.com':
                case 'www.youtube.com':
                    // https://www.youtube.com/watch?v=YKwDcLUXlvU

                    if (false
                        or false === isset($parsedUrl['query'])
                        or false === isset($parsedUrl['path'])
                        or 0 !== strcmp('/watch', $parsedUrl['path'])
                        or parse_str($parsedUrl['query'], $output)
                        or false === isset($output['v'])
                        or 11 !== strlen($output['v'])
                    ) {
                        $this->context->buildViolation($constraint->hostMessage)
                            ->setParameter('%host%', $this->formatValue($parsedUrl['host']))
                            ->addViolation();
                    }

                    break;
                case 'youtu.be':
                    // https://youtu.be/YKwDcLUXlvU
{'fraction_non_alphanumeric': 0.1377564614974687, 'fraction_numerical': 0.0015987210231814548, 'mean_word_length': 1.689111747851003, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '5320624', 'n_tokens_mistral': 970, 'n_tokens_neox': 953, 'n_words': 165}