HEX
Server: LiteSpeed
System: Linux eko108.isimtescil.net 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: uyarreklamcomtr (11202)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/GooglePriceConstraintValidator.php.tar
httpdocs/wp-content/plugins/google-listings-and-ads/src/Validator/GooglePriceConstraintValidator.php000064400000002765151547400120036376 0ustar00var/www/vhosts/uyarreklam.com.tr<?php
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;

use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\Price as GooglePrice;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

defined( 'ABSPATH' ) || exit;

/**
 * Class GooglePriceConstraintValidator
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
 */
class GooglePriceConstraintValidator extends ConstraintValidator {

	/**
	 * Checks if the passed value is valid.
	 *
	 * @param GooglePrice $value The value that should be validated
	 * @param Constraint  $constraint
	 *
	 * @throws UnexpectedTypeException If invalid constraint provided.
	 * @throws UnexpectedValueException If invalid value provided.
	 */
	public function validate( $value, Constraint $constraint ) {
		if ( ! $constraint instanceof GooglePriceConstraint ) {
			throw new UnexpectedTypeException( $constraint, GooglePriceConstraint::class );
		}

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

		if ( ! $value instanceof GooglePrice ) {
			throw new UnexpectedValueException( $value, GooglePrice::class );
		}

		if ( empty( $value->getValue() ) || empty( $value->getCurrency() ) ) {
			$this->context->buildViolation( $constraint->message )
							->atPath( 'value' )
							->addViolation();
		}
	}
}