<commit_before><?php

namespace App\Services\Configuration;

use App\Exceptions\ConfigurationException;
use App\Repositories\Contracts\SettingRepositoryContract;
use Illuminate\Auth\AuthManager;

class Manager {

	/**
	 * @var AuthManager
	 */
	protected $authManager;

	/**
	 * @var SettingRepositoryContract
	 */
	protected $settingsRepository;

	/**
	 * @param AuthManager $authManager
	 * @param SettingRepositoryContract $settingsRepository
	 */
	public function __construct(
		AuthManager $authManager,
		SettingRepositoryContract $settingsRepository
	) {
		$this->authManager = $authManager;
		$this->settingsRepository = $settingsRepository;
	}

	/**
	 * Returns given configuration unserialized option value or `null` if option was not found.
	 * @param string $key
	 * @return mixed|null
	 */
	public function getValueOrNull($key) {
		$guard = $this->authManager->guard();

		// check user preferences
		if ($guard->check()) {
			$value = $this->settingsRepository->getUserValueByKey($guard->id(), $key);

			if (!is_null($value)) {
				return $value;
			}
		}

		// check global settings
		return $this->settingsRepository->getValueByKey($key);
	}

	/**
	 * Returns given configuration unserialized option value or throws exception if option was not found.
	 * @param string $key
	 * @return mixed
	 * @throws ConfigurationException
	 */
	public function getValueOrFail($key) {
		$value = $this->getValueOrNull($key);

		if (is_null($value)) {
			throw new ConfigurationException('Configuration key not found: %s.', $key);
		}

		return $value;
	}

	/**
	 * Returns given configuration unserialized option value or default value if option was not found.
	 * @param string $key
	 * @return mixed
	 */
	public function getValueOrDefault($key) {
		$value = $this->getValueOrNull($key);

		if (is_null($value)) {
			return $this->getDefaultValue($key);
		} else {
			return $value;
		}
	}

	/**
	 * Returns option's default value.
	 * @param string $key
	 * @return mixed
	 */
	public function getDefaultValue($key) {
		// @todo

		if ($key === 'language') {
			return 'pl';
		}

		return 'asdf';
	}

}
<commit_msg>Add PHP7 type info.<commit_after><?php

namespace App\Services\Configuration;

use App\Exceptions\ConfigurationException;
use App\Repositories\Contracts\SettingRepositoryContract;
use Illuminate\Auth\AuthManager;

class Manager {

	/**
	 * @var AuthManager
	 */
	protected $authManager;

	/**
	 * @var SettingRepositoryContract
	 */
	protected $settingsRepository;

	/**
	 * @param AuthManager $authManager
	 * @param SettingRepositoryContract $settingsRepository
	 */
	public function __construct(
		AuthManager $authManager,
		SettingRepositoryContract $settingsRepository
	) {
		$this->authManager = $authManager;
		$this->settingsRepository = $settingsRepository;
	}

	/**
	 * Returns given configuration unserialized option value or `null` if option was not found.
	 * @param string $key
	 * @return mixed|null
	 */
	public function getValueOrNull(string $key) {
		$guard = $this->authManager->guard();

		// check user preferences
		if ($guard->check()) {
			$value = $this->settingsRepository->getUserValueByKey($guard->id(), $key);

			if (!is_null($value)) {
				return $value;
			}
		}

		// check global settings
		return $this->settingsRepository->getValueByKey($key);
	}

	/**
	 * Returns given configuration unserialized option value or throws exception if option was not found.
	 * @param string $key
	 * @return mixed
	 * @throws ConfigurationException
	 */
	public function getValueOrFail(string $key) {
		$value = $this->getValueOrNull($key);

		if (is_null($value)) {
			throw new ConfigurationException('Configuration key not found: %s.', $key);
		}

		return $value;
	}

	/**
	 * Returns given configuration unserialized option value or default value if option was not found.
	 * @param string $key
	 * @return mixed
	 */
	public function getValueOrDefault(string $key) {
		$value = $this->getValueOrNull($key);

		if (is_null($value)) {
			return $this->getDefaultValue($key);
		} else {
			return $value;
		}
	}

	/**
	 * Returns option's default value.
	 * @param string $key
	 * @return mixed
	 */
	public function getDefaultValue(string $key) {
		// @todo

		if ($key === 'language') {
			return 'pl';
		}

		return 'asdf';
	}

}

{'fraction_non_alphanumeric': 0.12879850397381953, 'fraction_numerical': 0.0002337540906965872, 'mean_word_length': 3.879133409350057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '5092747', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1236, 'n_words': 337}