for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* Copyright Andrea Heigl <[email protected]>
*
* Licenses under the MIT-license. For details see the included file LICENSE.md
*/
namespace Callingallpapers\Subcommands\Sessionize\Parser;
use DOMDocument;
use DOMXPath;
class Location
{
public function parse(DOMDocument $dom, DOMXPath $xpath) : string
$dom
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
// This expression does not work. It looks like the reason is the array-notation...
//$locations = $xpath->query('//div[contains(text()[2], "location")]/following-sibling::h2/span');
$locationMarker = $xpath->query("//div[contains(., 'location')]");
if (! $locationMarker || $locationMarker->length == 0) {
throw new \InvalidArgumentException('The Event does not seem to have a locationMarker');
}
$locations = $xpath->query('//h2/span', $locationMarker->item(0)->parentNode);
if (! $locations || $locations->length == 0) {
throw new \InvalidArgumentException('The Event does not seem to have a location');
$location = [];
foreach ($locations as $item) {
$location = trim($item->textContent);
if ($location === '') {
continue;
return $location;
$location[] = $location;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
return implode(', ', array_unique($location));
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.