1919class RenderHandler implements RobotsTxtInterface
2020{
2121 /**
22- * Mode
22+ * Render level
2323 * @var int
2424 */
25- private $ mode ;
25+ private $ level ;
2626
2727 /**
2828 * Line separator
2929 * @var string
3030 */
31- private $ separator ;
31+ private $ eol ;
3232
3333 /**
3434 * Rule strings
@@ -57,42 +57,42 @@ class RenderHandler implements RobotsTxtInterface
5757 /**
5858 * RenderHandler constructor.
5959 *
60- * @param int $mode
60+ * @param int $level
6161 * @param string $lineSeparator
6262 */
63- public function __construct ($ mode , $ lineSeparator = "\r\n" )
63+ public function __construct ($ level , $ lineSeparator = "\r\n" )
6464 {
65- $ this ->mode = $ mode ;
65+ $ this ->level = $ level ;
6666 $ this ->separatorCheck ($ lineSeparator );
6767 }
6868
6969 /**
7070 * Line separator check
7171 *
72- * @param string $lineSeparator
72+ * @param string $eol
7373 * @throws ClientException
7474 */
75- private function separatorCheck ($ lineSeparator )
75+ private function separatorCheck ($ eol )
7676 {
77- if (!in_array ($ lineSeparator , [
77+ if (!in_array ($ eol , [
7878 "\r\n" ,
7979 "\n" ,
8080 "\r" ,
8181 ])
8282 ) {
8383 throw new ClientException ('Invalid line separator ' );
8484 }
85- $ this ->separator = $ lineSeparator ;
85+ $ this ->eol = $ eol ;
8686 }
8787
8888 /**
8989 * Get mode
9090 *
9191 * @return int
9292 */
93- public function getMode ()
93+ public function getLevel ()
9494 {
95- return $ this ->mode ;
95+ return $ this ->level ;
9696 }
9797
9898 /**
@@ -104,8 +104,9 @@ public function getMode()
104104 */
105105 public function addInline ($ directive , RenderHandler $ handler )
106106 {
107- foreach ($ handler ->export () as $ line ) {
108- $ this ->add ($ directive , trim ($ line ));
107+ $ lines = array_map ('trim ' , $ handler ->export ());
108+ foreach ($ lines as $ line ) {
109+ $ this ->add ($ directive , $ line );
109110 }
110111 return true ;
111112 }
@@ -131,7 +132,7 @@ public function add($directive, $line)
131132 {
132133 $ this ->previous = $ this ->directive ;
133134 $ this ->directive = $ directive ;
134- if ($ this ->mode >= 2 ) {
135+ if ($ this ->level >= 2 ) {
135136 $ this ->strings [] = $ this ->advanced () . $ line ;
136137 return true ;
137138 }
@@ -147,11 +148,11 @@ public function add($directive, $line)
147148 private function advanced ()
148149 {
149150 $ result = '' ;
150- if ($ this ->boolInsertSeparatorMode3 () ||
151+ if ($ this ->boolInsertSeparatorLevel3 () ||
151152 $ this ->previous !== self ::DIRECTIVE_USER_AGENT &&
152153 $ this ->directive === self ::DIRECTIVE_USER_AGENT
153154 ) {
154- $ result = $ this ->separator ;
155+ $ result = $ this ->eol ;
155156 $ this ->previousRoot = $ this ->directive ;
156157 }
157158 $ result .= $ this ->basic ();
@@ -163,9 +164,9 @@ private function advanced()
163164 *
164165 * @return bool
165166 */
166- private function boolInsertSeparatorMode3 ()
167+ private function boolInsertSeparatorLevel3 ()
167168 {
168- return $ this ->mode >= 3 &&
169+ return $ this ->level >= 3 &&
169170 $ this ->previousRoot !== $ this ->directive &&
170171 in_array ($ this ->directive , [
171172 self ::DIRECTIVE_HOST ,
@@ -182,7 +183,7 @@ private function boolInsertSeparatorMode3()
182183 private function basic ()
183184 {
184185 $ result = $ this ->directive . ': ' ;
185- if ($ this ->mode === 0 ) {
186+ if ($ this ->level === 0 ) {
186187 return $ result ;
187188 }
188189 return ucfirst ($ result ) . ' ' ;
@@ -195,6 +196,6 @@ private function basic()
195196 */
196197 public function generate ()
197198 {
198- return trim (implode ($ this ->separator , $ this ->strings ));
199+ return trim (implode ($ this ->eol , $ this ->strings ));
199200 }
200201}
0 commit comments