<commit_before><?php

namespace Spoort\Bundle\Symfony2EconomicBundle\Service;

use Spoort\Bundle\Symfony2EconomicBundle\Service\SoapApi as SoapApiService;
use Spoort\Bundle\Symfony2EconomicBundle\Entity\Creditor as CreditorEntity;
use Spoort\Bundle\Symfony2EconomicBundle\Entity\Handle\CreditorHandle as CreditorHandleEntity;

class Creditor
{
    /** @var SoapApiService $soapApiService */
    private $soapApiService;

    /**
     * Creditor constructor.
     * @param SoapApi $soapApiService
     */
    public function __construct(SoapApiService $soapApiService)
    {
        $this->soapApiService = $soapApiService;
    }

    /**
     * Returns handle for creditors with a given name
     * @param $name
     * @return CreditorHandleEntity|null
     */
    public function findCreditorByName($name)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_FindByName(['name' => $name]);

        return !empty((array) $result) ? new CreditorHandleEntity($result->Creditor_FindByEmailResult) : null;
    }

    /**
     * Returns handle for creditor with a given number
     * @param $number
     * @return CreditorHandleEntity
     */
    public function findCreditorByNumber($number)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_FindByNumber(['number' => $number]);

        return !empty((array) $result) ? new CreditorHandleEntity($result->Creditor_FindByNumberResult) : null;
    }

    /**
     * Return handles for all creditors
     * @return CreditorHandleEntity[]
     */
    public function findAllCreditors()
    {
        $results = [];
        $data = $this->soapApiService
            ->getConnection()
            ->Creditor_GetAll()
            ->Creditor_GetAllResult;

        if (!empty((array) $data)) {
            // It's a collection of objects
            foreach ($data->CreditorHandle as $d) {
                $results[] = new CreditorHandleEntity($d);
            }
        }

        return $results;
    }

    /**
     * Gets the "property" of a creditor
     * @param CreditorHandleEntity $creditorHandleEntity
     * @param $property
     * @return CreditorHandleEntity
     * @throws InvalidArgumentException
     */
    public function getCreditorProperty(CreditorHandleEntity $creditorHandleEntity, $property)
    {
        $propertyList = [
            CreditorEntity::CREDITOR_ADDRESS,
            CreditorEntity::CREDITOR_BANK_ACCOUNT,
            CreditorEntity::CREDITOR_CI_NUMBER,
            CreditorEntity::CREDITOR_CITY,
            CreditorEntity::CREDITOR_COUNTRY,
            CreditorEntity::CREDITOR_COUNTY,
            CreditorEntity::CREDITOR_EMAIL,
            CreditorEntity::CREDITOR_NAME,
        ];

        if (!in_array($property, $propertyList)) {
            throw new InvalidArgumentException('Provided property is not correct!');
        }

        $method = 'Creditor_Get' . $property;

        $data = $this->soapApiService
            ->getConnection()
            ->$method(['creditorHandle' => $creditorHandleEntity]);

        return !empty((array) $data) ? new CreditorHandleEntity($data->{'Creditor_Get' . $property . 'Result'}) : null;
    }

    /**
     * Creates a new creditor from a data object
     * @param CreditorEntity $creditorEntity
     * @return CreditorHandleEntity|null
     */
    public function createCreditor(CreditorEntity $creditorEntity)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_CreateFromData(['data' => $creditorEntity->asTerseAssociateArray()]);

        return !empty((array) $result) ? $result->Creditor_CreateFromDataResult : null;
    }

    /**
     * Updates a creditor from a data object
     * @param CreditorEntity $creditorEntity
     * @return CreditorHandleEntity|null
     */
    public function updateCreditor(CreditorEntity $creditorEntity)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_UpdateFromData(['data' => $creditorEntity->asTerseAssociateArray()]);

        return !empty((array) $result) ? $result->Creditor_CreateFromDataResult : null;
    }

    /**
     * Deletes a creditor
     * @param CreditorHandleEntity $creditorHandleEntity
     * @return null
     */
    public function deleteCreditor(CreditorHandleEntity $creditorHandleEntity)
    {

        return $this->soapApiService
            ->getConnection()<commit_msg>Update creditor update method<commit_after><?php

namespace Spoort\Bundle\Symfony2EconomicBundle\Service;

use Spoort\Bundle\Symfony2EconomicBundle\Service\SoapApi as SoapApiService;
use Spoort\Bundle\Symfony2EconomicBundle\Entity\Creditor as CreditorEntity;
use Spoort\Bundle\Symfony2EconomicBundle\Entity\Handle\CreditorHandle as CreditorHandleEntity;

class Creditor
{
    /** @var SoapApiService $soapApiService */
    private $soapApiService;

    /**
     * Creditor constructor.
     * @param SoapApi $soapApiService
     */
    public function __construct(SoapApiService $soapApiService)
    {
        $this->soapApiService = $soapApiService;
    }

    /**
     * Returns handle for creditors with a given name
     * @param $name
     * @return CreditorHandleEntity|null
     */
    public function findCreditorByName($name)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_FindByName(['name' => $name]);

        return !empty((array) $result) ? new CreditorHandleEntity($result->Creditor_FindByEmailResult) : null;
    }

    /**
     * Returns handle for creditor with a given number
     * @param $number
     * @return CreditorHandleEntity
     */
    public function findCreditorByNumber($number)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_FindByNumber(['number' => $number]);

        return !empty((array) $result) ? new CreditorHandleEntity($result->Creditor_FindByNumberResult) : null;
    }

    /**
     * Return handles for all creditors
     * @return CreditorHandleEntity[]
     */
    public function findAllCreditors()
    {
        $results = [];
        $data = $this->soapApiService
            ->getConnection()
            ->Creditor_GetAll()
            ->Creditor_GetAllResult;

        if (!empty((array) $data)) {
            // It's a collection of objects
            foreach ($data->CreditorHandle as $d) {
                $results[] = new CreditorHandleEntity($d);
            }
        }

        return $results;
    }

    /**
     * Gets the "property" of a creditor
     * @param CreditorHandleEntity $creditorHandleEntity
     * @param $property
     * @return CreditorHandleEntity
     * @throws InvalidArgumentException
     */
    public function getCreditorProperty(CreditorHandleEntity $creditorHandleEntity, $property)
    {
        $propertyList = [
            CreditorEntity::CREDITOR_ADDRESS,
            CreditorEntity::CREDITOR_BANK_ACCOUNT,
            CreditorEntity::CREDITOR_CI_NUMBER,
            CreditorEntity::CREDITOR_CITY,
            CreditorEntity::CREDITOR_COUNTRY,
            CreditorEntity::CREDITOR_COUNTY,
            CreditorEntity::CREDITOR_EMAIL,
            CreditorEntity::CREDITOR_NAME,
        ];

        if (!in_array($property, $propertyList)) {
            throw new InvalidArgumentException('Provided property is not correct!');
        }

        $method = 'Creditor_Get' . $property;

        $data = $this->soapApiService
            ->getConnection()
            ->$method(['creditorHandle' => $creditorHandleEntity]);

        return !empty((array) $data) ? new CreditorHandleEntity($data->{'Creditor_Get' . $property . 'Result'}) : null;
    }

    /**
     * Creates a new creditor from a data object
     * @param CreditorEntity $creditorEntity
     * @return CreditorHandleEntity|null
     */
    public function createCreditor(CreditorEntity $creditorEntity)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_CreateFromData(['data' => $creditorEntity->asTerseAssociateArray()]);

        return !empty((array) $result) ? $result->Creditor_CreateFromDataResult : null;
    }

    /**
     * Updates a creditor from a data object
     * @param CreditorEntity $creditorEntity
     * @return CreditorHandleEntity|null
     */
    public function updateCreditor(CreditorEntity $creditorEntity)
    {
        $result = $this->soapApiService
            ->getConnection()
            ->Creditor_UpdateFromData(['data' => $creditorEntity->asTerseAssociateArray()]);

        return !empty((array) $result) ? $result->Creditor_UpdateFromDataResult : null;
    }

    /**
     * Deletes a creditor
     * @param CreditorHandleEntity $creditorHandleEntity
     * @return null
     */
    public function deleteCreditor(CreditorHandleEntity $creditorHandleEntity)
    {

        return $this->soapApiService
            ->getConnection()
{'fraction_non_alphanumeric': 0.10671140939597315, 'fraction_numerical': 0.0008948545861297539, 'mean_word_length': 2.643439282803586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, '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': '1637047', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2439, 'n_words': 484}