StringBuffer::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
namespace Htsl\ReadingBuffer;
4
5
use Htsl\Htsl;
6
7
////////////////////////////////////////////////////////////////
8
9
class StringBuffer extends Contracts\ABuffer
10
{
11
	/**
12
	 * Array of lines.
13
	 *
14
	 * @access private
15
	 *
16
	 * @var array
17
	 */
18
	private $lines;
19
20
	/**
21
	 * Constructing a string buffer to provide lines base on string content.
22
	 *
23
	 * @access public
24
	 *
25
	 * @param \Htsl\Htsl   $htsl
26
	 * @param string       $content
27
	 * @param string       $filePath Fake file path to enable document controller.
28
	 */
29
	public function __construct( Htsl$htsl, string$content, string$filePath='' )
30
	{
31
		if( false!==strpos($content,"\r") ){
32
			throw new \Exception("Line ending must be LF.", 1);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Line ending must be LF. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
33
		}
34
35
		$this->filePath= $filePath;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

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

will have no issues, while

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

will report issues in lines 1 and 2.

Loading history...
36
37
		$this->lines= array_filter(explode("\n",$content),'strlen');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

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

will have no issues, while

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

will report issues in lines 1 and 2.

Loading history...
38
		array_unshift($this->lines,null);
39
40
		parent::__construct($htsl);
41
	}
42
43
	/**
44
	 * Getting first line or next line.
45
	 *
46
	 * @access public
47
	 *
48
	 * @return \Htsl\ReadingBuffer\Line
49
	 */
50
	public function getLine():Line
51
	{
52
		return new Line(next($this->lines));
53
	}
54
55
	/**
56
	 * Getting another file reference fake file of this buffer.
57
	 *
58
	 * @access public
59
	 *
60
	 * @param  string $fileName
61
	 *
62
	 * @return \Htsl\ReadingBuffer\Contracts\ABuffer
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use StringBuffer.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
63
	 */
64
	public function goSide( $fileName ):parent
65
	{
66
		$filePath= $this->htsl->getFilePath($fileName,dirname($this->filePath));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces

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...
67
		$content= $this->htsl->getFileContent($filePath);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 0 spaces

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...
68
69
		return new static($this->htsl,$content,$filePath);
70
	}
71
}
0 ignored issues
show
Coding Style introduced by
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...
72