<commit_before><?php
/**
 * Database setting store.
 *
 * @author    MyBB Group
 * @version   2.0.0
 * @package   mybb/settings
 * @copyright Copyright (c) 2014, MyBB Group
 * @license   http://www.mybb.com/about/license GNU LESSER GENERAL PUBLIC LICENSE
 * @link      http://www.mybb.com
 */

namespace MyBB\Settings;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\JoinClause;

class DatabaseStore extends Store
{
	/**
	 * Database connection to use to load settings.
	 *
	 * @var ConnectionInterface $connection
	 */
	private $_connection;
	/**
	 * The name of the table to load settings from.
	 *
	 * @var string $_settingsTable
	 */
	private $_settingsTable;
	/**
	 * The name of the table to load setting values from.
	 *
	 * @var string $_settingsValueTable
	 */
	private $_settingsValueTable;

	/**
	 * @param Guard               $guard              Laravel guard instance, used to get user settings.
	 * @param ConnectionInterface $connection         Database connection to use to manage settings.
	 * @param string              $settingsTable      The name of the main settings table.
	 * @param string              $settingsValueTable The name of the setting values table.
	 */
	public function __construct(
		Guard $guard,
		ConnectionInterface $connection,
		$settingsTable = 'settings',
		$settingsValueTable = 'setting_values'
	) {
		parent::__construct($guard);

		$this->_connection = $connection;
		$this->_settingsTable = $settingsTable;
		$this->_settingsValueTable = $settingsValueTable;
	}

	/**
	 * Flush all setting changes to the backing store.
	 *
	 * @param array $settings     The setting data to flush to the backing store.
	 * @param array $userSettings The user setting data to flush to the backing store.
	 * @param int   $userId       The ID of the user to save the user settings for.
	 *
	 * @return bool Whether the settings were flushed correctly.
	 */
	protected function flush(array $settings, array $userSettings, $userId = -1)
	{
		if ($userId > 0) {
			$this->flushUserSettings($userSettings, $userId);
		}


	}

	/**
	 * Flush the user settings to the database.
	 *
	 * @param array $userSettings The user settings to flush.
	 * @param int   $userId The ID of the user to flush the settings for.
	 */
	private function flushUserSettings(array $userSettings, $userId = -1)
	{
		// TODO: Persist user settings
	}

	/**
	 * Load all settings into the setting store.
	 *
	 * @return array An array of all of the loaded settings.
	 */
	protected function loadSettings()
	{
		$settings = $this->_connection->table($this->_settingsTable)
		                              ->join($this->_settingsValueTable, $this->_settingsTable . '.id', '=',
		                                     $this->_settingsValueTable . '.setting_id')
		                              ->select([
			                                       $this->_settingsTable . '.package',
			                                       $this->_settingsTable . '.name',
			                                       $this->_settingsValueTable . '.value'
		                                       ])
		                              ->where('is_user_setting', '=', false)
		                              ->get();

		$settingsArray = [];

		foreach ($settings as $setting) {
			array_set($settingsArray, $setting->package . '.' . $setting->name, $setting->value);
		}

		return $settingsArray;
	}

	/**
	 * Load all of the user settings into the setting store.
	 *
	 * @param int $userId The ID of the user to load the user settings for.
	 *
	 * @return array An array of all of the loaded user settings.
	 */
	protected function loadUserSettings($userId = -1)
	{
		if ($userId > 0) {
			$settings = $this->_connection->table($this->_settingsTable)
			                              ->join($this->_settingsValueTable, function (JoinClause $join) use ($userId) {
				                              $join->on($this->_settingsTable . '.id', '=',
				                                        $this->_settingsValueTable . '.setting_id')
				                                   ->where($this->_settingsValueTable . '.user_id', '=', $userId)
				                                   ->where($this->_settingsTable . '.is_user_setting', '=', true);
			                              })
			                              ->select([
				                                       $this->_settingsTable . '.package',
				                                       $this->_settingsTable . '.name',
				                                       $this->_settingsValueTable . '.value'
			                                       ])
			                              ->get();

			$settingsArray = [];

			foreach ($settings as $setting) {
				array_set($settingsArray, $setting->package . '.' . $setting->name, $setting->value);
			}

			return $settingsArray;
		}
	}
}
<commit_msg>Fixed loading of settings to return array<commit_after><?php
/**
 * Database setting store.
 *
 * @author    <NAME>
 * @version   2.0.0
 * @package   mybb/settings
 * @copyright Copyright (c) 2014, MyBB Group
 * @license   http://www.mybb.com/about/license GNU LESSER GENERAL PUBLIC LICENSE
 * @link      http://www.mybb.com
 */

