<commit_before><?php

/* Copyright (C) 2011 by iRail vzw/asbl */
/**
 * Prints the Json style output.
 */
include_once 'Printer.php';

class Json extends Printer
{
    private $rootname;

    // Make a stack of array information, always work on the last one
    // for nested array support
    private $stack = [];
    private $arrayindices = [];
    private $currentarrayindex = -1;

    public function printHeader()
    {
        header('Access-Control-Allow-Origin: *');
        header('Content-Type: application/json;charset=UTF-8');
    }

    /**
     * @param $ec
     * @param $msg
     * @return mixed|void
     */
    public function printError($ec, $msg)
    {
        $this->printHeader();
        header("HTTP/1.1 $ec $msg");
        echo "{\"error\":$ec,\"message\":\"$msg\"}";
    }

    /**
     * @param $name
     * @param $version
     * @param $timestamp
     * @return mixed|void
     */
    public function startRootElement($name, $version, $timestamp)
    {
        $this->rootname = $name;
        echo "{\"version\":\"$version\",\"timestamp\":\"$timestamp\",";
    }

    /**
     * @param $name
     * @param $number
     * @param bool $root
     * @return mixed|void
     */
    public function startArray($name, $number, $root = false)
    {
        if (! $root || $this->rootname == 'liveboard' || $this->rootname == 'vehicleinformation') {
            echo '"'.$name."s\":{\"number\":\"$number\",";
        }

        echo "\"$name\":[";

        $this->currentarrayindex++;
        $this->stack[$this->currentarrayindex] = $name;
        $this->arrayindices[$this->currentarrayindex] = 0;
    }

    public function nextArrayElement()
    {
        echo ',';
        $this->arrayindices[$this->currentarrayindex]++;
    }

    public function nextObjectElement()
    {
        echo ',';
    }

    /**
     * @param $name
     * @param $object
     * @return mixed|void
     */
    public function startObject($name, $object)
    {
        if ($this->currentarrayindex > -1 && $this->stack[$this->currentarrayindex] == $name) {
            echo '{';
            // Show id (in array) except if array of stations (compatibility issues)
            if ($name != 'station') {
                echo '"id":"'.$this->arrayindices[$this->currentarrayindex].'",';
            }
        } else {
            if ($this->rootname != 'stations' && $name == 'station' || $name == 'platform') {
                // split station and platform into station/platform and stationinfo/platforminfox,
                // to be compatible with 1.0
                echo "\"$name\":\"$object->name\",";
                echo '"'.$name.'info":{';
            } elseif ($this->rootname != 'vehicle' && $name == 'vehicle') {
                // split vehicle into vehicle and vehicleinfo to be compatible with 1.0
                echo "\"$name\":\"$object->name\",";
                echo '"'.$name.'info":{';
            } else {
                echo "\"$name\":{";
            }
        }
    }

    /**
     * @param $key
     * @param $val
     * @return mixed|void
     */
    public function startKeyVal($key, $val)
    {
        $val = trim(json_encode($val),'"');
        echo "\"$key\":\"$val\"";
    }
<commit_msg>Apply fixes from StyleCI (#375)<commit_after><?php

/* Copyright (C) 2011 by iRail vzw/asbl */
/**
 * Prints the Json style output.
 */
include_once 'Printer.php';

class Json extends Printer
{
    private $rootname;

    // Make a stack of array information, always work on the last one
    // for nested array support
    private $stack = [];
    private $arrayindices = [];
    private $currentarrayindex = -1;

    public function printHeader()
    {
        header('Access-Control-Allow-Origin: *');
        header('Content-Type: application/json;charset=UTF-8');
    }

    /**
     * @param $ec
     * @param $msg
     * @return mixed|void
     */
    public function printError($ec, $msg)
    {
        $this->printHeader();
        header("HTTP/1.1 $ec $msg");
        echo "{\"error\":$ec,\"message\":\"$msg\"}";
    }

    /**
     * @param $name
     * @param $version
     * @param $timestamp
     * @return mixed|void
     */
    public function startRootElement($name, $version, $timestamp)
    {
        $this->rootname = $name;
        echo "{\"version\":\"$version\",\"timestamp\":\"$timestamp\",";
    }

    /**
     * @param $name
     * @param $number
     * @param bool $root
     * @return mixed|void
     */
    public function startArray($name, $number, $root = false)
    {
        if (! $root || $this->rootname == 'liveboard' || $this->rootname == 'vehicleinformation') {
            echo '"'.$name."s\":{\"number\":\"$number\",";
        }

        echo "\"$name\":[";

        $this->currentarrayindex++;
        $this->stack[$this->currentarrayindex] = $name;
        $this->arrayindices[$this->currentarrayindex] = 0;
    }

    public function nextArrayElement()
    {
        echo ',';
        $this->arrayindices[$this->currentarrayindex]++;
    }

    public function nextObjectElement()
    {
        echo ',';
    }

    /**
     * @param $name
     * @param $object
     * @return mixed|void
     */
    public function startObject($name, $object)
    {
        if ($this->currentarrayindex > -1 && $this->stack[$this->currentarrayindex] == $name) {
            echo '{';
            // Show id (in array) except if array of stations (compatibility issues)
            if ($name != 'station') {
                echo '"id":"'.$this->arrayindices[$this->currentarrayindex].'",';
            }
        } else {
            if ($this->rootname != 'stations' && $name == 'station' || $name == 'platform') {
                // split station and platform into station/platform and stationinfo/platforminfox,
                // to be compatible with 1.0
                echo "\"$name\":\"$object->name\",";
                echo '"'.$name.'info":{';
            } elseif ($this->rootname != 'vehicle' && $name == 'vehicle') {
                // split vehicle into vehicle and vehicleinfo to be compatible with 1.0
                echo "\"$name\":\"$object->name\",";
                echo '"'.$name.'info":{';
            } else {
                echo "\"$name\":{";
            }
        }
    }

    /**
     * @param $key
     * @param $val
     * @return mixed|void
     */
    public function startKeyVal($key, $val)
    {
        $val = trim(json_encode($val), '"');
        echo "\"$key\":\"$val\"";
    }

{'fraction_non_alphanumeric': 0.18014535333230247, 'fraction_numerical': 0.004793567341889593, 'mean_word_length': 1.9161406672678087, 'pattern_counts': {'":': 28, '<': 5, '<?xml version=': 0, '>': 45, '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': '1634616', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1890, 'n_words': 434}