jdel /
sspks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SSpkS\Handler; |
||
| 4 | |||
| 5 | use \SSpkS\Device\DeviceList; |
||
| 6 | use \SSpkS\Output\UrlFixer; |
||
| 7 | use \SSpkS\Package\PackageFinder; |
||
| 8 | use \SSpkS\Package\PackageFilter; |
||
| 9 | |||
| 10 | // if ($_SERVER['REQUEST_METHOD'] == 'GET') |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | class BrowserHandler implements HandlerInterface |
||
| 13 | { |
||
| 14 | private $config; |
||
| 15 | |||
| 16 | public function __construct(\SSpkS\Config $config) |
||
| 17 | { |
||
| 18 | $this->config = $config; |
||
| 19 | } |
||
| 20 | |||
| 21 | public function handle() |
||
| 22 | { |
||
| 23 | // GET-request, probably browser --> show HTML |
||
| 24 | $arch = trim($_GET['arch']); |
||
| 25 | $channel = trim($_GET['channel']); |
||
| 26 | if ($channel != 'beta') { |
||
| 27 | $channel = 'stable'; |
||
| 28 | } |
||
| 29 | $fullList = trim($_GET['fulllist']); |
||
| 30 | $packagesAvailable = array(); |
||
|
0 ignored issues
–
show
$packagesAvailable 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 Loading history...
|
|||
| 31 | |||
| 32 | $mustache = new \Mustache_Engine(array( |
||
| 33 | 'loader' => new \Mustache_Loader_FilesystemLoader($this->config->basePath . '/data/templates'), |
||
|
0 ignored issues
–
show
The property
$basePath is declared private in SSpkS\Config. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 34 | 'partials_loader' => new \Mustache_Loader_FilesystemLoader($this->config->basePath . '/data/templates/partials'), |
||
|
0 ignored issues
–
show
The property
$basePath is declared private in SSpkS\Config. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 35 | 'charset' => 'utf-8', |
||
| 36 | 'logger' => new \Mustache_Logger_StreamLogger('php://stderr'), |
||
| 37 | )); |
||
| 38 | |||
| 39 | $tpl_vars = array( |
||
| 40 | 'siteName' => $this->config->site['name'], |
||
| 41 | 'arch' => $arch, |
||
| 42 | 'channel' => ($channel == 'beta'), |
||
| 43 | 'requestUri' => $_SERVER['REQUEST_URI'], |
||
| 44 | 'baseUrl' => $this->config->baseUrl, |
||
|
0 ignored issues
–
show
The property
baseUrl does not exist on object<SSpkS\Config>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 45 | 'fullList' => $fullList, |
||
| 46 | ); |
||
| 47 | |||
| 48 | if ($arch) { |
||
| 49 | // Architecture is set --> show packages for that arch |
||
| 50 | $pkgs = new PackageFinder($this->config->paths['packages']); |
||
| 51 | $pkgf = new PackageFilter($pkgs->getAllPackages()); |
||
| 52 | $pkgf->setArchitectureFilter($arch); |
||
| 53 | $pkgf->setChannelFilter($channel); |
||
| 54 | $pkgf->setFirmwareVersionFilter(false); |
||
| 55 | $pkgf->setOldVersionFilter(true); |
||
| 56 | $filteredPkgList = $pkgf->getFilteredPackageList(); |
||
| 57 | |||
| 58 | $uf = new UrlFixer($this->config->baseUrl); |
||
|
0 ignored issues
–
show
The property
baseUrl does not exist on object<SSpkS\Config>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 59 | $uf->fixPackageList($filteredPkgList); |
||
| 60 | |||
| 61 | $packages = array(); |
||
| 62 | foreach ($filteredPkgList as $pkg) { |
||
| 63 | $packages[] = $pkg->getMetadata(); |
||
| 64 | } |
||
| 65 | |||
| 66 | $tpl_vars['packagelist'] = array_values($packages); |
||
| 67 | $tpl = $mustache->loadTemplate('html_packagelist'); |
||
| 68 | } elseif ($fullList) { |
||
| 69 | // No architecture, but full list of packages requested --> show simple list |
||
| 70 | $pkgs = new PackageFinder($this->config->paths['packages']); |
||
| 71 | $packagesList = $pkgs->getAllPackageFiles(); |
||
| 72 | |||
| 73 | // Prepare data for template |
||
| 74 | $packages = array(); |
||
| 75 | foreach ($packagesList as $spkFile) { |
||
| 76 | $packages[] = array( |
||
| 77 | 'url' => $baseUrl . $spkFile, |
||
|
0 ignored issues
–
show
|
|||
| 78 | 'filename' => basename($spkFile), |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | $tpl_vars['packagelist'] = $packages; |
||
| 82 | $tpl = $mustache->loadTemplate('html_packagelist_all'); |
||
| 83 | } else { |
||
| 84 | // Nothing requested --> show models overview |
||
| 85 | try { |
||
| 86 | $deviceList = new DeviceList($this->config->paths['models']); |
||
| 87 | $models = $deviceList->getDevices(); |
||
| 88 | if (count($models) == 0) { |
||
| 89 | $tpl = $mustache->loadTemplate('html_modellist_none'); |
||
| 90 | } else { |
||
| 91 | $tpl_vars['modellist'] = $models; |
||
| 92 | $tpl = $mustache->loadTemplate('html_modellist'); |
||
| 93 | } |
||
| 94 | } catch (\Exception $e) { |
||
| 95 | $tpl_vars['errorMessage'] = $e->getMessage(); |
||
| 96 | $tpl = $mustache->loadTemplate('html_modellist_error'); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | echo $tpl->render($tpl_vars); |
||
| 100 | } |
||
| 101 | } |
||
| 102 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.