<commit_before><?php
declare(strict_types=1);
namespace Viserio\Component\Http;

use BadMethodCallException;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Throwable;

class Stream implements StreamInterface
{
    /**
     * Bit mask to determine if the stream is a pipe.
     *
     * This is octal as per header stat.h
     */
    public const FSTAT_MODE_S_IFIFO = 0010000;

    /**
     * Resource modes.
     *
     * @var array
     *
     * @link http://php.net/manual/function.fopen.php
     */
    public const READABLE_MODES = [
        'r'   => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
        'rb'  => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
        'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
        'x+t' => true, 'c+t' => true, 'a+' => true,
    ];

    public const WRITABLE_MODES = [
        'w'   => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
        'c+'  => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
        'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
        'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true,
    ];

    /**
     * The underlying stream resource.
     *
     * @var resource
     */
    protected $stream;

    /**
     * Stream metadata.
     *
     * @var array
     */
    protected $meta;

    /**
     * Is this stream readable?
     *
     * @var bool
     */
    protected $readable;

    /**
     * Is this stream writable?
     *
     * @var bool
     */
    protected $writable;

    /**
     * Is this stream seekable?
     *
     * @var bool
     */
    protected $seekable;

    /**
     * The size of the stream if known.
     *
     * @var null|int
     */
    protected $size;

    /**
     * @var string
     */
    protected $uri;

    /**
     * This constructor accepts an associative array of options.
     *
     * - size: (int) If a read stream would otherwise have an indeterminate
     *   size, but the size is known due to foreknowledge, then you can
     *   provide that size, in bytes.
     * - metadata: (array) Any additional metadata to return when the metadata
     *   of the stream is accessed.
     *
     * @param resource $stream  stream resource to wrap
     * @param array    $options associative array of options
     *
     * @throws \InvalidArgumentException if the stream is not a stream resource
     */
    public function __construct($stream, array $options = [])
    {
        if (! is_resource($stream) || get_resource_type($stream) !== 'stream') {
            throw new InvalidArgumentException(
                'Invalid stream provided; must be a string stream identifier or stream resource'
            );
        }

        $this->stream = $stream;

        if (isset($options['size'])) {
            $this->size = (int) $options['size'];
        }

        $this->meta = isset($options['metadata'])
            ? $options['metadata']
            : [];

        $meta = stream_get_meta_data($this->stream);

        $this->seekable = $meta['seekable'];
        $this->readable = isset(self::READABLE_MODES[$meta['mode']]);
        $this->writable = isset(self::WRITABLE_MODES[$meta['mode']]);

        $this->uri = $this->getMetadata('uri');
    }

    /**
     * Closes the stream when the destructed.
     *
     * @return void
     */
    public function __destruct()
    {
        $this->close();
    }

    /**
     * @var string
     *
     * @param mixed $name
     *
     * @throws \RuntimeException|\BadMethodCallException
     *
     * @return void
     */
    public function __get($name)
    {
        if ($name == 'stream') {
            throw new RuntimeException('The stream is detached');
        }

        throw new BadMethodCallException('No value for ' . $name);
    }
<commit_msg>Issue 490 (#513)<commit_after><?php
declare(strict_types=1);
namespace Viserio\Component\Http;

use BadMethodCallException;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Throwable;

class Stream implements StreamInterface
{
    /**
     * Bit mask to determine if the stream is a pipe.
     *
     * This is octal as per header stat.h
     *
     * @var int
     */
    public const FSTAT_MODE_S_IFIFO = 0010000;

    /**
     * Resource modes.
     *
     * @var array
     *
     * @link http://php.net/manual/function.fopen.php
     */
    public const READABLE_MODES = [
        'r'   => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
        'rb'  => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
        'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
        'x+t' => true, 'c+t' => true, 'a+' => true,
    ];

    public const WRITABLE_MODES = [
        'w'   => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
        'c+'  => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
        'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
        'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true,
    ];

    /**
     * The underlying stream resource.
     *
     * @var resource
     */
    protected $stream;

    /**
     * Stream metadata.
     *
     * @var array
     */
    protected $meta;

    /**
     * Is this stream readable?
     *
     * @var bool
     */
    protected $readable;

    /**
     * Is this stream writable?
     *
     * @var bool
     */
    protected $writable;

    /**
     * Is this stream seekable?
     *
     * @var bool
     */
    protected $seekable;

    /**
     * The size of the stream if known.
     *
     * @var null|int
     */
    protected $size;

    /**
     * @var string
     */
    protected $uri;

    /**
     * This constructor accepts an associative array of options.
     *
     * - size: (int) If a read stream would otherwise have an indeterminate
     *   size, but the size is known due to foreknowledge, then you can
     *   provide that size, in bytes.
     * - metadata: (array) Any additional metadata to return when the metadata
     *   of the stream is accessed.
     *
     * @param resource $stream  stream resource to wrap
     * @param array    $options associative array of options
     *
     * @throws \InvalidArgumentException if the stream is not a stream resource
     */
    public function __construct($stream, array $options = [])
    {
        if (! is_resource($stream) || get_resource_type($stream) !== 'stream') {
            throw new InvalidArgumentException(
                'Invalid stream provided; must be a string stream identifier or stream resource'
            );
        }

        $this->stream = $stream;

        if (isset($options['size'])) {
            $this->size = (int) $options['size'];
        }

        $this->meta = isset($options['metadata'])
            ? $options['metadata']
            : [];

        $meta = stream_get_meta_data($this->stream);

        $this->seekable = $meta['seekable'];
        $this->readable = isset(self::READABLE_MODES[$meta['mode']]);
        $this->writable = isset(self::WRITABLE_MODES[$meta['mode']]);

        $this->uri = $this->getMetadata('uri');
    }

    /**
     * Closes the stream when the destructed.
     *
     * @return void
     */
    public function __destruct()
    {
        $this->close();
    }

    /**
     * @param mixed $name
     *
     * @throws \RuntimeException|\BadMethodCallException
     *
     * @return void
     */
    public function __get($name)
    {
        if ($name == 'stream') {
            throw new RuntimeException('The stream is detached');
        }

        throw new BadMethodCallException('No value for ' . $name);
    }

{'fraction_non_alphanumeric': 0.15259317174876205, 'fraction_numerical': 0.0028668230388324213, 'mean_word_length': 1.985219758848697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, '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': '4382965', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2385, 'n_words': 658}