<commit_before><?php
/**
 * User: <NAME> <<EMAIL>>
 */

namespace Praxigento\Core\Rewrite\Framework\Reflection;

/**
 * Override "\Magento\Framework\Reflection\TypeProcessor" to add parsing of the annotated accessors (get/set methods) for MOBI app.
 */
class TypeProcessor
    extends \Magento\Framework\Reflection\TypeProcessor
{
    const PATTERN_METHOD_GET = "/\@method\s+(.+)\s+get(.+)\(\)/";
    /**
     * Full names of the types for the internal registry.
     */
    const TYPE_ARRAY_ITERATOR = '\ArrayIterator';

    /**
     * Add annotation processing for accessors (get/set methods).
     *
     * @param string $class
     * @return array
     */
    protected function _processComplexType($class)
    {
        /* run parent method to analyze coded methods */
        $result = parent::_processComplexType($class);
        /* this is parent code w/o processed coded methods with own code to process annotated */
        $typeName = $this->translateTypeName($class);
        if (!$this->isArrayType($class)) {
            $reflection = new \Zend\Code\Reflection\ClassReflection($class);
            $docBlock = $reflection->getDocBlock();
            if ($docBlock) {
                $docBlockLines = $docBlock->getContents();
                $docBlockLines = explode("\n", $docBlockLines);
                foreach ($docBlockLines as $line) {
                    if (preg_match(self::PATTERN_METHOD_GET, $line, $matches)) {
                        $attrRequired = true;
                        $attrType = $matches[1];
                        $attrName = lcfirst($matches[2]);
                        if (substr($attrType, -0, strlen('null'))) {
                            $attrType = str_replace('|null', '', $attrType);
                            $attrRequired = false;
                        }
                        /* see docs for \Magento\Framework\Reflection\TypeProcessor::$_types */
                        $this->_types[$typeName]['parameters'][$attrName] = [
                            'type' => $this->register($attrType),
                            'required' => $attrRequired,
                            'documentation' => 'this is annotated property (see MOBI-329).',
                        ];
                    }
                }
                $result = $this->_types[$typeName];
            }
        }
        return $result;
    }

    public function getTypeData($typeName)
    {
        if ($typeName == self::TYPE_ARRAY_ITERATOR) {
            $result = parent::getTypeData(\ArrayIterator::class);
        } else {
            $result = parent::getTypeData($typeName);
        }
        return $result;
    }

    /**
     * Expand number of simple classes.
     *
     * @param string $type
     * @return bool
     */
    public function isTypeSimple($type)
    {
        $result = parent::isTypeSimple($type);
        if ($type == self::TYPE_ARRAY_ITERATOR) {
            if (!isset($this->_types[\ArrayIterator::class])) {
                $this->_types[\ArrayIterator::class] = []; // class name w/o leading slash ('ArrayIterator')
            }
            $result = true;
        }
        return $result;
    }

    public function translateTypeName($class)
    {
        try {
            $result = parent::translateTypeName($class);
        } catch (\InvalidArgumentException $e) {
            if (preg_match('/\\\\?(Praxigento)\\\\([A-Za-z0-9]*)\\\\(.*)/', $class, $matches)) {
                $moduleNamespace = 'Praxigento';
                $moduleName = $matches[2];
                $typeNameParts = explode('\\', $matches[3]);
                $result = ucfirst($moduleNamespace . $moduleName . implode('', $typeNameParts));
            }
        }
        return $result;
    }

}<commit_msg>MOBI-383 - Class "\Praxigento\Odoo\Service\Replicate\Response\ShipmentTrackingSave" does not exist. Please note that namespace must be specified.<commit_after><?php
/**
 * User: <NAME> <<EMAIL>>
 */

namespace Praxigento\Core\Rewrite\Framework\Reflection;

use Zend\Code\Reflection\MethodReflection;

/**
 * Override "\Magento\Framework\Reflection\TypeProcessor" to add parsing of the annotated accessors (get/set methods) for MOBI app.
 */
