From b9747c4926d7b67c6bb0e44f0fcdb8c470537bb8 Mon Sep 17 00:00:00 2001 From: Olav van Schie Date: Tue, 18 Apr 2017 18:03:25 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/HostsFile.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/HostsFile.php b/src/HostsFile.php index 415b953..1267ad7 100644 --- a/src/HostsFile.php +++ b/src/HostsFile.php @@ -38,18 +38,18 @@ public function __construct($filePath = null) } } - if (!is_file($filePath) || !is_readable($filePath)) { + if (! is_file($filePath) || ! is_readable($filePath)) { throw new Exception(sprintf('Unable to read file: %s', $filePath)); } $this->filePath = realpath($filePath); - $this->bakPath = realpath($filePath) . '.bak'; + $this->bakPath = realpath($filePath).'.bak'; $this->readFile(); } /** - * Return lines + * Return lines. * * @return array */ @@ -59,7 +59,7 @@ public function getLines() } /** - * Add a line + * Add a line. * * @param $ip * @param $domain @@ -70,11 +70,11 @@ public function getLines() */ public function addLine($ip, $domain, $aliases = '') { - if (!filter_var($ip, FILTER_VALIDATE_IP)) { + if (! filter_var($ip, FILTER_VALIDATE_IP)) { throw new Exception(sprintf("'%s', is not a valid ip", $ip)); } - if (!filter_var($domain, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => "/^[a-zA-Z0-9\\.]*[a-zA-Z0-9]+?/"]])) { + if (! filter_var($domain, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^[a-zA-Z0-9\\.]*[a-zA-Z0-9]+?/']])) { throw new Exception(sprintf("'%s', is not a valid domain", $domain)); } @@ -91,7 +91,7 @@ public function addLine($ip, $domain, $aliases = '') */ public function removeLine($domain) { - if (!filter_var($domain, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => "/^[a-zA-Z0-9\\.]*[a-zA-Z0-9]+?/"]])) { + if (! filter_var($domain, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^[a-zA-Z0-9\\.]*[a-zA-Z0-9]+?/']])) { throw new Exception(sprintf("'%s', is not a valid domain", $domain)); } @@ -101,7 +101,7 @@ public function removeLine($domain) } /** - * Save the file + * Save the file. * * @param null $filePath */ @@ -115,13 +115,13 @@ public function save($filePath = null) } /** - * Read the File + * Read the File. */ protected function readFile() { $file = fopen($this->filePath, 'r'); - while(($line = fgets($file)) !== false) { + while (($line = fgets($file)) !== false) { $this->parseLine($line); } @@ -129,7 +129,7 @@ protected function readFile() } /** - * Parse a line + * Parse a line. * * @param $line */ @@ -138,7 +138,6 @@ protected function parseLine($line) $matches = $this->explodeLine($line); if (isset($matches[1], $matches[2])) { - $ip = $matches[1]; $domainLine = $this->explodeLine($matches[2]); @@ -152,7 +151,7 @@ protected function parseLine($line) } /** - * Explode entry by whitespace regex + * Explode entry by whitespace regex. * * @param $line * @@ -166,7 +165,7 @@ protected function explodeLine($line) } /** - * Write lines to the file + * Write lines to the file. * * @param $filePath * @@ -175,16 +174,16 @@ protected function explodeLine($line) */ protected function writeFile($filePath) { - if (is_file($filePath) && !is_writable($filePath)) { + if (is_file($filePath) && ! is_writable($filePath)) { throw new Exception(sprintf("File '%s' is not writable", $filePath)); } $file = fopen($filePath, 'w'); foreach ($this->lines as $domain => $attributes) { - fwrite($file, $attributes['ip'] . "\t\t" . $domain ." " . $attributes['aliases'] . " \r\n"); + fwrite($file, $attributes['ip']."\t\t".$domain.' '.$attributes['aliases']." \r\n"); } fclose($file); } -} \ No newline at end of file +}