Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
FilterStream
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 filter
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getContents
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 reset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework CLI Library.
4 *
5 * (c) Natan Felles <natanfelles@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10namespace Framework\CLI\Streams;
11
12use JetBrains\PhpStorm\Pure;
13
14/**
15 * Trait FilterStream.
16 *
17 * @package cli
18 *
19 * @since 2.3.1
20 */
21trait FilterStream
22{
23    protected static string $contents = '';
24
25    /**
26     * @param resource $in
27     * @param resource $out
28     * @param int $consumed
29     * @param bool $closing
30     *
31     * @see https://php.net/manual/en/php-user-filter.filter.php
32     *
33     * @return int
34     */
35    public function filter($in, $out, &$consumed, $closing) : int
36    {
37        while ($bucket = \stream_bucket_make_writeable($in)) {
38            static::$contents .= $bucket->data;
39            $consumed += $bucket->datalen;
40            \stream_bucket_append($out, $bucket);
41        }
42        return \PSFS_FEED_ME;
43    }
44
45    #[Pure]
46    public static function getContents() : string
47    {
48        return static::$contents;
49    }
50
51    public static function reset() : void
52    {
53        static::$contents = '';
54    }
55}