<commit_before><?php
/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
*
* @link      https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license   https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/

namespace LooplineSystems\CloseIoApiWrapper\Library;

use Doctrine\Common\Inflector\Inflector;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\UndefinedMethodException;
use Zend\Filter\Word\UnderscoreToCamelCase;

trait ObjectHydrateHelperTrait
{

    /**
     * @param array $data
     * @param array $nestedObjects
     * @param array $method_mapper
     * @throws InvalidParamException
     * @throws UndefinedMethodException
     */
    public function hydrate(array $data, array $nestedObjects = [], array $method_mapper = [])
    {
        foreach ($data as $key => $value) {

            if (!$value) {
                continue;
            }

            if (!in_array($key, $nestedObjects)) {
                // get setter method for each key in data
                $setter = 'set' . Inflector::classify($key);
                if (method_exists($this, $setter)) {
                    $this->$setter($value);
                } else {
                    // check if setter method exists that doesn't match inflected filter format
                    if (in_array($setter, array_keys($method_mapper))) {
                        $this->$method_mapper[$setter]($value);
                    } else {
                        // value is not set - Entities should be extended if needed
                    }
                }
            } else {
                // try to hydrate the nested objects
                foreach ($nestedObjects as $currentNestedObject) {
                    // if empty then ignore
                    if (!empty($data[$currentNestedObject])) {
                        // if is not array then throw exception
                        if (is_array($data[$currentNestedObject])) {
                            // rename for clarity
                            $nestedObject = $data[$currentNestedObject];
                            $NestedObjectCollection = array();
                            foreach ($nestedObject as $nestedObjectArguments) {
                                $singluarizedName = Inflector::singularize($currentNestedObject);<commit_msg>Fix for PHP 7.1 behavior when calling variable functions<commit_after><?php
/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
*
* @link      https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license   https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/

namespace LooplineSystems\CloseIoApiWrapper\Library;

use Doctrine\Common\Inflector\Inflector;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\UndefinedMethodException;
use Zend\Filter\Word\UnderscoreToCamelCase;

trait ObjectHydrateHelperTrait
{

    /**
     * @param array $data
     * @param array $nestedObjects
     * @param array $method_mapper
     * @throws InvalidParamException
     * @throws UndefinedMethodException
     */
    public function hydrate(array $data, array $nestedObjects = [], array $method_mapper = [])
    {
        foreach ($data as $key => $value) {

            if (!$value) {
                continue;
            }

            if (!in_array($key, $nestedObjects)) {
                // get setter method for each key in data
                $setter = 'set' . Inflector::classify($key);
                if (method_exists($this, $setter)) {
                    $this->$setter($value);
                } else {
                    // check if setter method exists that doesn't match inflected filter format
                    if (in_array($setter, array_keys($method_mapper))) {
                        $this->{$method_mapper[$setter]}($value);
                    } else {
                        // value is not set - Entities should be extended if needed
                    }
                }
            } else {
                // try to hydrate the nested objects
                foreach ($nestedObjects as $currentNestedObject) {
                    // if empty then ignore
                    if (!empty($data[$currentNestedObject])) {
                        // if is not array then throw exception
                        if (is_array($data[$currentNestedObject])) {
                            // rename for clarity
                            $nestedObject = $data[$currentNestedObject];
                            $NestedObjectCollection = array();
                            foreach ($nestedObject as $nestedObjectArguments) {
                                $singluarizedName = Inflector::singularize($currentNestedObject);
{'fraction_non_alphanumeric': 0.09832595728304791, 'fraction_numerical': 0.0019241870309794113, 'mean_word_length': 1.8909899888765296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '5014321', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1279, 'n_words': 317}