<commit_before><?php

namespace NerdsAndCompany\Schematic\Models;

use Craft\FieldModel;
use Craft\FieldGroupModel;

/**
 * Schematic Assets Field Model.
 *
 * A schematic field model for mapping asset data
 *
 * @author    Nerds & Company
 * @copyright Copyright (c) 2015, Nerds & Company
 * @license   MIT
 *
 * @link      http://www.nerds.company
 */
class AssetsField extends Field
{
    /**
     * @param FieldModel $field
     * @param $includeContext
     *
     * @return array
     */
    public function getDefinition(FieldModel $field, $includeContext)
    {
        $definition = parent::getDefinition($field, $includeContext);
        $settings = $definition['settings'];

        $defaultUploadLocationSourceId = $settings['defaultUploadLocationSource'];
        $defaultUploadLocationSource = craft()->schematic_assets->getSourceTypeById($defaultUploadLocationSourceId);
        $settings['defaultUploadLocationSource'] = $defaultUploadLocationSource ?  $defaultUploadLocationSource->handle : '';

        $singleUploadLocationSourceId = $settings['singleUploadLocationSource'];
        $singleUploadLocationSource = craft()->schematic_assets->getSourceTypeById($singleUploadLocationSourceId);
        $settings['singleUploadLocationSource'] = $singleUploadLocationSource ? $singleUploadLocationSource->handle : '';

        $definition['settings'] = $settings;

        return $definition;
    }

    /**
     * @param array                $fieldDefinition
     * @param FieldModel           $field
     * @param string               $fieldHandle
     * @param FieldGroupModel|null $group
     */
    public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null)
    {
        parent::populate($fieldDefinition, $field, $fieldHandle, $group);

        $settings = $fieldDefinition['settings'];
        $defaultUploadLocationSourceId = $settings['defaultUploadLocationSource'];
        $defaultUploadLocationSource = craft()->schematic_assets->getSourceTypeByHandle($defaultUploadLocationSourceId);
        $settings['defaultUploadLocationSource'] = $defaultUploadLocationSource ?  $defaultUploadLocationSource->id : '';

        $singleUploadLocationSourceId = $settings['singleUploadLocationSource'];
        $singleUploadLocationSource = craft()->schematic_assets->getSourceTypeByHandle($singleUploadLocationSourceId);
        $settings['singleUploadLocationSource'] = $singleUploadLocationSource ? $singleUploadLocationSource->id : '';

        $field->settings = $settings;
    }
}<commit_msg>Use Craft::app() instead of craft() in assetfield model<commit_after><?php

namespace NerdsAndCompany\Schematic\Models;

use Craft\Craft;
use Craft\FieldModel;
use Craft\FieldGroupModel;

/**
 * Schematic Assets Field Model.
 *
 * A schematic field model for mapping asset data
 *
 * @author    Nerds & Company
 * @copyright Copyright (c) 2015, Nerds & Company
 * @license   MIT
 *
 * @link      http://www.nerds.company
 */
class AssetsField extends Field
{
    /**
     * @param FieldModel $field
     * @param $includeContext
     *
     * @return array
     */
    public function getDefinition(FieldModel $field, $includeContext)
    {
        $definition = parent::getDefinition($field, $includeContext);
        $settings = $definition['settings'];

        $defaultUploadLocationSourceId = $settings['defaultUploadLocationSource'];
        $defaultUploadLocationSource = Craft::app()->schematic_assets->getSourceTypeById($defaultUploadLocationSourceId);
        $settings['defaultUploadLocationSource'] = $defaultUploadLocationSource ?  $defaultUploadLocationSource->handle : '';

        $singleUploadLocationSourceId = $settings['singleUploadLocationSource'];
        $singleUploadLocationSource = Craft::app()->schematic_assets->getSourceTypeById($singleUploadLocationSourceId);
        $settings['singleUploadLocationSource'] = $singleUploadLocationSource ? $singleUploadLocationSource->handle : '';

        $definition['settings'] = $settings;

        return $definition;
    }

    /**
     * @param array                $fieldDefinition
     * @param FieldModel           $field
     * @param string               $fieldHandle
     * @param FieldGroupModel|null $group
     */
    public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null)
    {
        parent::populate($fieldDefinition, $field, $fieldHandle, $group);

        $settings = $fieldDefinition['settings'];
        $defaultUploadLocationSourceId = $settings['defaultUploadLocationSource'];
        $defaultUploadLocationSource = Craft::app()->schematic_assets->getSourceTypeByHandle($defaultUploadLocationSourceId);
        $settings['defaultUploadLocationSource'] = $defaultUploadLocationSource ?  $defaultUploadLocationSource->id : '';

        $singleUploadLocationSourceId = $settings['singleUploadLocationSource'];
        $singleUploadLocationSource = Craft::app()->schematic_assets->getSourceTypeByHandle($singleUploadLocationSourceId);
        $settings['singleUploadLocationSource'] = $singleUploadLocationSource ? $singleUploadLocationSource->id : '';

        $field->settings = $settings;
    }
}
{'fraction_non_alphanumeric': 0.11369310543499135, 'fraction_numerical': 0.0015363933166890724, 'mean_word_length': 4.061224489795919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5971996', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1276, 'n_words': 239}