geocoder-php /
plugin
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
|
|||
| 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 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.