]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Log/ParsedLogIterator.php
Merge remote-tracking branch 'upstream/develop' into inbox-gsid
[friendica.git] / src / Model / Log / ParsedLogIterator.php
index 0228fcf0535155e8ae1cb2166e5d4f3b59f7f0a7..a45b67176961b47f74ded3fb5f5fc3d54dcb6b5d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2021, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -45,7 +45,7 @@ class ParsedLogIterator implements \Iterator
        private $filters = [];
 
        /** @var string search term */
-       private $search = "";
+       private $search = '';
 
 
        /**
@@ -60,7 +60,7 @@ class ParsedLogIterator implements \Iterator
         * @param string $filename      File to open
         * @return $this
         */
-       public function open(string $filename)
+       public function open(string $filename): ParsedLogIterator
        {
                $this->reader->open($filename);
                return $this;
@@ -70,7 +70,7 @@ class ParsedLogIterator implements \Iterator
         * @param int $limit            Max num of lines to read
         * @return $this
         */
-       public function withLimit(int $limit)
+       public function withLimit(int $limit): ParsedLogIterator
        {
                $this->limit = $limit;
                return $this;
@@ -80,7 +80,7 @@ class ParsedLogIterator implements \Iterator
         * @param array $filters                filters per column
         * @return $this
         */
-       public function withFilters(array $filters)
+       public function withFilters(array $filters): ParsedLogIterator
        {
                $this->filters = $filters;
                return $this;
@@ -90,7 +90,7 @@ class ParsedLogIterator implements \Iterator
         * @param string $search        string to search to filter lines
         * @return $this
         */
-       public function withSearch(string $search)
+       public function withSearch(string $search): ParsedLogIterator
        {
                $this->search = $search;
                return $this;
@@ -100,18 +100,19 @@ class ParsedLogIterator implements \Iterator
         * Check if parsed log line match filters.
         * Always match if no filters are set.
         *
-        * @param ParsedLogLine $parsedlogline
-        * @return bool
+        * @param ParsedLogLine $parsedlogline ParsedLogLine instance
+        * @return bool Wether the parse log line matches
         */
-       private function filter($parsedlogline)
+       private function filter(ParsedLogLine $parsedlogline): bool
        {
                $match = true;
                foreach ($this->filters as $filter => $filtervalue) {
                        switch ($filter) {
-                               case "level":
+                               case 'level':
                                        $match = $match && ($parsedlogline->level == strtoupper($filtervalue));
                                        break;
-                               case "context":
+
+                               case 'context':
                                        $match = $match && ($parsedlogline->context == $filtervalue);
                                        break;
                        }
@@ -126,9 +127,9 @@ class ParsedLogIterator implements \Iterator
         * @param ParsedLogLine $parsedlogline
         * @return bool
         */
-       private function search($parsedlogline)
+       private function search(ParsedLogLine $parsedlogline): bool
        {
-               if ($this->search != "") {
+               if ($this->search != '') {
                        return strstr($parsedlogline->logline, $this->search) !== false;
                }
                return true;
@@ -138,7 +139,6 @@ class ParsedLogIterator implements \Iterator
         * Read a line from reader and parse.
         * Returns null if limit is reached or the reader is invalid.
         *
-        * @param ParsedLogLine $parsedlogline
         * @return ?ParsedLogLine
         */
        private function read()
@@ -160,7 +160,7 @@ class ParsedLogIterator implements \Iterator
         * @see Iterator::next()
         * @return void
         */
-       public function next()
+       public function next(): void
        {
                $parsed = $this->read();
 
@@ -177,7 +177,7 @@ class ParsedLogIterator implements \Iterator
         * @see Iterator::rewind()
         * @return void
         */
-       public function rewind()
+       public function rewind(): void
        {
                $this->value = null;
                $this->reader->rewind();
@@ -191,7 +191,7 @@ class ParsedLogIterator implements \Iterator
         * @see ReversedFileReader::key()
         * @return int
         */
-       public function key()
+       public function key(): int
        {
                return $this->reader->key();
        }
@@ -200,9 +200,9 @@ class ParsedLogIterator implements \Iterator
         * Return current iterator value
         *
         * @see Iterator::current()
-        * @return ?ParsedLogLing
+        * @return ?ParsedLogLine
         */
-       public function current()
+       public function current(): ?ParsedLogLine
        {
                return $this->value;
        }
@@ -213,8 +213,8 @@ class ParsedLogIterator implements \Iterator
         * @see Iterator::valid()
         * @return bool
         */
-       public function valid()
+       public function valid(): bool
        {
-               return ! is_null($this->value);
+               return !is_null($this->value);
        }
 }