update variable names #2

This commit is contained in:
ghost 2023-04-04 01:38:32 +03:00
parent ed2d4047b4
commit c9cd38f6ac

View File

@ -1,8 +1,10 @@
<?php <?php
// @TODO #2
class Robots { class Robots {
private $_index = []; private $_rule = [];
public function __construct(string $data) { public function __construct(string $data) {
@ -24,11 +26,11 @@ class Robots {
if (isset($part[0]) && isset($part[1])) { if (isset($part[0]) && isset($part[1])) {
if (false !== strpos($part[0], 'allow')) { if (false !== strpos($part[0], 'allow')) {
$this->_index[$this->_regex(trim($part[1]))] = true; $this->_rule[$this->_regex(trim($part[1]))] = true;
} }
if (false !== strpos($part[0], 'disallow')) { if (false !== strpos($part[0], 'disallow')) {
$this->_index[$this->_regex(trim($part[1]))] = false; $this->_rule[$this->_regex(trim($part[1]))] = false;
} }
} }
} }
@ -55,11 +57,11 @@ class Robots {
$result = true; $result = true;
// Begin index rules by ASC priority // Begin index rules by ASC priority
foreach ($this->_index as $rule => $index) { foreach ($this->_rule as $rule => $value) {
if (preg_match('!^' . $rule . '!', $url)) { if (preg_match('!^' . $rule . '!', $url)) {
$result = $index; $result = $value;
} }
} }