<commit_before><?php

/**
 *
 * Copyright (c) <NAME>
 *
 * For the full copyright and license information, please view the file license.md
 * that was distributed with this source code.
 *
 */

declare(strict_types = 1);

namespace WebLoader;


class FilesCollectionRender
{

	const
		LINK_ELEMENT = 'link',
		SCRIPT_ELEMENT = 'script',
		STYLE_ELEMENT = 'style';

	const
		LINK_PREFETCH = 'prefetch',
		LINK_PRELOAD = 'preload',
		LINK_PRELOAD_AS_CSS = 'style',
		LINK_PRELOAD_AS_JS = 'script';

	const
		SCRIPT_TYPE_ATTRIBUTE = 'text/javascript',
		STYLE_TYPE_ATTRIBUTE = 'text/css';

	const VERSION_MARK = '?v=';

	/**
	 * @var Compiler
	 */
	private $compiler;

	/**
	 * @var string
	 */
	private $basePath;

	/**
	 * @var string
	 */
	private $selectedCollectionName;

	/**
	 * @var string
	 */
	private $selectedPrefix;


	public function __construct(Compiler $compiler)
	{
		$this->compiler = $compiler;
		$this->basePath = $this->createBasePath($compiler->getDocumentRoot(), $compiler->getOutputDir());
	}


