<commit_before><?php
declare(strict_types=1);

namespace ManaPHP;

use ManaPHP\Exception\FileNotFoundException;
use ManaPHP\Exception\InvalidArgumentException;
use ManaPHP\Exception\InvalidValueException;

/**
 * @property-read \ManaPHP\AliasInterface $alias
 */
class Env extends Component implements EnvInterface
{
    protected string $file = '@config/.env';

    public function __construct(array $options = [])
    {
        if (isset($options['file'])) {
            $this->file = $options['file'];
        }
    }

    public function load(): static
    {
        $file = $this->alias->resolve($this->file);

        if (!str_contains($this->file, '://') && !is_file($file)) {
            throw new FileNotFoundException(['.env file is not found: :file', 'file' => $file]);
        }

        $lines = file($file, FILE_IGNORE_NEW_LINES);

        $count = count($lines);
        for ($i = 0; $i < $count; $i++) {
            $line = trim($lines[$i]);

            if ($line === '' || $line[0] === '#') {
                continue;
            }

            if ($pos = strpos($line, ' # ')) {
                $line = substr($line, 0, $pos);
            }
            if (str_starts_with($line, 'export ')) {<commit_msg>fix [EA] Foreach can probably be used instead (easier to read and support).<commit_after><?php
declare(strict_types=1);

namespace ManaPHP;

use ManaPHP\Exception\FileNotFoundException;
use ManaPHP\Exception\InvalidArgumentException;
use ManaPHP\Exception\InvalidValueException;

/**
 * @property-read \ManaPHP\AliasInterface $alias
 */
class Env extends Component implements EnvInterface
{
    protected string $file = '@config/.env';

    public function __construct(array $options = [])
    {
        if (isset($options['file'])) {
            $this->file = $options['file'];
        }
    }

    public function load(): static
    {
        $file = $this->alias->resolve($this->file);

        if (!str_contains($this->file, '://') && !is_file($file)) {
            throw new FileNotFoundException(['.env file is not found: :file', 'file' => $file]);
        }

        $lines = file($file, FILE_IGNORE_NEW_LINES);

        $count = count($lines);
        /** @noinspection ForeachInvariantsInspection */
        for ($i = 0; $i < $count; $i++) {
            $line = trim($lines[$i]);

            if ($line === '' || $line[0] === '#') {
                continue;
            }

            if ($pos = strpos($line, ' # ')) {
                $line = substr($line, 0, $pos);
            }
            if (str_starts_with($line, 'export ')) {
{'fraction_non_alphanumeric': 0.16854807318022577, 'fraction_numerical': 0.003114052160373686, 'mean_word_length': 2.3815789473684212, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3694808', 'n_tokens_mistral': 780, 'n_tokens_neox': 752, 'n_words': 168}