]> git.mxchange.org Git - friendica.git/commitdiff
Fix code formatting
authorfabrixxm <fabrix.xm@gmail.com>
Mon, 24 May 2021 20:05:02 +0000 (22:05 +0200)
committerfabrixxm <fabrix.xm@gmail.com>
Thu, 19 Aug 2021 12:55:33 +0000 (14:55 +0200)
src/Model/Log/ParsedLogIterator.php
src/Module/Admin/Logs/View.php
src/Object/Log/ParsedLog.php
src/Util/ReversedFileReader.php

index 15714454e7ce667a9631c0c7e477824ae5ed98d2..3e1832d969998cc46e10c200fd0e6cbd7119da55 100644 (file)
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  *
  */
-namespace Friendica\Model\Log;
 
-use \Friendica\Util\ReversedFileReader;
-use \Friendica\Object\Log\ParsedLog;
+namespace Friendica\Model\Log;
 
+use Friendica\Util\ReversedFileReader;
+use Friendica\Object\Log\ParsedLog;
 
 /**
  * An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
@@ -36,7 +36,7 @@ class ParsedLogIterator implements \Iterator
        private $reader;
 
        /** @var ParsedLog current iterator value*/
-       private $value; 
+       private $value;
 
        /** @var int max number of lines to read */
        private $limit;
@@ -54,19 +54,19 @@ class ParsedLogIterator implements \Iterator
         * @param array $filter         filters per column
         * @param string $search        string to search to filter lines
         */
-       public function __construct(string $filename, int $limit=0, array $filters=[], string $search="")
+       public function __construct(string $filename, int $limit = 0, array $filters = [], string $search = "")
        {
-               $this->reader = new ReversedFileReader($filename);
-               $this->value = null;
-               $this->limit = $limit;
+               $this->reader  = new ReversedFileReader($filename);
+               $this->value   = null;
+               $this->limit   = $limit;
                $this->filters = $filters;
-               $this->search = $search;
+               $this->search  = $search;
        }
 
        /**
         * Check if parsed log line match filters.
         * Always match if no filters are set.
-        * 
+        *
         * @param ParsedLog $parsedlog
         * @return bool
         */
