for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace eXpansion\Bundle\Acme\Plugins\Gui;
use eXpansion\Bundle\Acme\Plugins\Test;
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
use eXpansion\Framework\Core\Model\Gui\Widget;
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
use FML\Controls\Label;
use FML\Script\Script;
use FML\Script\ScriptLabel;
class MemoryWidgetFactory extends WidgetFactory
{
/** @var Label */
protected $memoryMessage;
public static $exp_hash;
/**
* @param ManialinkInterface|Widget $manialink
*/
protected function createContent(ManialinkInterface $manialink)
$this->memoryMessage = new Label();
$this->memoryMessage->setTextPrefix('$s')->setText("waiting data...");
$manialink->addChild($this->memoryMessage);
self::$exp_hash = uniqid("exp");
}
protected function updateContent(ManialinkInterface $manialink)
$this->memoryMessage->setText(Test::$memoryMsg);
$now = uniqid("exp2");
$now
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.
$myVar
$higher
$message = "Time now:".date("h:i:s");
$hash = self::$exp_hash;
$script = new Script();
$script->addCustomScriptLabel(ScriptLabel::OnInit,
'
declare Text '.$hash.' for LocalUser = Text;
'.$hash.' = "'.$message.'";
declare Text '.$hash.'_check for LocalUser = "";
'.$hash.'_check = "$now";
);
$manialink->getFmlManialink()->setScript($script);
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.