<commit_before><?php
/**
 * trait: Save
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Object;

use Cocur\Slugify\Slugify;
use Tigron\Skeleton\I18n\Language;

trait Slug {

	/**
	 * Generate a slug
	 *
	 * @access private
	 */
	private function generate_slug($append = 0, $unique = true) {
		$sluggable_field = 'name'; // default
		if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['sluggable'])) {
			$sluggable_field = self::$class_configuration['sluggable'];
		}

		if (isset($this->details[$sluggable_field])) {
			$name = $this->details[$sluggable_field];
		} elseif (isset(self::$object_text_fields) AND in_array('name', self::$object_text_fields)) {
			$key = 'text_' . \Skeleton\I18n\Config::$base_language . '_name';
			if (isset($this->$key) AND $this->$key != '') {
				$name = $this->$key;
			} else {
				throw new \Exception('No base found to generate slug');
			}
		} else {
			throw new Exception('No base found to generate slug');
		}

		if ($this->is_dirty($sluggable_field) === false) {
			return $this->details['slug'];
		}

		$slugify = new Slugify();
		$slug = $slugify->slugify($name);

		if ($unique === false) {
			return $slug;
		}

		if ($append != 0) {<commit_msg>Check if key exists before returning<commit_after><?php
/**
 * trait: Save
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Object;

use Cocur\Slugify\Slugify;
use Tigron\Skeleton\I18n\Language;

trait Slug {

	/**
	 * Generate a slug
	 *
	 * @access private
	 */
	private function generate_slug($append = 0, $unique = true) {
		$sluggable_field = 'name'; // default
		if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['sluggable'])) {
			$sluggable_field = self::$class_configuration['sluggable'];
		}

		if (isset($this->details[$sluggable_field])) {
			$name = $this->details[$sluggable_field];
		} elseif (isset(self::$object_text_fields) AND in_array('name', self::$object_text_fields)) {
			$key = 'text_' . \Skeleton\I18n\Config::$base_language . '_name';
			if (isset($this->$key) AND $this->$key != '') {
				$name = $this->$key;
			} else {
				throw new \Exception('No base found to generate slug');
			}
		} else {
			throw new Exception('No base found to generate slug');
		}

		if (isset($this->id) AND $this->is_dirty($sluggable_field) === false) {
			return $this->details['slug'];
		}

		$slugify = new Slugify();
		$slug = $slugify->slugify($name);

		if ($unique === false) {
			return $slug;
		}

		if ($append != 0) {
{'fraction_non_alphanumeric': 0.18735806207418623, 'fraction_numerical': 0.004542013626040878, 'mean_word_length': 4.053537284894838, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 38, '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': '6511994', 'n_tokens_mistral': 1024, 'n_tokens_neox': 939, 'n_words': 199}