@@ -74,7 +74,7 @@ class ParsedLogIterator implements \Iterator
        {
                $match = true;
                foreach ($this->filters as $filter => $filtervalue) {
-                       switch($filter) {
+                       switch ($filter) {
                                case "level":
                                        $match = $match && ($parsedlog->level == strtoupper($filtervalue));
                                        break;
@@ -89,7 +89,7 @@ class ParsedLogIterator implements \Iterator
        /**
         * Check if parsed log line match search.
         * Always match if no search query is set.
-        * 
+        *
         * @param ParsedLog $parsedlog
         * @return bool
         */
@@ -98,20 +98,20 @@ class ParsedLogIterator implements \Iterator
                if ($this->search != "") {
                        return strstr($parsedlog->logline, $this->search) !== false;
                }
-               return True;
+               return true;
        }
 
        /**
         * Read a line from reader and parse.
         * Returns null if limit is reached or the reader is invalid.
-        * 
+        *
         * @param ParsedLog $parsedlog
         * @return ?ParsedLog
         */
        private function read()
        {
                $this->reader->next();
-               if ($this->limit > 0 && $this->reader->key() > $this->limit  || !$this->reader->valid()) {
+               if ($this->limit > 0 && $this->reader->key() > $this->limit || !$this->reader->valid()) {
                        return null;
                }
 
@@ -126,7 +126,7 @@ class ParsedLogIterator implements \Iterator
                // if read() has not retuned none and
                // the line don't match filters or search
                //      read the next line
-               while(is_null($parsed) == false && !($this->filter($parsed)  && $this->search($parsed))) {
+               while (is_null($parsed) == false && !($this->filter($parsed) && $this->search($parsed))) {
                        $parsed = $this->read();
                }
                $this->value = $parsed;
@@ -153,6 +153,4 @@ class ParsedLogIterator implements \Iterator
        {
                return ! is_null($this->value);
        }
-
 }
-
index a512507278f76eaa72640d3f4e2424a87591c974..26ad3a8b61f28f19a473060f2ac82ff1b9f17a3d 100644 (file)
@@ -39,12 +39,12 @@ class View extends BaseAdmin
                $t = Renderer::getMarkupTemplate('admin/logs/view.tpl');
                DI::page()->registerFooterScript(Theme::getPathForFile('js/module/admin/logs/view.js'));
 
-               $f = DI::config()->get('system', 'logfile');
-               $data = null;
+               $f     = DI::config()->get('system', 'logfile');
+               $data  = null;
                $error = null;
 
-
                $search = $_GET['q'] ?? '';
+
                $filters_valid_values = [
                        'level' => [
                                '',
@@ -58,10 +58,10 @@ class View extends BaseAdmin
                        'context' => ['', 'index', 'worker'],
                ];
                $filters = [
-                       'level' => $_GET['level'] ?? '',
+                       'level'   => $_GET['level'] ?? '',
                        'context' => $_GET['context'] ?? '',
                ];
-               foreach($filters as $k=>$v) {
+               foreach ($filters as $k => $v) {
                        if ($v == '' || !in_array($v, $filters_valid_values[$k])) {
                                unset($filters[$k]);
                        }
@@ -77,14 +77,14 @@ class View extends BaseAdmin
                        }
                }
                return Renderer::replaceMacros($t, [
-                       '$title' => DI::l10n()->t('Administration'),
-                       '$page' => DI::l10n()->t('View Logs'),
-                       '$data' => $data,
-                       '$q' => $search,
-                       '$filters' => $filters,
+                       '$title'         => DI::l10n()->t('Administration'),
+                       '$page'          => DI::l10n()->t('View Logs'),
+                       '$data'          => $data,
+                       '$q'             => $search,
+                       '$filters'       => $filters,
                        '$filtersvalues' => $filters_valid_values,
-                       '$error' => $error,
-                       '$logname' => DI::config()->get('system', 'logfile'),
+                       '$error'         => $error,
+                       '$logname'       => DI::config()->get('system', 'logfile'),
                ]);
        }
 }
index f48ce400e7678fe940c065bff225eb6ffe171f5c..c33f4f95060d35aebe3d01f8ee15c0bf10986bdc 100644 (file)
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  *
  */
+
 namespace Friendica\Object\Log;
 
 /**
@@ -64,18 +65,22 @@ class ParsedLog
        private function parse($logline)
        {
                list($logline, $jsonsource) = explode(' - ', $logline);
+
                $jsondata = null;
+
                if (strpos($logline, '{"') > 0) {
                        list($logline, $jsondata) = explode('{"', $logline, 2);
+
                        $jsondata = '{"' . $jsondata;
                }
                preg_match(self::REGEXP, $logline, $matches);
-               $this->date = $matches[1];
+
+               $this->date    = $matches[1];
                $this->context = $matches[2];
-               $this->level = $matches[3];
+               $this->level   = $matches[3];
                $this->message = $matches[4];
-               $this->data = $jsondata;
-               $this->source = $jsonsource;
+               $this->data    = $jsondata;
+               $this->source  = $jsonsource;
                $this->try_fix_json();
 
                $this->logline = $logline;
@@ -83,7 +88,7 @@ class ParsedLog
 
        /**
         * Fix message / data split
-        * 
+        *
         * In log boundary between message and json data is not specified.
         * If message  contains '{' the parser thinks there starts the json data.
         * This method try to parse the found json and if it fails, search for next '{'
@@ -112,12 +117,12 @@ class ParsedLog
         *
         * @return array
         */
-       public function get_data() {
+       public function get_data()
+       {
                $data = json_decode($this->data, true);
                if ($data) {
-                       foreach($data as $k => $v) {
-                               $v = print_r($v, true);
-                               $data[$k] = $v;
+                       foreach ($data as $k => $v) {
+                               $data[$k] = print_r($v, true);
                        }
                }
                return $data;
@@ -128,7 +133,8 @@ class ParsedLog
         *
         * @return array
         */
-       public function get_source() {
+       public function get_source()
+       {
                return json_decode($this->source, true);
        }
 }
index eeedc1a5ccba435fe6ecac8f6055677924eb9101..c889b5f93d6bab033e533ba23f43cab69da6bb29 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Util;
 
-
 /**
  * An iterator which returns lines from file in reversed order
  *
@@ -29,87 +28,87 @@ namespace Friendica\Util;
  */
 class ReversedFileReader implements \Iterator
 {
-    const BUFFER_SIZE = 4096;
-    const SEPARATOR = "\n";
+       const BUFFER_SIZE = 4096;
+       const SEPARATOR   = "\n";
 
-    /** @var int */
-    private $filesize;
+       /** @var int */
+       private $filesize;
 
-    /** @var int */
-    private $pos;
+       /** @var int */
+       private $pos;
 
-    /** @var array */
-    private $buffer;
+       /** @var array */
+       private $buffer;
 
-    /** @var int */
-    private $key;
+       /** @var int */
+       private $key;
 
-    /** @var string */
-    private $value;
+       /** @var string */
+       private $value;
 
-    public function __construct($filename)
-    {
-        $this->_fh = fopen($filename, 'r');
+       public function __construct($filename)
+       {
+               $this->_fh = fopen($filename, 'r');
                if (!$this->_fh) {
                        // this should use a custom exception.
                        throw \Exception("Unable to open $filename");
                }
-        $this->filesize = filesize($filename);
-        $this->pos = -1;
-        $this->buffer = null;
-        $this->key = -1;
-        $this->value = null;
-    }
+               $this->filesize = filesize($filename);
+               $this->pos      = -1;
+               $this->buffer   = null;
+               $this->key      = -1;
+               $this->value    = null;
+       }
 
-    public function _read($size)
-    {
-        $this->pos -= $size;
-        fseek($this->_fh, $this->pos);
-        return fread($this->_fh, $size);
-    }
+       public function _read($size)
+       {
+               $this->pos -= $size;
+               fseek($this->_fh, $this->pos);
+               return fread($this->_fh, $size);
+       }
 
-    public function _readline()
-    {
-        $buffer =& $this->buffer;
-        while (true) {
-            if ($this->pos == 0) {
-                return array_pop($buffer);
-            }
-            if (count($buffer) > 1) {
-                return array_pop($buffer);
-            }
-            $buffer = explode(self::SEPARATOR, $this->_read(self::BUFFER_SIZE) . $buffer[0]);
-        }
-    }
+       public function _readline()
+       {
+               $buffer = & $this->buffer;
+               while (true) {
+                       if ($this->pos == 0) {
+                               return array_pop($buffer);
+                       }
+                       if (count($buffer) > 1) {
+                               return array_pop($buffer);
+                       }
+                       $buffer = explode(self::SEPARATOR, $this->_read(self::BUFFER_SIZE) . $buffer[0]);
+               }
+       }
 
-    public function next()
-    {
-        ++$this->key;
-        $this->value = $this->_readline();
-    }
+       public function next()
+       {
+               ++$this->key;
+               $this->value = $this->_readline();
+       }
 
-    public function rewind()
-    {
-        if ($this->filesize > 0) {
-            $this->pos = $this->filesize;
-            $this->value = null;
-            $this->key = -1;
-            $this->buffer = explode(self::SEPARATOR, $this->_read($this->filesize % self::BUFFER_SIZE ?: self::BUFFER_SIZE));
-            $this->next();
-        }
-    }
+       public function rewind()
+       {
+               if ($this->filesize > 0) {
+                       $this->pos    = $this->filesize;
+                       $this->value  = null;
+                       $this->key    = -1;
+                       $this->buffer = explode(self::SEPARATOR, $this->_read($this->filesize % self::BUFFER_SIZE ?: self::BUFFER_SIZE));
+                       $this->next();
+               }
+       }
 
-    public function key()
+       public function key()
        {
                return $this->key;
        }
 
-    public function current()
+       public function current()
        {
                return $this->value;
        }
 
-    public function valid()
+       public function valid()
        {
                return ! is_null($this->value);
        }