<commit_before><?php
namespace Pakettikauppa\Logistics\Helper;

use Magento\Checkout\Model\Cart;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function __construct(
        Cart $cart,
        \Magento\Backend\Model\Session\Quote $backendQuoteSession
    ) {
        $this->cart = $cart;
        $this->backendQuoteSession = $backendQuoteSession;
    }

    public function getCarrierCode($carrier, $name)
    {
        $carrier = preg_replace('/[^\00-\255]+/u', '', strtolower(preg_replace('/\s+/', '', $carrier)));
        $name = preg_replace('/[^\00-\255]+/u', '', strtolower(preg_replace('/\s+/', '', preg_replace('/\-/', '', $name))));
        $code = $carrier . '_' . $name;
        if ($code == 'posti_palautus') {
            return false;
        } else {
            return $code;
        }
    }

    public function getZip()
    {
        $zip_pickup = $this->cart->getQuote()->getData('pickuppoint_zip');
        $zip_shipping = $this->cart->getQuote()->getShippingAddress()->getPostcode();
        $zip_backend = $this->backendQuoteSession->getQuote()->getShippingAddress()->getPostcode();

        if ($zip_pickup) {
            return $zip_pickup;
        } elseif ($zip_shipping) {
            return $zip_shipping;
        } elseif ($zip_backend) {
            return $zip_backend;
        } else {
            return false;
        }
    }
    public function getPickupPointServiceCode($data, $provider)
    {
        $result = 0;
        foreach ($data as $d) {
            if ($d->service_provider == $provider) {
                if (count($d->additional_services)>0) {
                    foreach ($d->additional_services as $service) {
                        if ($service->service_code == '2106') {
                            $result = $d->shipping_method_code;
                            break;
                        }
                    }
                }
            }
        }
        return $result;
    }

    public function getMethod($code)
    {
        if (strpos($code, 'pktkppickuppoint') !== false) {
            return 'pktkppickuppoint';
        }
        if (strpos($code, 'pktkphomedelivery') !== false) {
            return 'pktkphomedelivery';
        }
    }<commit_msg>Refactoring getZip()<commit_after><?php
namespace Pakettikauppa\Logistics\Helper;

use Magento\Checkout\Model\Cart;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function __construct(
        Cart $cart,
        \Magento\Backend\Model\Session\Quote $backendQuoteSession
    ) {
        $this->cart = $cart;
        $this->backendQuoteSession = $backendQuoteSession;
    }

    public function getCarrierCode($carrier, $name)
    {
        $carrier = preg_replace('/[^\00-\255]+/u', '', strtolower(preg_replace('/\s+/', '', $carrier)));
        $name = preg_replace('/[^\00-\255]+/u', '', strtolower(preg_replace('/\s+/', '', preg_replace('/\-/', '', $name))));
        $code = $carrier . '_' . $name;
        if ($code == 'posti_palautus') {
            return false;
        } else {
            return $code;
        }
    }

    public function getZip()
    {
        $zip = false;

        if ($zip = $this->cart->getQuote()->getData('pickuppoint_zip')) {
            return $zip;
        } elseif ($zip = $this->cart->getQuote()->getShippingAddress()->getPostcode()) {
            return $zip;
        } elseif ($zip = $this->backendQuoteSession->getQuote()->getShippingAddress()->getPostcode()) {
            return $zip;
        }
        return $zip;
    }
    public function getPickupPointServiceCode($data, $provider)
    {
        $result = 0;
        foreach ($data as $d) {
            if ($d->service_provider == $provider) {
                if (count($d->additional_services)>0) {
                    foreach ($d->additional_services as $service) {
                        if ($service->service_code == '2106') {
                            $result = $d->shipping_method_code;
                            break;
                        }
                    }
                }
            }
        }
        return $result;
    }

    public function getMethod($code)
    {
        if (strpos($code, 'pktkppickuppoint') !== false) {
            return 'pktkppickuppoint';
        }
        if (strpos($code, 'pktkphomedelivery') !== false) {
            return 'pktkphomedelivery';
        }
    }
{'fraction_non_alphanumeric': 0.15178368552601681, 'fraction_numerical': 0.007271074755737333, 'mean_word_length': 1.819987187700192, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '7044425', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1284, 'n_words': 219}