<commit_before><?php

namespace ErrorHandler;

class JsonSerializationState {
    public $root = array(
        'arrays'  => array(),
        'objects' => array(),
    );
    public $objectIDs = array();
    public $arrayIDs = array();
}

class JsonDeSerializationState {
    /** @var ValueObject[] */
    public $finishedObjects = array();
    /** @var ValueArray[] */
    public $finishedArrays = array();
    public $root;

    function constructValue($v) {
        if (is_float($v))
            return new ValueFloat($v);

        if (is_int($v))
            return new ValueInt($v);

        if (is_bool($v))
            return new ValueBool($v);

        if (is_null($v))
            return new ValueNull;

        if (is_string($v))
            return new ValueString($v);

        switch ($v[0]) {
            case 'object':
                return ValueObject::fromJson($this, $v);
            case '-inf':
            case '+inf':
            case 'nan':
            case 'float':
                return ValueFloat::fromJson($v);
            case 'array':
                return ValueArray::fromJson($this, $v);
            case 'exception':
                return ValueException::fromJson($this, $v);
            case 'resource':
                return ValueResource::fromJson($this, $v);
            case 'unknown':
                return new ValueUnknown;
            case 'null':
                return new ValueNull;
            case 'int':
                return new ValueInt($v[1]);
            case 'bool':
                return new ValueBool($v[1]);
            case 'string':
                return new ValueString($v[1]);
            default:
                throw new Exception("Unknown type: {$v[0]}");
        }
    }
}

class JsonSchemaObject implements JsonSerializable {
    /** @var JsonWritable[] */
    private $properties = array();

    function toJSON(JsonSerializationState $s) {
        $result = array();

        foreach ($this->properties as $k => $p)
            $result[$k] = $p->toJSON($s);

        return $result;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        foreach ($this->properties as $k => $p)
            $p->fromJSON($s, $x[$k]);
    }

    function bindRef($property, &$ref) {
        $this->bind($property, new JsonRef($ref));
    }

    function bind($property, JsonWritable $j) {
        $this->properties[$property] = $j;
    }

    function bindObject($property, &$ref, $constructor) {
        $this->bind($property, new JsonRefObject($ref, $constructor));
    }

    function bindObjectList($property, &$ref, $constructor) {
        $this->bind($property, new JsonRefObjectList($ref, $constructor));
    }

    function bindValueList($string, &$args) {
        $this->bindObjectList($string, $args, function (JsonDeSerializationState $j, $v) {
            return $j->constructValue($v);
        });
    }

    function bindValue($string, &$value) {
        $this->bindObject($string, $value, function (JsonDeSerializationState $j, $v) {
            return $j->constructValue($v);
        });
    }
}

interface JsonSerializable {
    function toJSON(JsonSerializationState $s);
}

interface JsonWritable extends JsonSerializable {
    function fromJSON(JsonDeSerializationState $s, $x);
}

class JsonRef implements JsonWritable {
    private $ref;

    function __construct(&$ref) {
        $this->ref =& $ref;
    }

    protected function get() { return $this->ref; }

    protected function set($x) { $this->ref = $x; }

    function toJSON(JsonSerializationState $s) {
        return $this->ref;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        $this->ref = $x;
    }
}

class JsonRefObject implements JsonWritable {
    private $constructor;
    private $ref;

    /**
     * @param JsonSerializable|null $ref
     * @param callable              $constructor
     */
    function __construct(&$ref, \Closure $constructor) {
        $this->constructor = $constructor;
        $this->ref         =& $ref;
    }

    function toJSON(JsonSerializationState $s) {
        return $this->ref !== null ? $this->ref->toJSON($s) : null;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        $constructor = $this->constructor;
        $this->ref   = $constructor($s, $x);
    }
}

class JsonRefObjectList implements JsonWritable {
    private $ref;
    private $constructor;

    /**
     * @param JsonSerializable[]|null $ref
     * @param callable                $constructor
     */
    function __construct(&$ref, \Closure $constructor) {
        $this->ref         =& $ref;
        $this->constructor = $constructor;
    }