	public function css(string $collectionName = NULL, array $attributes = [], bool $loadContent = FALSE): string
	{
		$collection = $this->getSelectedCollection(Engine::CSS, $collectionName);
		$collectionName = $collection->getName();
		$this->compiler->compileFilesCollectionByType(Engine::CSS, $collectionName);
		$attributes = array_merge($attributes, $collection->getOutputElementAttributes());
		$attributes['type'] = self::STYLE_TYPE_ATTRIBUTE;
		$element = self::STYLE_ELEMENT;
		$basePath = $this->getCollectionBasePath($collectionName, Engine::CSS);
		$filePathParameter = NULL;

		if ($loadContent || $collection->isContentLoadingEnabled()) {
			$filePathParameter = $this->getCollectionFilePath($basePath);

		} else {
			$element = self::LINK_ELEMENT;
			$attributes['rel'] = 'stylesheet';
			$attributes['href'] = $this->addVersionTobasePath($basePath);
		}

		return $this->generateElement($element, $attributes, $filePathParameter);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function cssPrefetch($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements($collectionsNames, Engine::CSS, self::LINK_PREFETCH);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function cssPreload($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements(
			$collectionsNames, Engine::CSS, self::LINK_PRELOAD, self::LINK_PRELOAD_AS_CSS
		);
	}


	public function getCompiler(): Compiler
	{
		return $this->compiler;
	}


	public function js(string $collectionName = NULL, array $attributes = [], bool $loadContent = FALSE): string
	{
		$collection = $this->getSelectedCollection(Engine::JS, $collectionName);
		$collectionName = $collection->getName();
		$this->compiler->compileFilesCollectionByType(Engine::JS, $collectionName);
		$attributes = array_merge($attributes, $collection->getOutputElementAttributes());
		$attributes['type'] = self::SCRIPT_TYPE_ATTRIBUTE;
		$basePath = $this->getCollectionBasePath($collectionName, Engine::JS);
		$filePathParameter = NULL;

		if ($loadContent || $collection->isContentLoadingEnabled()) {
			$filePathParameter = $this->getCollectionFilePath($basePath);

		} else {
			$attributes['src'] = $this->addVersionToBasePath($basePath);
		}

		return $this->generateElement(self::SCRIPT_ELEMENT, $attributes, $filePathParameter);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function jsPrefetch($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements($collectionsNames, Engine::JS, self::LINK_PREFETCH);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function jsPreload($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements(
			$collectionsNames, Engine::JS, self::LINK_PRELOAD, self::LINK_PRELOAD_AS_JS
		);
	}


	public function selectCollection(string $collectionName): FilesCollectionRender
	{
		$this->selectedCollectionName = $collectionName;
		return $this;
	}


	public function setPrefix(string $prefix): FilesCollectionRender
	{
		$this->selectedPrefix = $prefix;
		return $this;
	}
<commit_msg>- Allowed nullable parameter for selectCollection and setPrefix methods<commit_after><?php

/**
 *
 * Copyright (c) <NAME>
 *
 * For the full copyright and license information, please view the file license.md
 * that was distributed with this source code.
 *
 */

declare(strict_types = 1);

namespace WebLoader;


class FilesCollectionRender
{

	const
		LINK_ELEMENT = 'link',
		SCRIPT_ELEMENT = 'script',
		STYLE_ELEMENT = 'style';

	const
		LINK_PREFETCH = 'prefetch',
		LINK_PRELOAD = 'preload',
		LINK_PRELOAD_AS_CSS = 'style',
		LINK_PRELOAD_AS_JS = 'script';

	const
		SCRIPT_TYPE_ATTRIBUTE = 'text/javascript',
		STYLE_TYPE_ATTRIBUTE = 'text/css';

	const VERSION_MARK = '?v=';

	/**
	 * @var Compiler
	 */
	private $compiler;

	/**
	 * @var string
	 */
	private $basePath;

	/**
	 * @var string
	 */
	private $selectedCollectionName;

	/**
	 * @var string
	 */
	private $selectedPrefix;


	public function __construct(Compiler $compiler)
	{
		$this->compiler = $compiler;
		$this->basePath = $this->createBasePath($compiler->getDocumentRoot(), $compiler->getOutputDir());
	}


	public function css(string $collectionName = NULL, array $attributes = [], bool $loadContent = FALSE): string
	{
		$collection = $this->getSelectedCollection(Engine::CSS, $collectionName);
		$collectionName = $collection->getName();
		$this->compiler->compileFilesCollectionByType(Engine::CSS, $collectionName);
		$attributes = array_merge($attributes, $collection->getOutputElementAttributes());
		$attributes['type'] = self::STYLE_TYPE_ATTRIBUTE;
		$element = self::STYLE_ELEMENT;
		$basePath = $this->getCollectionBasePath($collectionName, Engine::CSS);
		$filePathParameter = NULL;

		if ($loadContent || $collection->isContentLoadingEnabled()) {
			$filePathParameter = $this->getCollectionFilePath($basePath);

		} else {
			$element = self::LINK_ELEMENT;
			$attributes['rel'] = 'stylesheet';
			$attributes['href'] = $this->addVersionTobasePath($basePath);
		}

		return $this->generateElement($element, $attributes, $filePathParameter);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function cssPrefetch($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements($collectionsNames, Engine::CSS, self::LINK_PREFETCH);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function cssPreload($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements(
			$collectionsNames, Engine::CSS, self::LINK_PRELOAD, self::LINK_PRELOAD_AS_CSS
		);
	}


	public function getCompiler(): Compiler
	{
		return $this->compiler;
	}


	public function js(string $collectionName = NULL, array $attributes = [], bool $loadContent = FALSE): string
	{
		$collection = $this->getSelectedCollection(Engine::JS, $collectionName);
		$collectionName = $collection->getName();
		$this->compiler->compileFilesCollectionByType(Engine::JS, $collectionName);
		$attributes = array_merge($attributes, $collection->getOutputElementAttributes());
		$attributes['type'] = self::SCRIPT_TYPE_ATTRIBUTE;
		$basePath = $this->getCollectionBasePath($collectionName, Engine::JS);
		$filePathParameter = NULL;

		if ($loadContent || $collection->isContentLoadingEnabled()) {
			$filePathParameter = $this->getCollectionFilePath($basePath);

		} else {
			$attributes['src'] = $this->addVersionToBasePath($basePath);
		}

		return $this->generateElement(self::SCRIPT_ELEMENT, $attributes, $filePathParameter);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function jsPrefetch($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements($collectionsNames, Engine::JS, self::LINK_PREFETCH);
	}


	/**
	 * @param array|string|NULL $collectionsNames
	 * @return string
	 */
	public function jsPreload($collectionsNames = NULL): string
	{
		return $this->generateMetaLinkElements(
			$collectionsNames, Engine::JS, self::LINK_PRELOAD, self::LINK_PRELOAD_AS_JS
		);
	}


	public function selectCollection(string $collectionName = NULL): FilesCollectionRender
	{
		$this->selectedCollectionName = $collectionName;
		return $this;
	}


	public function setPrefix(string $prefix = NULL): FilesCollectionRender
	{
		$this->selectedPrefix = $prefix;
		return $this;
	}

{'fraction_non_alphanumeric': 0.13961420842154787, 'fraction_numerical': 0.0002352387673488591, 'mean_word_length': 5.345522388059702, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 69, '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': '2125186', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2545, 'n_words': 506}