<commit_before><?php
require_once Mage::getBaseDir('lib') . '/Ebanx/vendor/autoload.php';

use Ebanx\Benjamin\Models\Address;
use Ebanx\Benjamin\Models\Card;
use Ebanx\Benjamin\Models\Item;
use Ebanx\Benjamin\Models\Payment;
use Ebanx\Benjamin\Models\Person;

class Ebanx_Gateway_Model_Adapters_Paymentadapter
{
	private $helper;

	public function __construct()
	{
		$this->helper = Mage::helper('ebanx');
	}

	public function transformCard(Varien_Object $data)
	{
		$gatewayFields = $data->getGatewayFields();
		$instalmentTerms = $data->getInstalmentTerms();

		$payment = $this->transform($data);

		$selectedCard = $gatewayFields['selected_card'];
		$payment->deviceId = $gatewayFields['ebanx_device_fingerprint'][$selectedCard];

		if (isset($gatewayFields['instalments'])) {
			$payment->instalments = $gatewayFields['instalments'];
			$term = $instalmentTerms[$gatewayFields['instalments'] - 1];
			$payment->amountTotal = $term->baseAmount * $term->instalmentNumber;
		}

		$code = $data->getPaymentType();

		$payment->card = new Card([
			'autoCapture' => true,
			'cvv' => $gatewayFields[$code . '_cid'][$selectedCard],
			'dueDate' => $this->transformDueDate($gatewayFields, $code),
			'name' => $gatewayFields[$code . '_name'][$selectedCard],
			'token' => $gatewayFields['ebanx_token'][$selectedCard],
			'type' => $gatewayFields['ebanx_brand'][$selectedCard],
		]);

		return $payment;
	}

	/**
	 * @param Varien_Object $data
	 * @return Payment
	 */
	public function transform(Varien_Object $data)
	{
		return new Payment([
			'type' => $data->getEbanxMethod(),
			'amountTotal' => $data->getAmountTotal(),
			'merchantPaymentCode' => $data->getMerchantPaymentCode(),
			'orderNumber' => $data->getOrderId(),
			'dueDate' => new \DateTime($data->getDueDate()),
			'address' => $this->transformAddress($data->getBillingAddress(), $data),
			'person' => $this->transformPerson($data->getPerson(), $data),
			'responsible' => $this->transformPerson($data->getPerson(), $data),
			'items' => $this->transformItems($data->getItems(), $data)
		]);
	}

	public function transformAddress($address, $data)
	{
		$street = $this->helper->split_street($address->getStreet1());

		return new Address([
			'address' => $street['streetName'],
			'streetNumber' => $street['houseNumber'],
			'city' => $address->getCity(),
			'country' => $this->helper->transformCountryCodeToName($address->getCountry()),
			'state' => $address->getRegion(),
			'streetComplement' => $address->getStreet2(),
			'zipcode' => $address->getPostcode()
		]);
	}

	public function transformPerson($person, $data)
	{
		$document = $this->helper->getDocumentNumber($data->getOrder(), $data);

		return new Person([
			'type' => $this->helper->getPersonType($document),
			'document' => $document,
			'email' => $person->getCustomerEmail(),
			'ip' => $data->getRemoteIp(),
			'name' => $person->getCustomerFirstname() . ' ' . $person->getCustomerLastname(),
			'phoneNumber' => $data->getBillingAddress()->getTelephone()
		]);
	}

	public function transformItems($items, $data)
	{
		$itemsData = [];

		foreach ($items as $item) {
			$product = $item->getProduct();

			$itemsData[] = new Item([
				'sku' => $item->getSku(),
				'name' => $item->getName(),
				'unitPrice' => $product->getPrice(),
				'quantity' => $item->getQtyToInvoice()
			]);
		}

		return $itemsData;
	}

	/**
	 * @param array $gatewayFields
	 * @param string $code
	 *
	 * @return bool|DateTime
	 */
	private function transformDueDate($gatewayFields, $code) {
		$month = $gatewayFields[ $code . '_exp_month' ] ?: 1;
		$year = $gatewayFields[ $code . '_exp_year' ] ?: 2120;

		return DateTime::createFromFormat( 'n-Y', $month . '-' . $year );
	}
}<commit_msg>Fixed one click php5.4 incompatibility<commit_after><?php
require_once Mage::getBaseDir('lib') . '/Ebanx/vendor/autoload.php';