    function toJSON(JsonSerializationState $s) {
        if ($this->ref === null)
            return null;

        $result = array();

        foreach ($this->ref as $k => $v) {
            $result[$k] = $v->toJSON($s);
        }

        return $result;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        if ($x === null) {
            $this->ref = null;
        } else {
            $this->ref = array();<commit_msg>Changed JsonWritable interface to JsonSchema class<commit_after><?php

namespace ErrorHandler;

class JsonSerializationState {
    public $root = array(
        'arrays'  => array(),
        'objects' => array(),
    );
    public $objectIDs = array();
    public $arrayIDs = array();
}

class JsonDeSerializationState {
    /** @var ValueObject[] */
    public $finishedObjects = array();
    /** @var ValueArray[] */
    public $finishedArrays = array();
    public $root;

    function constructValue($v) {
        if (is_float($v))
            return new ValueFloat($v);

        if (is_int($v))
            return new ValueInt($v);

        if (is_bool($v))
            return new ValueBool($v);

        if (is_null($v))
            return new ValueNull;

        if (is_string($v))
            return new ValueString($v);

        switch ($v[0]) {
            case 'object':
                return ValueObject::fromJson($this, $v);
            case '-inf':
            case '+inf':
            case 'nan':
            case 'float':
                return ValueFloat::fromJson($v);
            case 'array':
                return ValueArray::fromJson($this, $v);
            case 'exception':
                return ValueException::fromJson($this, $v);
            case 'resource':
                return ValueResource::fromJson($this, $v);
            case 'unknown':
                return new ValueUnknown;
            case 'null':
                return new ValueNull;
            case 'int':
                return new ValueInt($v[1]);
            case 'bool':
                return new ValueBool($v[1]);
            case 'string':
                return new ValueString($v[1]);
            default:
                throw new Exception("Unknown type: {$v[0]}");
        }
    }
}

class JsonSchemaObject implements JsonSerializable {
    /** @var JsonSchema[] */
    private $properties = array();

    function toJSON(JsonSerializationState $s) {
        $result = array();

        foreach ($this->properties as $k => $p)
            $result[$k] = $p->toJSON($s);

        return $result;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        foreach ($this->properties as $k => $p)
            $p->fromJSON($s, $x[$k]);
    }

    function bindRef($property, &$ref) {
        $this->bind($property, new JsonRef($ref));
    }

    function bind($property, JsonSchema $j) {
        $this->properties[$property] = $j;
    }

    function bindObject($property, &$ref, $constructor) {
        $this->bind($property, new JsonRefObject($ref, $constructor));
    }

    function bindObjectList($property, &$ref, $constructor) {
        $this->bind($property, new JsonRefObjectList($ref, $constructor));
    }

    function bindValueList($string, &$args) {
        $this->bindObjectList($string, $args, function (JsonDeSerializationState $j, $v) {
            return $j->constructValue($v);
        });
    }

    function bindValue($string, &$value) {
        $this->bindObject($string, $value, function (JsonDeSerializationState $j, $v) {
            return $j->constructValue($v);
        });
    }
}

interface JsonSerializable {
    function toJSON(JsonSerializationState $s);
}

abstract class JsonSchema implements JsonSerializable {
    abstract function fromJSON(JsonDeSerializationState $s, $x);
}

class JsonRef extends JsonSchema {
    private $ref;

    function __construct(&$ref) {
        $this->ref =& $ref;
    }

    protected function get() { return $this->ref; }

    protected function set($x) { $this->ref = $x; }

    function toJSON(JsonSerializationState $s) {
        return $this->ref;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        $this->ref = $x;
    }
}

class JsonRefObject extends JsonSchema {
    private $constructor;
    private $ref;

    /**
     * @param JsonSerializable|null $ref
     * @param callable              $constructor
     */
    function __construct(&$ref, \Closure $constructor) {
        $this->constructor = $constructor;
        $this->ref         =& $ref;
    }

    function toJSON(JsonSerializationState $s) {
        return $this->ref !== null ? $this->ref->toJSON($s) : null;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        $constructor = $this->constructor;
        $this->ref   = $constructor($s, $x);
    }
}

class JsonRefObjectList extends JsonSchema {
    private $ref;
    private $constructor;

    /**
     * @param JsonSerializable[]|null $ref
     * @param callable                $constructor
     */
    function __construct(&$ref, \Closure $constructor) {
        $this->ref         =& $ref;
        $this->constructor = $constructor;
    }

    function toJSON(JsonSerializationState $s) {
        if ($this->ref === null)
            return null;

        $result = array();

        foreach ($this->ref as $k => $v) {
            $result[$k] = $v->toJSON($s);
        }

        return $result;
    }

    function fromJSON(JsonDeSerializationState $s, $x) {
        if ($x === null) {
            $this->ref = null;
        } else {
            $this->ref = array();
{'fraction_non_alphanumeric': 0.14163972965030855, 'fraction_numerical': 0.0009795278675678322, 'mean_word_length': 2.0958156458459674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '7019712', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2860, 'n_words': 690}