<commit_before><?php

namespace App\Content; 

use App\Content\FieldTypeColor;
use App\Content\FieldTypeDate;
use App\Content\FieldTypeTextfield;
use App\Content\FieldTypeTextarea;
use App\Content\FieldTypeAudio;
use App\Content\FieldTypeVideo;
use App\Content\FieldTypeImage;
use App\Content;
use Log;

class ContentType {

    const FIELD_TYPE_COLOR = 'color';
    const FIELD_TYPE_DATE = 'date';
    const FIELD_TYPE_TEXTFIELD = 'textfield';
    const FIELD_TYPE_TEXTAREA = 'textarea';
    const FIELD_TYPE_AUDIO = 'audio';
    const FIELD_TYPE_VIDEO = 'video';
    const FIELD_TYPE_IMAGE = 'image';

    private $fieldTypes;

    /**
     * Create a new content type instance.
     * Register field types.
     *
     * @return void
     */
    public function __construct() {

        $this->fieldTypes[ContentType::FIELD_TYPE_VIDEO] = new FieldTypeVideo('public/assets/user/video/');
        $this->fieldTypes[ContentType::FIELD_TYPE_AUDIO] = new FieldTypeAudio('public/assets/user/audio/');
        $this->fieldTypes[ContentType::FIELD_TYPE_IMAGE] = new FieldTypeImage('public/assets/user/image/');
        $this->fieldTypes[ContentType::FIELD_TYPE_COLOR] = new FieldTypeColor();
        $this->fieldTypes[ContentType::FIELD_TYPE_DATE] = new FieldTypeDate();
        $this->fieldTypes[ContentType::FIELD_TYPE_TEXTFIELD] = new FieldTypeTextfield();
        $this->fieldTypes[ContentType::FIELD_TYPE_TEXTAREA] = new FieldTypeTextarea();
    }


    /**
     * Process a theme.
     * 
     * @param Array $contenttype
     *
     * @return $vars
     */
    public function process($contenttype) {

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type'])) {

                $contenttype['#fields'][$field_id] = $this->fieldTypes[$properties['#type']]->process($field_id, $properties);

            } else {

                abort(404);
            }
        }

        return $contenttype;
    }


    /**
     * Get validation rules and messages for fields.
     * 
     * @param Request $request
     * @param Array $contenttype
     *
     * @return $validation_rules_messages
     */
    public function get_validation_rules_messages($request, $contenttype) {

        $validation_rules_messages = [
            'rules' => [], 
            'messages' => []
        ];

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type'])) {

                $validation_rules_messages = $this->fieldTypes[$properties['#type']]->get_validation_rules_messages($validation_rules_messages, $field_id, $properties);

            } else {

                abort(404);
            }
        }

        return $validation_rules_messages;
    }


    /**
     * Create entry, after validation of field values.
     * 
     * @param int $space_id
     * @param String $contenttype_key
     * @param Array $contenttype
     * @param Array $request_all
     *
     * @return content id 
     */
    public function create($space_id, $contenttype_key, $contenttype, $request_all) {

        $content = new Content;
        $content->space_id = $space_id;
        $content->key = $contenttype_key;        
        $content->weight = 0;
        $content->save();

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type']) && array_has($request_all, $field_id)) {

                $this->fieldTypes[$properties['#type']]->save($content->id, $field_id, $properties['#type'], $request_all[$field_id]);
            }
        }

        return $content->id;
    }


}
<commit_msg>bugfix: create instead of save<commit_after><?php

namespace App\Content; 

use App\Content\FieldTypeColor;
use App\Content\FieldTypeDate;
use App\Content\FieldTypeTextfield;
use App\Content\FieldTypeTextarea;
use App\Content\FieldTypeAudio;
use App\Content\FieldTypeVideo;
use App\Content\FieldTypeImage;
use App\Content;
use Log;

class ContentType {

    const FIELD_TYPE_COLOR = 'color';
    const FIELD_TYPE_DATE = 'date';
    const FIELD_TYPE_TEXTFIELD = 'textfield';
    const FIELD_TYPE_TEXTAREA = 'textarea';
    const FIELD_TYPE_AUDIO = 'audio';
    const FIELD_TYPE_VIDEO = 'video';
    const FIELD_TYPE_IMAGE = 'image';

    private $fieldTypes;

    /**
     * Create a new content type instance.
     * Register field types.
     *
     * @return void
     */
    public function __construct() {

        $this->fieldTypes[ContentType::FIELD_TYPE_VIDEO] = new FieldTypeVideo('public/assets/user/video/');
        $this->fieldTypes[ContentType::FIELD_TYPE_AUDIO] = new FieldTypeAudio('public/assets/user/audio/');
        $this->fieldTypes[ContentType::FIELD_TYPE_IMAGE] = new FieldTypeImage('public/assets/user/image/');
        $this->fieldTypes[ContentType::FIELD_TYPE_COLOR] = new FieldTypeColor();
        $this->fieldTypes[ContentType::FIELD_TYPE_DATE] = new FieldTypeDate();
        $this->fieldTypes[ContentType::FIELD_TYPE_TEXTFIELD] = new FieldTypeTextfield();
        $this->fieldTypes[ContentType::FIELD_TYPE_TEXTAREA] = new FieldTypeTextarea();
    }


    /**
     * Process a theme.
     * 
     * @param Array $contenttype
     *
     * @return $vars
     */
    public function process($contenttype) {

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type'])) {

                $contenttype['#fields'][$field_id] = $this->fieldTypes[$properties['#type']]->process($field_id, $properties);

            } else {

                abort(404);
            }
        }

        return $contenttype;
    }


    /**
     * Get validation rules and messages for fields.
     * 
     * @param Request $request
     * @param Array $contenttype
     *
     * @return $validation_rules_messages
     */
    public function get_validation_rules_messages($request, $contenttype) {

        $validation_rules_messages = [
            'rules' => [], 
            'messages' => []
        ];

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type'])) {

                $validation_rules_messages = $this->fieldTypes[$properties['#type']]->get_validation_rules_messages($validation_rules_messages, $field_id, $properties);

            } else {

                abort(404);
            }
        }

        return $validation_rules_messages;
    }


    /**
     * Create entry, after validation of field values.
     * 
     * @param int $space_id
     * @param String $contenttype_key
     * @param Array $contenttype
     * @param Array $request_all
     *
     * @return content id 
     */
    public function create($space_id, $contenttype_key, $contenttype, $request_all) {

        $content = new Content;
        $content->space_id = $space_id;
        $content->key = $contenttype_key;        
        $content->weight = 0;
        $content->save();

        foreach ($contenttype['#fields'] as $field_id => $properties) {

            if (array_has($this->fieldTypes, $properties['#type']) && array_has($request_all, $field_id)) {

                $this->fieldTypes[$properties['#type']]->create($content->id, $field_id, $properties['#type'], $request_all[$field_id]);
            }
        }

        return $content->id;
    }


}

{'fraction_non_alphanumeric': 0.13413157540696893, 'fraction_numerical': 0.0018834925332974573, 'mean_word_length': 2.7225838758137204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '4496925', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2150, 'n_words': 402}