<commit_before><?php
namespace FormKit;
use CascadingAttribute;

abstract class Element extends CascadingAttribute
{

    /**
     * @var array class name
     */
    public $class = array();



    /**
     * Children elements
     */
    public $children = array();


    /**
     * @var array id field
     */
    public $id = array();


    public function addClass($class)
    {
        $this->class[] = $class;
        return $this;
    }

    public function addId($id)
    {
        $this->id[] = $id;
        return $this;
    }

    public function addChild($child)
    {
        $this->children[] = $child;
        return $this;
    }

    protected function _renderChildren()
    {
        return join("\n",array_map(function($item) { 
            return $item->render() . PHP_EOL;
        }, $this->children ));
    }

    protected function _renderAttributes($keys) 
    {
        $html = '';
        foreach( $keys as $key ) {
            $val = $this->$key;
            if( $val ) {
                if( is_array($val) ) {
                    if( array_keys($val)===range(0, count($val)-1) )
                        $val = join(' ', $val);
                    else {
                        $val0 = $val;
                        $val = '';
                        foreach( $val0 as $name => $data )
                            $val .= "$name:$data;";
                    }
                }
                $html .= sprintf(' %s="%s"', 
                        $key, 
                        htmlspecialchars( is_array($val) ? join(' ',$val) : $val ) 
                    );
            }
        }
        return $html;
    }

    abstract public function render( $attributes = array() );

    public function __toString()
    {
<commit_msg>simplified the attribute render method<commit_after><?php
namespace FormKit;
use CascadingAttribute;

abstract class Element extends CascadingAttribute
{

    /**
     * @var array class name
     */
    public $class = array();



    /**
     * Children elements
     */
    public $children = array();


    /**
     * @var array id field
     */
    public $id = array();


    public function addClass($class)
    {
        $this->class[] = $class;
        return $this;
    }

    public function addId($id)
    {
        $this->id[] = $id;
        return $this;
    }

    public function addChild($child)
    {
        $this->children[] = $child;
        return $this;
    }

    protected function _renderChildren()
    {
        return join("\n",array_map(function($item) { 
            return $item->render() . PHP_EOL;
        }, $this->children ));
    }

    protected function _renderAttributes($keys) 
    {
        $html = '';
        foreach( $keys as $key ) {
            if( $val = $this->$key ) {
                if( is_array($val) ) {

                    // check if array is a indexed array, check keys of array[0..cnt] 
                    //
                    // if it's an indexed array
                    // for attributes like "class", which the parameter can be array('class1','class2')
                    // this render the attribute as "class1 class2"
                    //
                    // if it's an associative array
                    // for attribute "style", which the parameter can be array( 'border' => '1px solid #ccc' )
                    // this render the attribute as "border: 1px solid #ccc;"
                    if( array_keys($val) === range(0, count($val)-1) ) {
                        $val = join(' ', $val);
                    } else {
                        $val0 = $val;
                        $val = '';
                        foreach( $val0 as $name => $data ) {
                            $val .= "$name:$data;";
                        }
                    }
                }
                elseif ( is_bool($val) ) {
                    $val = $key;
                }

                // for boolean values like readonly attribute, 
                // we render it as readonly="readonly".
                $html .= sprintf(' %s="%s"', 
                        $key, 
                        htmlspecialchars( $val )
                );
            }
        }
        return $html;
    }

    abstract public function render( $attributes = array() );

    public function __toString()
    {

{'fraction_non_alphanumeric': 0.1287563569116967, 'fraction_numerical': 0.0034674063800277394, 'mean_word_length': 1.214431934493347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '4976046', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1113, 'n_words': 296}