<commit_before><?php

namespace Lazy\Environment;

use Lazy\Environment\Exception\Exception;

class Environment
{
    protected $data;
    protected $body;
    protected static $_body;

    public function __construct()
    {
        $this->data = [
            'serverVars'    => $_SERVER,
            'paramsGet'     => $_GET,
            'paramsPost'    => $_POST,
            'paramsFile'    => $_FILES,
            'paramsCookie'  => $_COOKIE,
            'params'        => [],
        ];

        $this->data['params'] = array_replace([], $_GET?: [], $_POST?: [], $_COOKIE?: []);

        if ('application/json' == $this->header('CONTENT_TYPE') || 'application/json' == $this->serverVar('CONTENT_TYPE')) {
            $body = $this->body()?: '{}';
            $this->params(json_decode($body, true));
        }
    }

    public function __call($method, $args)
    {
        if (!array_key_exists($method, $this->data)) {
            throw new Exception("Call undefined method $method");
        }

        $name = isset($args[0])? $args[0] : null;
        $value = isset($args[1])? $args[1] : null;
        $data = $this->data[$method];

        switch (count($args)) {
            case 0: return $data;
            case 1:
                if (is_array($name)) {
                    $this->data[$method] = array_replace($data, $name);
                    return $this;
                }
                if ('params' == $method) {
                    if (isset($data[$name])) {<commit_msg>fix env json data<commit_after><?php

namespace Lazy\Environment;

use Lazy\Environment\Exception\Exception;

class Environment
{
    protected $data;
    protected $body;
    protected static $_body;

    public function __construct()
    {
        $this->data = [
            'serverVars'    => $_SERVER,
            'paramsGet'     => $_GET,
            'paramsPost'    => $_POST,
            'paramsFile'    => $_FILES,
            'paramsCookie'  => $_COOKIE,
            'params'        => [],
        ];

        $this->data['params'] = array_replace([], $_GET?: [], $_POST?: [], $_COOKIE?: []);

        $contentType = $this->header('CONTENT_TYPE')?: $this->serverVar('CONTENT_TYPE');
        if ($contentType && 'application/json' == substr($contentType, 0, 16)) {
            $body = $this->body()?: '{}';
            $this->params(json_decode($body, true));
        }
    }

    public function __call($method, $args)
    {
        if (!array_key_exists($method, $this->data)) {
            throw new Exception("Call undefined method $method");
        }

        $name = isset($args[0])? $args[0] : null;
        $value = isset($args[1])? $args[1] : null;
        $data = $this->data[$method];

        switch (count($args)) {
            case 0: return $data;
            case 1:
                if (is_array($name)) {
                    $this->data[$method] = array_replace($data, $name);
                    return $this;
                }
                if ('params' == $method) {
                    if (isset($data[$name])) {
{'fraction_non_alphanumeric': 0.17231173955935547, 'fraction_numerical': 0.004932587964485367, 'mean_word_length': 1.8350419384902144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '7470026', 'n_tokens_mistral': 904, 'n_tokens_neox': 878, 'n_words': 179}