for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Copyright (c) 2014 Viktar Dubiniuk <[email protected]>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Files_Antivirus;
use OCA\Files_Antivirus\Scanner\InitException;
use \OCP\ILogger;
class ScannerFactory{
* @var \OCA\Files_Antivirus\AppConfig
protected $appConfig;
* @var ILogger;
protected $logger;
* @var string
protected $scannerClass;
public function __construct(AppConfig $appConfig, ILogger $logger){
$this->appConfig = $appConfig;
$this->logger = $logger;
try {
$avMode = $appConfig->getAvMode();
switch ($avMode) {
case 'daemon':
$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Daemon';
break;
case 'socket':
$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Socket';
case 'executable':
$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Local';
default:
throw new InitException(
sprintf(
'Please check the settings at the admin page. Invalid mode: "%s"',
$avMode
)
);
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
}
} catch (InitException $e) {
// TODO: add a new config option to prevent upload on misconfiguration
// and check it here
$this->logger->warning(
'Application is misconfigured. %s',
$e->getMessage()
} catch (\Exception $e) {
$message = implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]);
$this->logger->warning($message);
* Produce a scanner instance
* @return \OCA\Files_Antivirus\Scanner\AbstractScanner
public function getScanner(){
return new $this->scannerClass($this->appConfig, $this->logger);
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
orexit
statements that have been added for debug purposes.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.