FileBuffer::getLine()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace Htsl\ReadingBuffer;
4
5
use Htsl\Htsl;
6
7
////////////////////////////////////////////////////////////////
8
9
class FileBuffer extends Contracts\ABuffer
10
{
11
	/**
12
	 * File handle.
13
	 *
14
	 * @access private
15
	 *
16
	 * @var resource
17
	 */
18
	private $handle;
19
20
	/**
21
	 * Constructing a file buffer reading HTSL content from file system.
22
	 *
23
	 * @access public
24
	 *
25
	 * @param Htsl   $htsl     Main Htsl object
26
	 * @param string $filePath
27
	 */
28
	public function __construct( Htsl$htsl, string$filePath )
29
	{
30
		substr($filePath,-5)==='.htsl' or $filePath.= '.htsl';
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...
31
32
		if( !file_exists($filePath) || !is_file($filePath) ){
33
			throw new \Exception("File $filePath not exists.", 1);
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $filePath instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
34
		}
35
36
		$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...
37
38
		$this->handle= fopen($filePath,'r');
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...
39
40
		parent::__construct($htsl);
41
	}
42
43
	/**
44
	 * Destructor
45
	 *
46
	 * @access public
47
	 */
48
	public function __destruct()
49
	{
50
		fclose($this->handle);
51
	}
52
53
	/**
54
	 * Getting first line or next line.
55
	 *
56
	 * @access public
57
	 *
58
	 * @return \Htsl\ReadingBuffer\Line
59
	 */
60
	public function getLine():Line
61
	{
62
		while( "\n"===$content= fgets($this->handle) );
63
64
		return new Line($content);
65
	}
66
67
	/**
68
	 * Getting another file reference file of this buffer.
69
	 *
70
	 * @access public
71
	 *
72
	 * @param  string $fileName
73
	 *
74
	 * @return \Htsl\ReadingBuffer\Contracts\ABuffer
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use FileBuffer.

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...
75
	 */
76
	public function goSide( $fileName ):parent
77
	{
78
		$filePath= $this->htsl->getFilePath($fileName,dirname($this->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...
79
80
		return new static($this->htsl,$filePath);
81
	}
82
}
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...
83