for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace JMGQ\AStar\Example\Graph;
class SequencePrinter
{
/**
* @param Graph $graph
* @param Coordinate[] $sequence
*/
public function __construct(private Graph $graph, private iterable $sequence)
$graph
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function __construct(/** @scrutinizer ignore-unused */ private Graph $graph, private iterable $sequence)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
$sequence
public function __construct(private Graph $graph, /** @scrutinizer ignore-unused */ private iterable $sequence)
}
public function printSequence(): void
$coordinatesAsString = [];
foreach ($this->sequence as $coordinate) {
sequence
JMGQ\AStar\Example\Graph\SequencePrinter
$coordinatesAsString[] = $this->getCoordinateAsString($coordinate);
if (!empty($coordinatesAsString)) {
echo implode(' => ', $coordinatesAsString);
echo "\n";
echo 'Total cost: ' . $this->getTotalDistance();
private function getCoordinateAsString(Coordinate $coordinate): string
return "({$coordinate->getX()}, {$coordinate->getY()})";
private function getTotalDistance(): float | int
if (count($this->sequence) < 2) {
return 0;
$totalDistance = 0;
$sequence = $this->sequence;
$previousNode = array_shift($sequence);
foreach ($sequence as $node) {
$totalDistance += $this->graph->getLink($previousNode, $node)->getDistance();
graph
$previousNode = $node;
return $totalDistance;
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.