Skip to content

Commit 3189f8a

Browse files
committed
code loop fix
1 parent 4a603a4 commit 3189f8a

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/XRobotsTagParser/Rebuild.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
final class Rebuild
66
{
77
private $directiveArray;
8-
private $reRun = true;
98

109
/**
1110
* Constructor
@@ -15,8 +14,19 @@ final class Rebuild
1514
public function __construct($directives)
1615
{
1716
$this->directiveArray = $directives;
18-
while ($this->reRun) {
19-
$this->reRun = false;
17+
$this->parse();
18+
}
19+
20+
/**
21+
* parse
22+
*
23+
* @return void
24+
*/
25+
private function parse()
26+
{
27+
$past = [];
28+
while ($past !== $this->directiveArray) {
29+
$past = $this->directiveArray;
2030
$this->all();
2131
$this->noindex();
2232
$this->none();
@@ -48,7 +58,6 @@ private function noindex()
4858
return;
4959
}
5060
$this->directiveArray['noarchive'] = true;
51-
$this->reRun = true;
5261
}
5362

5463
/**
@@ -63,7 +72,6 @@ private function none()
6372
}
6473
$this->directiveArray['noindex'] = true;
6574
$this->directiveArray['nofollow'] = true;
66-
$this->reRun = true;
6775
}
6876

6977
/**
@@ -73,14 +81,13 @@ private function none()
7381
*/
7482
private function unavailable_after()
7583
{
76-
if (
77-
!isset($this->directiveArray['unavailable_after'])
78-
|| time() < date_create_from_format(DATE_RFC850, $this->directiveArray['unavailable_after'])
79-
) {
84+
if (!isset($this->directiveArray['unavailable_after'])) {
8085
return;
8186
}
82-
$this->directiveArray['noindex'] = true;
83-
$this->reRun = true;
87+
$dateTime = date_create_from_format(DATE_RFC850, $this->directiveArray['unavailable_after']);
88+
if ($dateTime !== false && time() >= $dateTime->getTimestamp()) {
89+
$this->directiveArray['noindex'] = true;
90+
}
8491
}
8592

8693
/**

0 commit comments

Comments
 (0)