<commit_before><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\EventExport\FileWriter;


class JSONLDFileWriter implements FileWriterInterface
{
    protected $f;

    /**
     * @var string[]
     */
    protected $includedProperties;

    public function __construct($filePath, $include = null) {
        $this->f = fopen($filePath, 'w');
        if (false === $this->f) {
            throw new \RuntimeException('Unable to open file for writing: ' . $filePath);
        }
        fwrite($this->f, '[');

        $this->first = true;

        if($include) {
            $include[] = '@id';
            // The address property is nested inside location.
            // The whole location property gets included instead of pulling it
            // out and placing it directly on the object.
            if(in_array('address', $include) && !in_array('location', $include)) {
                array_push($include, 'location');
            }
            $this->includedProperties = $include;
        }

    }

    /**
     * @param mixed $event
     */
    public function exportEvent($event)
    {
        if ($this->first) {
            $this->first = false;
        }
        else {
            fwrite($this->f, ',');
        }

        if($this->includedProperties) {
            $eventObject = json_decode($event);
            foreach($eventObject as $propertyName => $value) {
                var_dump($propertyName);
                if(!in_array($propertyName, $this->includedProperties)) {
                    unset($eventObject->{$propertyName});
                }
            }
            $event = json_encode($eventObject);
        }

        fwrite($this->f, $event);
    }

    public function close() {
        if (is_resource($this->f)) {
            fwrite($this->f, ']');

            fclose($this->f);
        }
    }
}<commit_msg>III-160: Fix some coding standard violations and remove a remaining var_dump()<commit_after><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\EventExport\FileWriter;


class JSONLDFileWriter implements FileWriterInterface
{
    protected $f;

    /**
     * @var string[]
     */
    protected $includedProperties;

    public function __construct($filePath, $include = null)
    {
        $this->f = fopen($filePath, 'w');
        if (false === $this->f) {
            throw new \RuntimeException(
                'Unable to open file for writing: ' . $filePath
            );
        }
        fwrite($this->f, '[');

        $this->first = true;

        if ($include) {
            $include[] = '@id';
            // The address property is nested inside location.
            // The whole location property gets included instead of pulling it
            // out and placing it directly on the object.
            if (in_array('address', $include) && !in_array(
                    'location',
                    $include
                )
            ) {
                array_push($include, 'location');
            }
            $this->includedProperties = $include;
        }

    }

    /**
     * @param mixed $event
     */
    public function exportEvent($event)
    {
        if ($this->first) {
            $this->first = false;
        } else {
            fwrite($this->f, ',');
        }

        if ($this->includedProperties) {
            $eventObject = json_decode($event);
            foreach ($eventObject as $propertyName => $value) {
                if (!in_array($propertyName, $this->includedProperties)) {
                    unset($eventObject->{$propertyName});
                }
            }
            $event = json_encode($eventObject);
        }

        fwrite($this->f, $event);
    }

    public function close()
    {
        if (is_resource($this->f)) {
            fwrite($this->f, ']');

            fclose($this->f);
        }
    }
}
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.0013061650992685476, 'mean_word_length': 1.631615120274914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '5892809', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1021, 'n_words': 230}