class TypeProcessor
    extends \Magento\Framework\Reflection\TypeProcessor
{
    const PATTERN_METHOD_GET = "/\@method\s+(.+)\s+get(.+)\(\)\s*(.*)/";
    const PATTERN_NULL = '|null';
    const LEN_NULL = 5;
    const SKIP_DATA = 'getData';
    const SKIP_ITERATOR = 'getIterator';
    /**
     * Full names of the types for the internal registry.
     */
    const TYPE_ARRAY_ITERATOR = '\ArrayIterator';

    /** @inheritdoc */
    protected function _processComplexType($class)
    {
        /* run parent method to analyze coded methods */
        $result = parent::_processComplexType($class);
        /* this is parent code w/o processed coded methods with own code to process annotated */
        $typeName = $this->translateTypeName($class);
        if (!$this->isArrayType($class)) {
            $reflection = new \Zend\Code\Reflection\ClassReflection($class);
            $docBlock = $reflection->getDocBlock();
            if ($docBlock) {
                $docBlockLines = $docBlock->getContents();
                $docBlockLines = explode("\n", $docBlockLines);
                foreach ($docBlockLines as $line) {
                    if (preg_match(self::PATTERN_METHOD_GET, $line, $matches)) {
                        $attrRequired = true;
                        $attrType = $matches[1];
                        $attrName = lcfirst($matches[2]);
                        $documentation = $matches[3];
                        $lenType = strlen($attrType);
                        if (substr($attrType, $lenType - self::LEN_NULL) == self::PATTERN_NULL) {
                            $attrType = str_replace(self::PATTERN_NULL, '', $attrType);
                            $attrRequired = false;
                        }
                        /* see docs for \Magento\Framework\Reflection\TypeProcessor::$_types */
                        $this->_types[$typeName]['parameters'][$attrName] = [
                            'type' => $this->register($attrType),
                            'required' => $attrRequired,
                            'documentation' => $documentation,
                        ];
                    }
                }
                $result = $this->_types[$typeName];
            }
        }
        return $result;
    }

    /** @inheritdoc */
    protected function _processMethod(MethodReflection $methodReflection, $typeName)
    {
        /* skip basic methods of the DataObjects */
        $name = $methodReflection->getName();
        if ($name != self::SKIP_DATA && $name != self::SKIP_ITERATOR) {
            parent::_processMethod($methodReflection, $typeName);
        }
    }

//    /** @inheritdoc */
//    public function getTypeData($typeName)
//    {
//        if ($typeName == self::TYPE_ARRAY_ITERATOR) {
//            $result = parent::getTypeData(\ArrayIterator::class);
//        } else {
//            $result = parent::getTypeData($typeName);
//        }
//        return $result;
//    }

//    /** @inheritdoc */
//    public function isTypeSimple($type)
//    {
//        $result = parent::isTypeSimple($type);
//        if ($type == self::TYPE_ARRAY_ITERATOR) {
//            if (!isset($this->_types[\ArrayIterator::class])) {
//                $this->_types[\ArrayIterator::class] = []; // class name w/o leading slash ('ArrayIterator')
//            }
//            $result = true;
//        }
//        return $result;
//    }

    /** @inheritdoc */
    public function translateTypeName($class)
    {
        try {
            $result = parent::translateTypeName($class);
        } catch (\InvalidArgumentException $e) {
            if (preg_match('/\\\\?(Praxigento)\\\\([A-Za-z0-9]*)\\\\(.*)/', $class, $matches)) {
                $moduleNamespace = 'Praxigento';
                $moduleName = $matches[2];
                $typeNameParts = explode('\\', $matches[3]);
                $result = ucfirst($moduleNamespace . $moduleName . implode('', $typeNameParts));
            }
        }
        return $result;
    }
}
{'fraction_non_alphanumeric': 0.1443563148261135, 'fraction_numerical': 0.0025625381330079315, 'mean_word_length': 1.7944084555063076, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, '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': '7014', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2167, 'n_words': 443}