<commit_before><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014-2015 Elcodi.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author Elcodi Team <<EMAIL>>
 */

namespace Elcodi\Plugin\StripeBundle\EventListener;

use PaymentSuite\PaymentCoreBundle\Services\Interfaces\PaymentBridgeInterface;
use PaymentSuite\StripeBundle\Router\StripeRoutesLoader;
use PaymentSuite\StripeBundle\Twig\StripeExtension;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

use Elcodi\Component\Payment\Entity\PaymentMethod;
use Elcodi\Component\Payment\Event\PaymentCollectionEvent;
use Elcodi\Component\Plugin\Entity\Plugin;

/**
 * Class PaymentCollectEventListener
 */
class PaymentCollectEventListener
{
    /**
     * @var UrlGeneratorInterface
     *
     * Router
     */
    protected $router;

    /**
     * @var Plugin
     *
     * Plugin
     */
    protected $plugin;

    /**
     * @var StripeExtension
     *
     * Stripe twig extension.
     */
    protected $stripeTwigExtension;

    /**
     * @var FormFactory
     *
     * Form factory
     */
    protected $formFactory;

    /**
     * @var
     */
    protected $templating;

    /**
     * @var string
     *
     * Public key
     */
    private $publicKey;

    /**
     * @var PaymentBridgeInterface
     *
     * Currency wrapper
     */
    private $paymentBridgeInterface;

    /**
     * Construct
     *
     * @param UrlGeneratorInterface  $router                 Router
     * @param Plugin                 $plugin                 Plugin
     * @param string                 $publicKey              Public key
     * @param FormFactory            $formFactory            Form factory
     * @param PaymentBridgeInterface $paymentBridgeInterface Payment Bridge Interface
     */
    public function __construct(
        UrlGeneratorInterface $router,
        Plugin $plugin,
        $publicKey,
        FormFactory $formFactory,
        PaymentBridgeInterface $paymentBridgeInterface,
        EngineInterface $templating
    ) {
        $this->router = $router;
        $this->plugin = $plugin;
        $this->publicKey = $publicKey;
        $this->formFactory = $formFactory;
        $this->paymentBridgeInterface = $paymentBridgeInterface;
        $this->templating = $templating;
    }

    /**
     * Add Stripe payment method
     *
     * @param PaymentCollectionEvent $event Event
     */
    public function addStripePaymentMethod(PaymentCollectionEvent $event)
    {
        if ($this
            ->plugin
            ->isUsable([
                'private_key',
                'public_key',
            ])
        ) {
            $stripeForm = $this->getStripeForm() . $this->getStripeScript();

            $stripe = new PaymentMethod(
                $this
                    ->plugin
                    ->getHash(),
                'elcodi_plugin.stripe.name',
                'elcodi_plugin.stripe.description',
                '',
                '',
                $stripeForm
            );

            $event->addPaymentMethod($stripe);
        }
    }

    protected function getStripeForm()
    {
        $formType = $this->formFactory->create('stripe_view');

        return $this->templating->render('StripeBundle:Stripe:view.html.twig', [
            'stripe_form'  =>  $formType->createView(),
            'stripe_execute_route' =>  StripeRoutesLoader::ROUTE_NAME,
        ]);
    }

    protected function getStripeScript()
    {
        return $this->templating->render('StripeBundle:Stripe:scripts.html.twig', [
            'public_key'    =>  $this->publicKey,
            'currency'      =>  $this->paymentBridgeInterface->getCurrency(),
        ]);
    }
}
<commit_msg>Fixes #571 Updated PHPDoc and improved format<commit_after><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014-2015 Elco<EMAIL>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author Elcodi Team <<EMAIL>>
 */

namespace Elcodi\Plugin\StripeBundle\EventListener;

use PaymentSuite\PaymentCoreBundle\Services\Interfaces\PaymentBridgeInterface;
use PaymentSuite\StripeBundle\Router\StripeRoutesLoader;
use PaymentSuite\StripeBundle\Twig\StripeExtension;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

use Elcodi\Component\Payment\Entity\PaymentMethod;
use Elcodi\Component\Payment\Event\PaymentCollectionEvent;
use Elcodi\Component\Plugin\Entity\Plugin;

/**
 * Class PaymentCollectEventListener
 */
class PaymentCollectEventListener
{
    /**
     * @var UrlGeneratorInterface
     *
     * Router
     */
    protected $router;

    /**
     * @var Plugin
     *
     * Plugin
     */
    protected $plugin;

    /**
     * @var StripeExtension
     *
     * Stripe twig extension.
     */
    protected $stripeTwigExtension;

    /**
     * @var FormFactory
     *
     * Form factory
     */
    protected $formFactory;

    /**
     * @var EngineInterface
     *
     * Templating
     */
    protected $templating;

    /**
     * @var string
     *
     * Public key
     */
    private $publicKey;

    /**
     * @var PaymentBridgeInterface
     *
     * Currency wrapper
     */
    private $paymentBridgeInterface;

    /**
     * Construct
     *
     * @param UrlGeneratorInterface  $router                 Router
     * @param Plugin                 $plugin                 Plugin
     * @param string                 $publicKey              Public key
     * @param FormFactory            $formFactory            Form factory
     * @param PaymentBridgeInterface $paymentBridgeInterface Payment Bridge Interface
     */
    public function __construct(
        UrlGeneratorInterface $router,
        Plugin $plugin,
        $publicKey,
        FormFactory $formFactory,
        PaymentBridgeInterface $paymentBridgeInterface,
        EngineInterface $templating
    ) {
        $this->router = $router;
        $this->plugin = $plugin;
        $this->publicKey = $publicKey;
        $this->formFactory = $formFactory;
        $this->paymentBridgeInterface = $paymentBridgeInterface;
        $this->templating = $templating;
    }

    /**
     * Add Stripe payment method
     *
     * @param PaymentCollectionEvent $event Event
     */
    public function addStripePaymentMethod(PaymentCollectionEvent $event)
    {
        if ($this
            ->plugin
            ->isUsable([
                'private_key',
                'public_key',
            ])
        ) {
            $stripeForm = $this->getStripeForm() . $this->getStripeScript();

            $stripe = new PaymentMethod(
                $this
                    ->plugin
                    ->getHash(),
                'elcodi_plugin.stripe.name',
                'elcodi_plugin.stripe.description',
                '',
                '',
                $stripeForm
            );

            $event->addPaymentMethod($stripe);
        }
    }

    /**
     * Return stripe form
     *
     * @return string Stripe form
     */
    protected function getStripeForm()
    {
        $formType = $this
            ->formFactory
            ->create('stripe_view');

        return $this
            ->templating
            ->render('StripeBundle:Stripe:view.html.twig', [
                'stripe_form'  =>  $formType->createView(),
                'stripe_execute_route' =>  StripeRoutesLoader::ROUTE_NAME,
            ]);
    }

    /**
     * Return stripe script
     *
     * @return string Stripe script
     */
    protected function getStripeScript()
    {
        $currency = $this
            ->paymentBridgeInterface
            ->getCurrency();

        return $this
            ->templating
            ->render('StripeBundle:Stripe:scripts.html.twig', [
                'public_key'    =>  $this->publicKey,
                'currency'      =>  $currency,
            ]);
    }
}

{'fraction_non_alphanumeric': 0.10457671330329618, 'fraction_numerical': 0.0022527863410007113, 'mean_word_length': 1.932892906815021, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 74, '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': '6710437', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2304, 'n_words': 464}