Issues (4)

src/Syslog/ParseLine.php (2 issues)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\logpeek\Syslog;
6
7
use function getdate;
8
use function intval;
9
use function sprintf;
10
use function sscanf;
11
use function strtotime;
12
13
class ParseLine
14
{
15
    /**
16
     * @param int $time
17
     * @param string $logLine
18
     * @return bool
19
     */
20
    public static function isOlderThan(int $time, string $logLine): bool
0 ignored issues
show
The parameter $time is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
    public static function isOlderThan(/** @scrutinizer ignore-unused */ int $time, string $logLine): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $logLine is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
    public static function isOlderThan(int $time, /** @scrutinizer ignore-unused */ string $logLine): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        return true;
23
    }
24
25
26
    /**
27
     * @param string $logLine
28
     * @param int|null $year
29
     * @return int|false
30
     */
31
    public static function getUnixTime(string $logLine, int $year = null)
32
    {
33
        // I can read month and day and time from the file.
34
        // but I will assume year is current year retured by time().
35
        // Unless month and day in the file is bigger than current month and day,
36
        // I will then assume previous year.
37
        // A better approach would be to get the year from last modification time (mtime) of the
38
        // file this record is taken from. But that requires knowledge about the file.
39
        if ($year === null) {
40
            $now = getdate();
41
            $year = intval($now['year']);
42
        }
43
        list($month, $day, $hour, $minute, $second) = sscanf($logLine, "%s %d %d:%d:%d ");
44
        $time = sprintf("%d %s %d %d:%d:%d", $day, $month, $year, $hour, $minute, $second);
45
        return strtotime($time);
46
    }
47
}
48