<commit_before><?php
namespace Asgard\Entity\Properties;

class FileProperty extends \Asgard\Entity\Property {
	protected static $defaultExtensions = ['pdf', 'doc', 'jpg', 'jpeg', 'png', 'docx', 'gif', 'rtf', 'ppt', 'xls', 'zip', 'txt'];

	public function __construct($params) {
		$params['extensions'] = static::$defaultExtensions;
		parent::__construct($params);
	}

	public function getRules() {
		$rules = parent::getRules();
		$rules['isNull'] = function($input) {
			return !$input || $input->shouldDelete() || !$input->src();
		};
		if(!isset($rules['extension']))
			$rules['extension'] = $this->get('extensions');

		return $rules;
	}

	public function getSQLType() {
		if($this->multiple)
			return 'text';
		else
			return 'varchar(255)';
	}

	protected function _getDefault($entity=null) {
		if($this->multiple)
			return [];
		else
			return null;
	}

	protected function doSerialize($obj) {
		if(is_object($obj))
			return $obj->src();
	}

	protected function doUnserialize($str, $entity=null) {
		if(!$str || !file_exists($str))
			return null;
		$file = new \Asgard\Entity\File($str);
		$file->setWebDir($this->definition->getApp()['kernel']['webdir']);
		$file->setUrl($this->definition->getApp()['request']->url);
		$file->setDir($this->get('dir'));
		return $file;
	}

	public function doSet($val, $entity=null) {
		if(is_string($val) && $val !== null)
			$val = new \Asgard\Entity\File($val);<commit_msg>fixes for scrutinizer<commit_after><?php
namespace Asgard\Entity\Properties;

class FileProperty extends \Asgard\Entity\Property {
	protected static $defaultExtensions = ['pdf', 'doc', 'jpg', 'jpeg', 'png', 'docx', 'gif', 'rtf', 'ppt', 'xls', 'zip', 'txt'];

	public function __construct($params) {
		$params['extensions'] = static::$defaultExtensions;
		parent::__construct($params);
	}

	public function getRules() {
		$rules = parent::getRules();
		$rules['isNull'] = function($input) {
			return !$input || $input->shouldDelete() || !$input->src();
		};
		if(!isset($rules['extension']))
			$rules['extension'] = $this->get('extensions');

		return $rules;
	}

	public function getSQLType() {
		if($this->multiple)
			return 'text';
		else
			return 'varchar(255)';
	}

	protected function _getDefault() {
		return null;
	}

	protected function doSerialize($obj) {
		if(is_object($obj))
			return $obj->src();
	}

	protected function doUnserialize($str) {
		if(!$str || !file_exists($str))
			return null;
		$file = new \Asgard\Entity\File($str);
		$file->setWebDir($this->definition->getApp()['kernel']['webdir']);
		$file->setUrl($this->definition->getApp()['request']->url);
		$file->setDir($this->get('dir'));
		return $file;
	}

	public function doSet($val) {
		if(is_string($val) && $val !== null)
			$val = new \Asgard\Entity\File($val);
{'fraction_non_alphanumeric': 0.20923520923520925, 'fraction_numerical': 0.0021645021645021645, 'mean_word_length': 5.054585152838428, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '7457271', 'n_tokens_mistral': 1022, 'n_tokens_neox': 931, 'n_words': 182}