<commit_before><?php

namespace Sonata\ProductBundle\Seo\Services;

use Sonata\SeoBundle\Seo\SeoPageInterface;
use Sonata\Component\Product\ProductInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Component\HttpFoundation\Request;

/**
 * TwitterService.
 *
 * @author     <NAME> <<EMAIL>>
 */
class Twitter implements ServiceInterface
{
    /**
     * @var Pool
     */
    protected $mediaPool;

    /**
     * @var Request
     */
    protected $request;

    /**
     * @param Pool    $mediaPool
     * @param Request $request
     */
    public function __construct(Pool $mediaPool, Request $request)
    {
        $this->mediaPool = $mediaPool;
        $this->request = $request;
    }

    /**
     * Add the meta information
     *
     * @param SeoPageInterface $seoPage
     * @param ProductInterface $product
     * @param string|null      $currency
     *
     * @return void
     */
    public function alterPage(SeoPageInterface $seoPage, ProductInterface $product, $currency = null)
    {
        $seoPage->addMeta('name', 'twitter:card', 'product')
            ->addMeta('name', 'twitter:site', $product->getName())
            ->addMeta('name', 'twitter:title', $product->getName())
            ->addMeta('name', 'twitter:description', substr($product->getDescription(), 0, 200));

        if (null !== $currency) {
            $seoPage->addMeta('name', 'twitter:label1', 'Price')
                ->addMeta('name', 'twitter:data1', sprintf('%.2f%s', $product->getPrice(), $currency))
                // TODO provide useful information
                ->addMeta('name', 'twitter:label2', 'Price')
                ->addMeta('name', 'twitter:data2', sprintf('%.2f%s', $product->getPrice(), $currency));
        }

        $seoPage->addMeta('name', 'twitter:domain', $this->request->getHost());

        // If a media is available, we add the image data
        if ($image = $product->getImage()) {
            $format = 'reference';
            $provider = $this->mediaPool->getProvider($image->getProviderName());

            $seoPage->addMeta('property', 'twitter:image:src', $provider->generatePublicUrl($image, $format));
        }
    }
}<commit_msg>SONATA-112 - Fixed invalid metadata values<commit_after><?php

namespace Sonata\ProductBundle\Seo\Services;

use Sonata\SeoBundle\Seo\SeoPageInterface;
use Sonata\Component\Product\ProductInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Component\HttpFoundation\Request;

/**
 * TwitterService.
 *
 * @author     <NAME> <<EMAIL>>
 */
class Twitter implements ServiceInterface
{
    /**
     * @var Pool
     */
    protected $mediaPool;

    /**
     * @var Request
     */
    protected $request;

    /**
     * @param Pool    $mediaPool
     * @param Request $request
     */
    public function __construct(Pool $mediaPool, Request $request)
    {
        $this->mediaPool = $mediaPool;
        $this->request = $request;
    }

    /**
     * Add the meta information
     *
     * @param SeoPageInterface $seoPage
     * @param ProductInterface $product
     * @param string|null      $currency
     *
     * @return void
     */
    public function alterPage(SeoPageInterface $seoPage, ProductInterface $product, $currency = null)
    {
        $seoPage->addMeta('name', 'twitter:card', 'product')
            ->addMeta('name', 'twitter:site', '@sonataproject')
            ->addMeta('name', 'twitter:creator', '@th0masr')
            ->addMeta('name', 'twitter:title', $product->getName())
            ->addMeta('name', 'twitter:description', substr($product->getDescription(), 0, 200));

        if (null !== $currency) {
            $seoPage->addMeta('name', 'twitter:label1', 'Price')
                ->addMeta('name', 'twitter:data1', sprintf('%.2f%s', $product->getPrice(), $currency))
                ->addMeta('name', 'twitter:label2', 'SKU')
                ->addMeta('name', 'twitter:data2', $product->getSku());
        }

        $seoPage->addMeta('name', 'twitter:domain', $this->request->getHost());

        // If a media is available, we add the image data
        if ($image = $product->getImage()) {
            $format = 'reference';
            $provider = $this->mediaPool->getProvider($image->getProviderName());

            $seoPage->addMeta('property', 'twitter:image:src', $provider->generatePublicUrl($image, $format));
        }
    }
}
{'fraction_non_alphanumeric': 0.16269477543538038, 'fraction_numerical': 0.005270394133822181, 'mean_word_length': 2.6835443037974684, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, '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': '4885749', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1258, 'n_words': 255}