Passed
Push — master ( 6bab95...ec3c3e )
by Zaahid
03:17
created

src/ChunkSplitStream.php (89 issues)

1
<?php
0 ignored issues
show
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Filename "ChunkSplitStream.php" doesn't match the expected filename "chunksplitstream.php"
Loading history...
2
/**
3
 * This file is part of the ZBateson\StreamDecorators project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
6
 */
0 ignored issues
show
PHP version not specified
Loading history...
There must be exactly one blank line after the file comment
Loading history...
Coding Style Documentation introduced by
Missing @package tag in file comment
Loading history...
Coding Style Documentation introduced by
Missing @subpackage tag in file comment
Loading history...
Missing @category tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @link tag in file comment
Loading history...
7
namespace ZBateson\StreamDecorators;
8
9
use Psr\Http\Message\StreamInterface;
10
use GuzzleHttp\Psr7\StreamDecoratorTrait;
11
12
/**
13
 * Inserts line ending characters after the set number of characters have been
14
 * written to the underlying stream.
15
 *
16
 * @author Zaahid Bateson
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
17
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
18
class ChunkSplitStream implements StreamInterface
19
{
0 ignored issues
show
Opening brace should be on the same line as the declaration for class ChunkSplitStream
Loading history...
20
    use StreamDecoratorTrait;
21
22
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
23
     * @var int Number of bytes written, and importantly, if non-zero, writes a
24
     *      final $lineEnding on close (and so maintained instead of using
25
     *      tell() directly)
26
     */
27
    private $position;
0 ignored issues
show
Private member variable "position" must contain a leading underscore
Loading history...
Private member variable "position" must be prefixed with an underscore
Loading history...
28
29
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
30
     * @var int The number of characters in a line before inserting $lineEnding.
31
     */
32
    private $lineLength;
0 ignored issues
show
Private member variable "lineLength" must contain a leading underscore
Loading history...
Private member variable "lineLength" must be prefixed with an underscore
Loading history...
33
34
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
35
     * @var string The line ending characters to insert.
36
     */
37
    private $lineEnding;
0 ignored issues
show
Private member variable "lineEnding" must contain a leading underscore
Loading history...
Private member variable "lineEnding" must be prefixed with an underscore
Loading history...
38
39
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
40
     * @var int The strlen() of $lineEnding
41
     */
42
    private $lineEndingLength;
0 ignored issues
show
Private member variable "lineEndingLength" must contain a leading underscore
Loading history...
Private member variable "lineEndingLength" must be prefixed with an underscore
Loading history...
43
44
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
45
     * @param StreamInterface $stream
0 ignored issues
show
Missing parameter comment
Loading history...
46
     * @param int $lineLength
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 13 spaces after parameter type; 1 found
Loading history...
Expected "integer" but found "int" for parameter type
Loading history...
47
     * @param string $lineEnding
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 10 spaces after parameter type; 1 found
Loading history...
48
     */
49 2
    public function __construct(StreamInterface $stream, $lineLength = 76, $lineEnding = "\r\n")
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
Type hint "int" missing for $lineLength
Loading history...
Type hint "string" missing for $lineEnding
Loading history...
50
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
51 2
        $this->stream = $stream;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52 2
        $this->lineLength = $lineLength;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53 2
        $this->lineEnding = $lineEnding;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54 2
        $this->lineEndingLength = strlen($this->lineEnding);
55 2
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end __construct()
Loading history...
56
57
    /**
58
     * Inserts the line ending character after each line length characters in
59
     * the passed string, making sure previously written bytes are taken into
60
     * account.
61
     *
62
     * @param string $string
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
63
     * @return string
0 ignored issues
show
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
64
     */
65 2
    private function getChunkedString($string)
0 ignored issues
show
Private method name "ChunkSplitStream::getChunkedString" must be prefixed with an underscore
Loading history...
Type hint "string" missing for $string
Loading history...
66
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
67 2
        $firstLine = '';
68 2
        if ($this->tell() !== 0) {
69 2
            $next = $this->lineLength - ($this->position % ($this->lineLength + $this->lineEndingLength));
0 ignored issues
show
Arithmetic operation must be bracketed
Loading history...
70 2
            if (strlen($string) > $next) {
71 2
                $firstLine = substr($string, 0, $next) . $this->lineEnding;
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
72 2
                $string = substr($string, $next);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
73
            }
74
        }
75
        // chunk_split always ends with the passed line ending
0 ignored issues
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
76 2
        $chunked = $firstLine . chunk_split($string, $this->lineLength, $this->lineEnding);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
77 2
        return substr($chunked, 0, strlen($chunked) - $this->lineEndingLength);
0 ignored issues
show
Arithmetic operation must be bracketed
Loading history...
78
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end getChunkedString()
Loading history...
79
80
    /**
81
     * Writes the passed string to the underlying stream, ensuring line endings
82
     * are inserted every "line length" characters in the string.
83
     *
84
     * @param string $string
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
85
     * @return number of bytes written
0 ignored issues
show
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
86
     */
87 2
    public function write($string)
0 ignored issues
show
Type hint "string" missing for $string
Loading history...
88
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
89 2
        $chunked = $this->getChunkedString($string);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
90 2
        $this->position += strlen($chunked);
91 2
        return $this->stream->write($chunked);
92
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end write()
Loading history...
93
94
    /**
95
     * Inserts a final line ending character.
96
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
97 2
    private function beforeClose()
0 ignored issues
show
Private method name "ChunkSplitStream::beforeClose" must be prefixed with an underscore
Loading history...
98
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
99 2
        if ($this->position !== 0) {
100 2
            $this->stream->write($this->lineEnding);
101
        }
102 2
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end beforeClose()
Loading history...
103
104
    /**
105
     * Closes the stream after ensuring a final line ending character is
106
     * inserted.
107
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
108 2
    public function close()
109
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
110 2
        $this->beforeClose();
111 2
        $this->stream->close();
112 2
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end close()
Loading history...
113
114
    /**
115
     * Detaches the stream after ensuring a final line ending character is
116
     * inserted.
117
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
118
    public function detach()
119
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
120
        $this->beforeClose();
121
        $this->stream->detach();
122
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end detach()
Loading history...
123
}
0 ignored issues
show
Expected //end class
Loading history...
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
124