<commit_before><?php


namespace Mishterk\WP\Tools\DB;


abstract class ModelBase {


	/** @var \wpdb */
	public $db;

	/** @var Adaptor */
	public $adaptor;

	/** @var bool Set this to true in your child class if you want to allow dropping of this table on plugin deactivation */
	public $drop_on_deactivation = false;

	/** @var string Table version. Use this for updating table schema */
	public $version = '0.0.1';


	/**
	 * Model constructor.
	 *
	 * @param array $dependencies Optional array for overriding default dependencies
	 */
	public function __construct( Array $dependencies = [] ) {
		global $wpdb;

		$dependencies = array_merge( [
			'db'      => '',
			'adaptor' => '',
		], $dependencies );

		$this->db      = $dependencies['db'] ?: $wpdb;
		$this->adaptor = $dependencies['adaptor'] ?: new Adaptor();
	}

	/**
	 * Must return the schema for this table (CREATE TABLE SQL Statement)
	 *
	 * @return mixed
	 */
	abstract function schema();


	/**
	 * Must return the table name without the prefix
	 *
	 * @return mixed
	 */
	abstract function table_name();


	/**
	 * Returns an associative array of columns and their formats. e.g; ['col_name' => '%s', 'col2_name' => '%d']
	 *
	 * @return array
	 */
	abstract function columns();


	/**
	 * If columns have defaults, the required format here is ['col_name' => 'default_val']
	 *
	 * @return array
	 */
	abstract function column_defaults();


	/**
	 * Returns an array containing the primary key. Multiple columns are supported for composite keys, but should be
	 * in order of their composition to ensure optimal query performance.
	 *
	 * @return string|array
	 */
	abstract function primary_key();


	/**
	 * Returns the full table name (with WP table prefix)
	 *
	 * @return string
	 */
	public function full_table_name() {
		return $this->db->prefix . $this->table_name();
	}


	/**
	 * Creates/updates the table using our adaptor's dbDelta()<commit_msg>A sensible note about setting defaults<commit_after><?php


namespace Mishterk\WP\Tools\DB;


abstract class ModelBase {


	/** @var \wpdb */
	public $db;

	/** @var Adaptor */
	public $adaptor;

	/** @var bool Set this to true in your child class if you want to allow dropping of this table on plugin deactivation */
	public $drop_on_deactivation = false;

	/** @var string Table version. Use this for updating table schema */
	public $version = '0.0.1';


	/**
	 * Model constructor.
	 *
	 * @param array $dependencies Optional array for overriding default dependencies
	 */
	public function __construct( Array $dependencies = [] ) {
		global $wpdb;

		$dependencies = array_merge( [
			'db'      => '',
			'adaptor' => '',
		], $dependencies );

		$this->db      = $dependencies['db'] ?: $wpdb;
		$this->adaptor = $dependencies['adaptor'] ?: new Adaptor();
	}

	/**
	 * Must return the schema for this table (CREATE TABLE SQL Statement)
	 *
	 * @return mixed
	 */
	abstract function schema();


	/**
	 * Must return the table name without the prefix
	 *
	 * @return mixed
	 */
	abstract function table_name();


	/**
	 * Returns an associative array of columns and their formats. e.g; ['col_name' => '%s', 'col2_name' => '%d']
	 *
	 * @return array
	 */
	abstract function columns();


	/**
	 * If columns have defaults, the required format here is ['col_name' => 'default_val']
	 *
	 * Note: if using the timestamp_field() method to generate a timestamp field in your model's schema, it's not
	 * necessary to set default values for that particular field.
	 *
	 * @return array
	 */
	abstract function column_defaults();


	/**
	 * Returns an array containing the primary key. Multiple columns are supported for composite keys, but should be
	 * in order of their composition to ensure optimal query performance.
	 *
	 * @return string|array
	 */
	abstract function primary_key();


	/**
	 * Returns the full table name (with WP table prefix)
	 *
	 * @return string
	 */
	public function full_table_name() {
		return $this->db->prefix . $this->table_name();
	}


	/**
	 * Creates/updates the table using our adaptor's dbDelta()
{'fraction_non_alphanumeric': 0.12663217541266322, 'fraction_numerical': 0.001970928800197093, 'mean_word_length': 3.2736842105263158, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '6841390', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1127, 'n_words': 434}