use Ebanx\Benjamin\Models\Address;
use Ebanx\Benjamin\Models\Card;
use Ebanx\Benjamin\Models\Item;
use Ebanx\Benjamin\Models\Payment;
use Ebanx\Benjamin\Models\Person;

class Ebanx_Gateway_Model_Adapters_Paymentadapter
{
	private $helper;

	public function __construct()
	{
		$this->helper = Mage::helper('ebanx');
	}

	public function transformCard(Varien_Object $data)
	{
		$gatewayFields = $data->getGatewayFields();
		$instalmentTerms = $data->getInstalmentTerms();

		$payment = $this->transform($data);

		$selectedCard = $gatewayFields['selected_card'];
		$payment->deviceId = $gatewayFields['ebanx_device_fingerprint'][$selectedCard];

		if (isset($gatewayFields['instalments'])) {
			$payment->instalments = $gatewayFields['instalments'];
			$term = $instalmentTerms[$gatewayFields['instalments'] - 1];
			$payment->amountTotal = $term->baseAmount * $term->instalmentNumber;
		}

		$code = $data->getPaymentType();

		$payment->card = new Card([
			'autoCapture' => true,
			'cvv' => $gatewayFields[$code . '_cid'][$selectedCard],
			'dueDate' => $this->transformDueDate($gatewayFields, $code),
			'name' => $gatewayFields[$code . '_name'][$selectedCard],
			'token' => $gatewayFields['ebanx_token'][$selectedCard],
			'type' => $gatewayFields['ebanx_brand'][$selectedCard],
		]);

		return $payment;
	}

	/**
	 * @param Varien_Object $data
	 * @return Payment
	 */
	public function transform(Varien_Object $data)
	{
		return new Payment([
			'type' => $data->getEbanxMethod(),
			'amountTotal' => $data->getAmountTotal(),
			'merchantPaymentCode' => $data->getMerchantPaymentCode(),
			'orderNumber' => $data->getOrderId(),
			'dueDate' => new \DateTime($data->getDueDate()),
			'address' => $this->transformAddress($data->getBillingAddress(), $data),
			'person' => $this->transformPerson($data->getPerson(), $data),
			'responsible' => $this->transformPerson($data->getPerson(), $data),
			'items' => $this->transformItems($data->getItems(), $data)
		]);
	}

	public function transformAddress($address, $data)
	{
		$street = $this->helper->split_street($address->getStreet1());

		return new Address([
			'address' => $street['streetName'],
			'streetNumber' => $street['houseNumber'],
			'city' => $address->getCity(),
			'country' => $this->helper->transformCountryCodeToName($address->getCountry()),
			'state' => $address->getRegion(),
			'streetComplement' => $address->getStreet2(),
			'zipcode' => $address->getPostcode()
		]);
	}

	public function transformPerson($person, $data)
	{
		$document = $this->helper->getDocumentNumber($data->getOrder(), $data);

		return new Person([
			'type' => $this->helper->getPersonType($document),
			'document' => $document,
			'email' => $person->getCustomerEmail(),
			'ip' => $data->getRemoteIp(),
			'name' => $person->getCustomerFirstname() . ' ' . $person->getCustomerLastname(),
			'phoneNumber' => $data->getBillingAddress()->getTelephone()
		]);
	}

	public function transformItems($items, $data)
	{
		$itemsData = [];

		foreach ($items as $item) {
			$product = $item->getProduct();

			$itemsData[] = new Item([
				'sku' => $item->getSku(),
				'name' => $item->getName(),
				'unitPrice' => $product->getPrice(),
				'quantity' => $item->getQtyToInvoice()
			]);
		}

		return $itemsData;
	}

	/**
	 * @param array $gatewayFields
	 * @param string $code
	 *
	 * @return bool|DateTime
	 */
	private function transformDueDate($gatewayFields, $code) {
		$month = 1;
		if (array_key_exists($code . '_exp_month', $gatewayFields)) {
			$month = $gatewayFields[$code . '_exp_month'] ?: 1;
		}

		$year = 2120;
		if (array_key_exists($code . '_exp_month', $gatewayFields)) {
			$year = $gatewayFields[$code . '_exp_year'] ?: 2120;
		}

		return DateTime::createFromFormat( 'n-Y', $month . '-' . $year );
	}
}
{'fraction_non_alphanumeric': 0.1954521556256572, 'fraction_numerical': 0.0030231335436382754, 'mean_word_length': 4.912198912198912, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 169, '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': '1218621', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2543, 'n_words': 416}