<commit_before><?php
class AppDecorator implements IteratorAggregate, ArrayAccess, Countable /*, JsonSerializable /* PHP 5.4 */ {
    public $decorate = array(); // List of associations to decorate on instantiation
    public $children = array(); // Child nodes from threaded find results

    protected $attributes = array();
    protected $associations = array();
    public $serializableAttributes = null;
    public $serializableAssociations = null;

    private $modelName = null;
    private $isCollection = false;

    private static $_HtmlHelper = null;

    public function __construct($_attributes = null, $modelName = null) {
        if ($modelName) {
            $this->modelName = $modelName;
        }

        if ($_attributes) {
            $this->set($_attributes);
        }
    }

    public function count() {
        if ($this->isCollection) {
            return count($this->attributes);
        } else {
            return empty($this->attributes) ? 0 : 1;
        }
    }

    /**
     * @implements IteratorAggregate
     * @return ArrayIterator
     */
    public function getIterator() {
        return new ArrayIterator($this->attributes);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @param mixed $value
     */
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->attributes[] = $value;
        } else {
            $this->attributes[$offset] = $value;
        }
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @return bool
     */
    public function offsetExists($offset) {
        return isset($this->attributes[$offset]);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     */
    public function offsetUnset($offset) {
        unset($this->attributes[$offset]);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @return null
     */
    public function offsetGet($offset) {
        return isset($this->attributes[$offset]) ? $this->attributes[$offset] : null;
    }

    public function set($_attributes) {
        if (is_array($_attributes)) {
            if (array_key_exists($this->getModelName(), $_attributes)) {
                $modelAttributes = $_attributes[$this->getModelName()];
                unset($_attributes[$this->getModelName()]);

                // What remains must all be associations or 'children' (threaded results)
                $this->associations = $_attributes;
                $_attributes = $modelAttributes;
            } else {
                $decoratorClass = $this->getModelName() . 'Decorator';
                foreach ($_attributes as $key => $data) {
                    if (is_int($key) && is_array($data)) {
                        $this->isCollection = true;

                        if ( ! class_exists($decoratorClass)) {
                            App::uses($decoratorClass, 'Decorator');
                        }

                        if (class_exists($decoratorClass)) {
                            $_attributes[$key] = new $decoratorClass($data);
                        }
                    }
                }
            }
        }

        $this->attributes = $_attributes;

        foreach ($this->associations as $associationName => $values) {
            // Instantiate decorator for associated data
            if ( ! $this->decorateAssociation($associationName, false)) {
                // leave as array if no decorator is defined
                $this->$associationName = $values;
            }
        }

        // Decorate the association as requested by the parent decorator class
        foreach ($this->decorate as $associationName) {
            if ( ! isset($this->associations[$associationName])
                && isset($this->attributes[$associationName])) {
                $this->associations[$associationName] = $this->attributes[$associationName];
            }
            $this->decorateAssociation($associationName, false);
        }
    }

    public function getModelName() {
        if ($this->modelName) {<commit_msg>Decorate a collection with AppDecorator when there is no model-specific decorator<commit_after><?php
class AppDecorator implements IteratorAggregate, ArrayAccess, Countable /*, JsonSerializable /* PHP 5.4 */ {
    public $decorate = array(); // List of associations to decorate on instantiation
    public $children = array(); // Child nodes from threaded find results

    protected $attributes = array();
    protected $associations = array();
    public $serializableAttributes = null;
    public $serializableAssociations = null;

    private $modelName = null;
    private $isCollection = false;

    private static $_HtmlHelper = null;

    public function __construct($_attributes = null, $modelName = null) {
        if ($modelName) {
            $this->modelName = $modelName;
        }

        if ($_attributes) {
            $this->set($_attributes);
        }
    }

    public function count() {
        if ($this->isCollection) {
            return count($this->attributes);
        } else {
            return empty($this->attributes) ? 0 : 1;
        }
    }

    /**
     * @implements IteratorAggregate
     * @return ArrayIterator
     */
    public function getIterator() {
        return new ArrayIterator($this->attributes);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @param mixed $value
     */
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->attributes[] = $value;
        } else {
            $this->attributes[$offset] = $value;
        }
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @return bool
     */
    public function offsetExists($offset) {
        return isset($this->attributes[$offset]);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     */
    public function offsetUnset($offset) {
        unset($this->attributes[$offset]);
    }

    /**
     * @implements ArrayAccess
     * @param mixed $offset
     * @return null
     */
    public function offsetGet($offset) {
        return isset($this->attributes[$offset]) ? $this->attributes[$offset] : null;
    }

    public function set($_attributes) {
        if (is_array($_attributes)) {
            if (array_key_exists($this->getModelName(), $_attributes)) {
                $modelAttributes = $_attributes[$this->getModelName()];
                unset($_attributes[$this->getModelName()]);

                // What remains must all be associations or 'children' (threaded results)
                $this->associations = $_attributes;
                $_attributes = $modelAttributes;
            } else {
                $decoratorClass = $this->getModelName() . 'Decorator';
                foreach ($_attributes as $key => $data) {
                    if (is_int($key) && is_array($data)) {
                        $this->isCollection = true;

                        if ( ! class_exists($decoratorClass)) {
                            App::uses($decoratorClass, 'Decorator');
                        }

                        if (class_exists($decoratorClass)) {
                            $_attributes[$key] = new $decoratorClass($data);
                        } else {
                            $_attributes[$key] = new AppDecorator($data, $this->getModelName());
                        }
                    }
                }
            }
        }

        $this->attributes = $_attributes;

        foreach ($this->associations as $associationName => $values) {
            // Instantiate decorator for associated data
            if ( ! $this->decorateAssociation($associationName, false)) {
                // leave as array if no decorator is defined
                $this->$associationName = $values;
            }
        }

        // Decorate the association as requested by the parent decorator class
        foreach ($this->decorate as $associationName) {
            if ( ! isset($this->associations[$associationName])
                && isset($this->attributes[$associationName])) {
                $this->associations[$associationName] = $this->attributes[$associationName];
            }
            $this->decorateAssociation($associationName, false);
        }
    }

    public function getModelName() {
        if ($this->modelName) {
{'fraction_non_alphanumeric': 0.12144212523719165, 'fraction_numerical': 0.0009487666034155598, 'mean_word_length': 1.890983887555708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, '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': '4177752', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2090, 'n_words': 493}