<commit_before><?php

namespace ETM\AppBundle\Converter;

use ETM\AppBundle\Types\BaseType;

class ObjectToArrayConverter implements ConverterInterface
{


    public function convert(BaseType $baseType)
    {

        $reflectionObject = new \ReflectionObject($baseType);

        return $this->handle($reflectionObject->getProperties(), $baseType);

    }

    protected function handle(array $properties, $object)
    {
        $resultArray = [];

        /** @var \ReflectionProperty[] $properties */
        foreach ($properties as $property) {

            $property->setAccessible(true);

            $value = $property->getValue($object);
            $keyName = $property->getName();

            if (is_object($value) && ! $value instanceof \DateTime) {

                $reflectionObject = new \ReflectionObject($value);
                $result = $this->handle($reflectionObject->getProperties(), $value);
                $resultArray[$keyName] = $result;

            } elseif (is_array($value)) {

                $result = [];

                foreach ($value as $obj) {
                    $reflectionObject = new \ReflectionObject($obj);
                    $result[] = $this->handle($reflectionObject->getProperties(), $obj);
                }

                $resultArray[$keyName] = $result;

            } else {
                $resultArray[$keyName] = $value;
            }
        }
        return $resultArray;
    }
}<commit_msg>[cs] Отформатировал код<commit_after><?php

namespace ETM\AppBundle\Converter;

use ETM\AppBundle\Types\BaseType;

class ObjectToArrayConverter implements ConverterInterface
{

    public function convert(BaseType $baseType)
    {

        $reflectionObject = new \ReflectionObject($baseType);

        return $this->handle($reflectionObject->getProperties(), $baseType);
    }

    protected function handle(array $properties, $object)
    {
        $resultArray = [];

        /** @var \ReflectionProperty[] $properties */
        foreach ($properties as $property) {

            $property->setAccessible(true);

            $value = $property->getValue($object);
            $keyName = $property->getName();

            if (is_object($value) && !$value instanceof \DateTime) {

                $reflectionObject = new \ReflectionObject($value);
                $result = $this->handle($reflectionObject->getProperties(), $value);
                $resultArray[$keyName] = $result;
            } elseif (is_array($value)) {

                $result = [];

                foreach ($value as $obj) {
                    $reflectionObject = new \ReflectionObject($obj);
                    $result[] = $this->handle($reflectionObject->getProperties(), $obj);
                }

                $resultArray[$keyName] = $result;
            } else {
                $resultArray[$keyName] = $value;
            }
        }
        return $resultArray;
    }
}
{'fraction_non_alphanumeric': 0.13182286302780638, 'fraction_numerical': 0.0, 'mean_word_length': 2.0738396624472575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3104238', 'n_tokens_mistral': 776, 'n_tokens_neox': 732, 'n_words': 142}