Skip to content

Commit 8ab12a4

Browse files
committed
Added comments and reformated some code
1 parent 6900951 commit 8ab12a4

22 files changed

+345
-165
lines changed

src/PHPHtmlParser/Content.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22
namespace PHPHtmlParser;
33

4+
/**
5+
* Class Content
6+
*
7+
* @package PHPHtmlParser
8+
*/
49
class Content {
510

611
/**
@@ -32,15 +37,25 @@ class Content {
3237
protected $blank = " \t\r\n";
3338
protected $equal = ' =/>';
3439
protected $slash = " />\r\n\t";
35-
protected $attr = ' >';
40+
protected $attr = ' >';
3641

42+
/**
43+
* Content constructor.
44+
*
45+
* @param $content
46+
*/
3747
public function __construct($content)
3848
{
3949
$this->content = $content;
4050
$this->size = strlen($content);
4151
$this->pos = 0;
4252
}
4353

54+
/**
55+
* Returns the current position of the content.
56+
*
57+
* @return int
58+
*/
4459
public function getPosition()
4560
{
4661
return $this->pos;
@@ -77,6 +92,7 @@ public function char($char = null)
7792
public function fastForward($count)
7893
{
7994
$this->pos += $count;
95+
8096
return $this;
8197
}
8298

@@ -93,6 +109,7 @@ public function rewind($count)
93109
{
94110
$this->pos = 0;
95111
}
112+
96113
return $this;
97114
}
98115

@@ -115,8 +132,8 @@ public function copyUntil($string, $char = false, $escape = false)
115132
if ($escape)
116133
{
117134
$position = $this->pos;
118-
$found = false;
119-
while( ! $found)
135+
$found = false;
136+
while ( ! $found)
120137
{
121138
$position = strpos($this->content, $string, $position);
122139
if ($position === false)
@@ -138,7 +155,7 @@ public function copyUntil($string, $char = false, $escape = false)
138155
}
139156
elseif ($char)
140157
{
141-
$position = strcspn($this->content, $string, $this->pos);
158+
$position = strcspn($this->content, $string, $this->pos);
142159
$position += $this->pos;
143160
}
144161
else
@@ -151,6 +168,7 @@ public function copyUntil($string, $char = false, $escape = false)
151168
// could not find character, just return the remaining of the content
152169
$return = substr($this->content, $this->pos, $this->size - $this->pos);
153170
$this->pos = $this->size;
171+
154172
return $return;
155173
}
156174

@@ -163,6 +181,7 @@ public function copyUntil($string, $char = false, $escape = false)
163181
$return = substr($this->content, $this->pos, $position - $this->pos);
164182
// set the new position
165183
$this->pos = $position;
184+
166185
return $return;
167186
}
168187

@@ -187,6 +206,7 @@ public function copyUntilUnless($string, $unless)
187206
}
188207
// rewind changes and return nothing
189208
$this->pos = $lastPos;
209+
190210
return '';
191211
}
192212

@@ -202,6 +222,7 @@ public function copyUntilUnless($string, $unless)
202222
public function copyByToken($token, $char = false, $escape = false)
203223
{
204224
$string = $this->$token;
225+
205226
return $this->copyUntil($string, $char, $escape);
206227
}
207228

@@ -215,7 +236,7 @@ public function copyByToken($token, $char = false, $escape = false)
215236
public function skip($string, $copy = false)
216237
{
217238
$len = strspn($this->content, $string, $this->pos);
218-
239+
219240
// make it chainable if they don't want a copy
220241
$return = $this;
221242
if ($copy)
@@ -240,6 +261,7 @@ public function skip($string, $copy = false)
240261
public function skipByToken($token, $copy = false)
241262
{
242263
$string = $this->$token;
264+
243265
return $this->skip($string, $copy);
244266
}
245267
}

src/PHPHtmlParser/Curl.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
use PHPHtmlParser\Exceptions\CurlException;
55

6+
/**
7+
* Class Curl
8+
*
9+
* @package PHPHtmlParser
10+
*/
611
class Curl implements CurlInterface {
7-
12+
813
/**
914
* A simple curl implementation to get the content of the url.
1015
*
@@ -15,11 +20,12 @@ class Curl implements CurlInterface {
1520
public function get($url)
1621
{
1722
$ch = curl_init($url);
18-
19-
if(!ini_get('open_basedir')) {
23+
24+
if ( ! ini_get('open_basedir'))
25+
{
2026
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
2127
}
22-
28+
2329
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2430
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
2531

src/PHPHtmlParser/CurlInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
22
namespace PHPHtmlParser;
33

4+
/**
5+
* Interface CurlInterface
6+
*
7+
* @package PHPHtmlParser
8+
*/
49
interface CurlInterface {
5-
10+
611
/**
712
* This method should return the content of the url in a string
813
*

0 commit comments

Comments
 (0)