<commit_before><?php

namespace ShopwareAdapter\ResponseParser\Payment;

use Assert\Assertion;
use PlentyConnector\Connector\IdentityService\IdentityServiceInterface;
use PlentyConnector\Connector\TransferObject\Currency\Currency;
use PlentyConnector\Connector\TransferObject\Order\Order;
use PlentyConnector\Connector\TransferObject\Payment\Payment;
use PlentyConnector\Connector\TransferObject\PaymentMethod\PaymentMethod;
use Shopware\Models\Order\Status;
use Shopware\Models\Shop\Currency as CurrencyModel;
use ShopwareAdapter\ShopwareAdapter;

/**
 * Class PaymentResponseParser
 */
class PaymentResponseParser implements PaymentResponseParserInterface
{
    /**
     * @var IdentityServiceInterface
     */
    private $identityService;

    /**
     * OrderStatusResponseParser constructor.
     *
     * @param IdentityServiceInterface $identityService
     */
    public function __construct(IdentityServiceInterface $identityService)
    {
        $this->identityService = $identityService;
    }

    /**
     * @param int    $entry
     * @param string $type
     *
     * @return string
     */
    private function getIdentifier($entry, $type)
    {
        Assertion::integerish($entry);

        return $this->identityService->findOneOrThrow(
            (string) $entry,
            ShopwareAdapter::NAME,
            $type
        )->getObjectIdentifier();
    }

    /**
     * @param string $currency
     *
     * @return int
     */
    private function getCurrencyId($currency)
    {
        /**
         * @var ModelRepository $currencyRepo
         */
        $currencyRepo = Shopware()->Models()->getRepository(CurrencyModel::class);

        return $currencyRepo->findOneBy(['currency' => $currency])->getId();
    }

    /**
     * {@inheritdoc}
     */
    public function parse(array $element)
    {
        $payments = [];

        $paymentIdentifier = $this->identityService->findOneOrCreate(
            (string) $element['id'],
            ShopwareAdapter::NAME,
            Payment::TYPE
        )->getObjectIdentifier();

        $orderIdentifier = $this->getIdentifier($element['id'], Order::TYPE);

        $currencyIdentifier = $this->getIdentifier($this->getCurrencyId($element['currency']), Currency::TYPE);
        $paymentMethodIdentifier = $this->getIdentifier($element['paymentId'], PaymentMethod::TYPE);<commit_msg>fixed a missing use statement<commit_after><?php

namespace ShopwareAdapter\ResponseParser\Payment;

use Assert\Assertion;
use PlentyConnector\Connector\IdentityService\IdentityServiceInterface;
use PlentyConnector\Connector\TransferObject\Currency\Currency;
use PlentyConnector\Connector\TransferObject\Order\Order;
use PlentyConnector\Connector\TransferObject\Payment\Payment;
use PlentyConnector\Connector\TransferObject\PaymentMethod\PaymentMethod;
use Shopware\Components\Model\ModelRepository;
use Shopware\Models\Order\Status;
use Shopware\Models\Shop\Currency as CurrencyModel;
use ShopwareAdapter\ShopwareAdapter;

/**
 * Class PaymentResponseParser
 */
class PaymentResponseParser implements PaymentResponseParserInterface
{
    /**
     * @var IdentityServiceInterface
     */
    private $identityService;

    /**
     * OrderStatusResponseParser constructor.
     *
     * @param IdentityServiceInterface $identityService
     */
    public function __construct(IdentityServiceInterface $identityService)
    {
        $this->identityService = $identityService;
    }

    /**
     * @param int    $entry
     * @param string $type
     *
     * @return string
     */
    private function getIdentifier($entry, $type)
    {
        Assertion::integerish($entry);

        return $this->identityService->findOneOrThrow(
            (string) $entry,
            ShopwareAdapter::NAME,
            $type
        )->getObjectIdentifier();
    }

    /**
     * @param string $currency
     *
     * @return int
     */
    private function getCurrencyId($currency)
    {
        /**
         * @var ModelRepository $currencyRepository
         */
        $currencyRepository = Shopware()->Models()->getRepository(CurrencyModel::class);

        return $currencyRepository->findOneBy(['currency' => $currency])->getId();
    }

    /**
     * {@inheritdoc}
     */
    public function parse(array $element)
    {
        $payments = [];

        $paymentIdentifier = $this->identityService->findOneOrCreate(
            (string) $element['id'],
            ShopwareAdapter::NAME,
            Payment::TYPE
        )->getObjectIdentifier();

        $orderIdentifier = $this->getIdentifier($element['id'], Order::TYPE);

        $currencyIdentifier = $this->getIdentifier($this->getCurrencyId($element['currency']), Currency::TYPE);
        $paymentMethodIdentifier = $this->getIdentifier($element['paymentId'], PaymentMethod::TYPE);
{'fraction_non_alphanumeric': 0.11867582760774516, 'fraction_numerical': 0.0, 'mean_word_length': 3.1846689895470384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '983711', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1241, 'n_words': 209}