namespace MyBB\Settings;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\JoinClause;

class DatabaseStore extends Store
{
	/**
	 * Database connection to use to load settings.
	 *
	 * @var ConnectionInterface $connection
	 */
	private $_connection;
	/**
	 * The name of the table to load settings from.
	 *
	 * @var string $_settingsTable
	 */
	private $_settingsTable;
	/**
	 * The name of the table to load setting values from.
	 *
	 * @var string $_settingsValueTable
	 */
	private $_settingsValueTable;

	/**
	 * @param Guard               $guard              Laravel guard instance, used to get user settings.
	 * @param ConnectionInterface $connection         Database connection to use to manage settings.
	 * @param string              $settingsTable      The name of the main settings table.
	 * @param string              $settingsValueTable The name of the setting values table.
	 */
	public function __construct(
		Guard $guard,
		ConnectionInterface $connection,
		$settingsTable = 'settings',
		$settingsValueTable = 'setting_values'
	) {
		parent::__construct($guard);

		$this->_connection = $connection;
		$this->_settingsTable = $settingsTable;
		$this->_settingsValueTable = $settingsValueTable;
	}

	/**
	 * Flush all setting changes to the backing store.
	 *
	 * @param array $settings     The setting data to flush to the backing store.
	 * @param array $userSettings The user setting data to flush to the backing store.
	 * @param int   $userId       The ID of the user to save the user settings for.
	 *
	 * @return bool Whether the settings were flushed correctly.
	 */
	protected function flush(array $settings, array $userSettings, $userId = -1)
	{
		if ($userId > 0) {
			$this->flushUserSettings($userSettings, $userId);
		}


	}

	/**
	 * Flush the user settings to the database.
	 *
	 * @param array $userSettings The user settings to flush.
	 * @param int   $userId The ID of the user to flush the settings for.
	 */
	private function flushUserSettings(array $userSettings, $userId = -1)
	{
		// TODO: Persist user settings
	}

	/**
	 * Load all settings into the setting store.
	 *
	 * @return array An array of all of the loaded settings.
	 */
	protected function loadSettings()
	{
		$settings = $this->_connection->table($this->_settingsTable)
		                              ->join($this->_settingsValueTable, $this->_settingsTable . '.id', '=',
		                                     $this->_settingsValueTable . '.setting_id')
		                              ->select([
			                                       $this->_settingsTable . '.package',
			                                       $this->_settingsTable . '.name',
			                                       $this->_settingsValueTable . '.value'
		                                       ])
		                              ->where('is_user_setting', '=', false)
		                              ->get();


		foreach ($settings as $setting) {
			array_set($this->_settings, $setting->package . '.' . $setting->name, $setting->value);
		}

		return $this->_settings;
	}

	/**
	 * Load all of the user settings into the setting store.
	 *
	 * @param int $userId The ID of the user to load the user settings for.
	 *
	 * @return array An array of all of the loaded user settings.
	 */
	protected function loadUserSettings($userId = -1)
	{
		if ($userId > 0) {
			$settings = $this->_connection->table($this->_settingsTable)
			                              ->join($this->_settingsValueTable, function (JoinClause $join) use ($userId) {
				                              $join->on($this->_settingsTable . '.id', '=',
				                                        $this->_settingsValueTable . '.setting_id')
				                                   ->where($this->_settingsValueTable . '.user_id', '=', $userId)
				                                   ->where($this->_settingsTable . '.is_user_setting', '=', true);
			                              })
			                              ->select([
				                                       $this->_settingsTable . '.package',
				                                       $this->_settingsTable . '.name',
				                                       $this->_settingsValueTable . '.value'
			                                       ])
			                              ->get();

			foreach ($settings as $setting) {
				array_set($this->_userSettings, $setting->package . '.' . $setting->name, $setting->value);
			}

			return $this->_userSettings;
		}
	}
}

{'fraction_non_alphanumeric': 0.11309157959434542, 'fraction_numerical': 0.002458512599877074, 'mean_word_length': 1.8563487419543592, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401493', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2429, 'n_words': 745}