Completed
Push — master ( f93b5f...ceb78f )
by Tobias
01:19
created

Plugin/LoggerPlugin.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Plugin\Plugin;
14
15
use Geocoder\Collection;
16
use Geocoder\Exception\Exception;
17
use Geocoder\Query\Query;
18
use Psr\Log\LoggerInterface;
19
20
/**
21
 * Log all queries and the result/failure.
22
 *
23
 * @author Tobias Nyholm <[email protected]>
24
 */
25
class LoggerPlugin
26
{
27
    /**
28
     * @var LoggerInterface
29
     */
30
    private $logger;
31
32
    /**
33
     * @param LoggerInterface $logger
34
     */
35 2
    public function __construct(LoggerInterface $logger)
36
    {
37 2
        $this->logger = $logger;
38 2
    }
39
40 2
    public function handleQuery(Query $query, callable $next, callable $first)
41
    {
42 2
        $startTime = microtime(true);
43 2
        $logger = $this->logger;
0 ignored issues
show
$logger is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
45
        return $next($query)->then(function (Collection $result) use ($query, $startTime) {
46 1
            $duration = (microtime(true) - $startTime) * 1000;
47 1
            $this->logger->info(sprintf('[Geocoder] Got %d results in %0.2f ms for query %s', count($result), $duration, $query->__toString()));
48
49 1
            return $result;
50
        }, function (Exception $exception) use ($query, $startTime) {
51 1
            $duration = (microtime(true) - $startTime) * 1000;
52 1
            $this->logger->error(sprintf('[Geocoder] Failed with %s after %0.2f ms for query %s', get_class($exception), $duration, $query->__toString()));
53
54 1
            throw $exception;
55 2
        });
56
    }
57
}
58