Remove php strict errors

refs #4448
This commit is contained in:
Marius Hein 2013-07-23 12:18:27 +02:00
parent 6ea048d4ef
commit 8d3ff94696
24 changed files with 94 additions and 50 deletions

View File

@ -19,13 +19,14 @@ class Backend
$name = AuthManager::getInstance()->getSession()->get('backend');
}
if ($name === null) {
$name = array_shift(array_keys($backends->toArray()));
$backendKeys = array_keys($backends->toArray());
$name = array_shift($backendKeys);
}
if (isset($backends->$name)) {
$config = $backends->$name;
$type = $config->type;
$type[0] = strtoupper($type[0]);
$class = '\\Icinga\\Backend\\' . $type;
$class = '\\Monitoring\\Backend\\' . $type;
self::$instances[$name] = new $class($config);
} else {
throw new \Exception(sprintf(

View File

@ -188,7 +188,7 @@ class Parser
throw new ParsingException("No $this->currentObjectType objects registered in objects.cache");
}
$base = & $this->icingaState[$this->currentObjectType];
$state = & $this->skipObject(true);
$state = $this->skipObject(true);
$statusdatObject->runtimeState = & $state;
$name = $this->getObjectIdentifier($statusdatObject);

View File

@ -259,9 +259,9 @@ class Query extends AbstractQuery
$result = array();
$source = self::$VALID_TARGETS[$this->source];
foreach ($source as $target) {
$indexes = & array_keys($state[$target]);
$indexes = array_keys($state[$target]);
if ($baseGroup) {
$indexes = & $baseGroup->filter($state[$target]);
$indexes = $baseGroup->filter($state[$target]);
}
if (!isset($result[$target])) {
$result[$target] = $indexes;
@ -292,8 +292,8 @@ class Query extends AbstractQuery
*/
private function orderResult($a, $b)
{
$o1 = & $this->ds->getObjectByName($this->currentType, $a);
$o2 = & $this->ds->getObjectByName($this->currentType, $b);
$o1 = $this->ds->getObjectByName($this->currentType, $a);
$o2 = $this->ds->getObjectByName($this->currentType, $b);
$result = 0;
foreach ($this->order_columns as $col) {
$result += $col[1] * strnatcasecmp($o1->{$col[0]}, $o2->{$col[0]});
@ -352,7 +352,7 @@ class Query extends AbstractQuery
$result = array();
foreach ($indices as $type => $subindices) {
foreach ($subindices as $objectIndex) {
$r = & $this->ds->getObjectByName($type, $objectIndex);
$r = $this->ds->getObjectByName($type, $objectIndex);
$hash = "";
$cols = array();
foreach ($this->groupColumns as $col) {
@ -377,7 +377,7 @@ class Query extends AbstractQuery
public function getResult()
{
$indices = & $this->getFilteredIndices();
$indices = $this->getFilteredIndices();
$this->orderIndices($indices);
if ($this->groupByFn) {
$scope = $this->groupByFn[self::FN_SCOPE];
@ -389,7 +389,7 @@ class Query extends AbstractQuery
$this->limitIndices($indices);
$result = array();
$state = & $this->ds->getObjects();
$state = $this->ds->getObjects();
foreach ($indices as $type => $subindices) {
foreach ($subindices as $index) {

View File

@ -379,7 +379,8 @@ class Group implements IQueryPart
if ($this->type == self::TYPE_OR) {
$idx = array();
foreach ($this->items as &$subFilter) {
$idx += $subFilter->filter($base, array_keys($base));
$baseKeys = array_keys($base);
$idx += $subFilter->filter($base, $baseKeys);
}
} else {
if (!$idx) {

View File

@ -242,7 +242,7 @@ class Reader implements IReader, DatasourceInterface
$this->parser = new Parser(fopen($this->config->objects_file, "r"));
}
$this->parser->parseObjectsFile();
$this->lastState = & $this->parser->getRuntimeState();
$this->lastState = $this->parser->getRuntimeState();
}
/**
@ -259,7 +259,7 @@ class Reader implements IReader, DatasourceInterface
$this->parser = new Parser(fopen($this->config->status_file, "r"), $this->lastState);
}
$this->parser->parseRuntimeState(fopen($this->config->status_file, "r"));
$this->lastState = & $this->parser->getRuntimeState();
$this->lastState = $this->parser->getRuntimeState();
if (!$this->noCache) {
$this->statusCache->save(array("true" => true), "state" . md5($this->config->objects_file));
}

View File

@ -155,6 +155,7 @@ class Monitoring_ListController extends ModuleActionController
-1,
PREG_SPLIT_NO_EMPTY
);
$this->view->extraColumns = $extra;
$query = $this->backend->select()
->from($view, array_merge($columns, $extra))

View File

@ -29,7 +29,11 @@ class Zend_View_Helper_MonitoringFlags extends Zend_View_Helper_Abstract
*/
private function getObjectType(array $vars)
{
return array_shift(explode('_', array_shift(array_keys($vars)), 2));
$keys = array_keys($vars);
$firstKey = array_shift($keys);
$keyParts = explode('_', $firstKey, 2);
return array_shift($keyParts);
}
/**

View File

@ -64,7 +64,9 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
*/
private function getObjectType(\stdClass $object)
{
return array_shift(explode('_', array_shift(array_keys(get_object_vars($object))), 2));
$keys = array_keys(get_object_vars($object));
$keyParts = explode('_', array_shift($keys), 2);
return array_shift($keyParts);
}
/**
@ -136,10 +138,14 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
$val .= self::VALUE_NA;
} else {
$val .= $this->floatFormatter($object->latency);
$val .= $this->floatFormatter(
(isset($object->latency)) ? $object->latency : 0
);
}
$val .= ' / '. $this->floatFormatter($object->execution_time). ' seconds';
$val .= ' / '. $this->floatFormatter(
isset($object->execution_time) ? $object->execution_time : 0
). ' seconds';
return $val;
}

View File

@ -1,5 +1,9 @@
<?php
$commandParts = preg_split('|!|', $object->check_command);
$commandName = array_shift($commandParts);
?>
<?= $this->expandable(
'<b>Command:</b> ' . array_shift(preg_split('|!|', $object->check_command)),
'<b>Command:</b> '. $commandName,
$this->commandArguments($object->check_command),
// TODO: no JS handler right now, should be collapsed
array('collapsed' => ! (bool) strpos($object->check_command, '!'))

View File

@ -11,6 +11,8 @@
);
}
}
$checkCommandParts = explode('!', $this->host->host_check_command, 2);
?>
<?=
$this->partial(
@ -42,7 +44,7 @@
<div>
<strong>Command:</strong>
<?= array_shift(explode('!', $this->host->host_check_command, 2)); ?>
<?= array_shift($checkCommandParts); ?>
<?= $this->commandArguments($this->host->host_check_command); ?>
</div>
</div>

View File

@ -33,7 +33,7 @@ class Backend
return key($configs);
}
public function getBackendConfigs()
public static function getBackendConfigs()
{
if (self::$backendConfigs === null) {
$backends = IcingaConfig::app('backends');
@ -45,7 +45,7 @@ class Backend
return self::$backendConfigs;
}
public function getBackend($name = null)
public static function getBackend($name = null)
{
if (! array_key_exists($name, self::$instances)) {
if ($name === null) {

View File

@ -39,9 +39,10 @@ class AbstractBackend implements DatasourceInterface
*
* Leave fields empty to get all available properties
*
* @param string Virtual table name
* @param array Fields
* return self
* @param string $virtual_table Virtual table name
* @param array $fields Fields
* @throws \Icinga\Exception\ProgrammingError
* @return self
*/
public function from($virtual_table, $fields = array())
{

View File

@ -114,7 +114,8 @@ abstract class AbstractQuery extends Query
protected function beforeCreatingSelectQuery()
{
$this->setRealColumns();
Benchmark::measure(sprintf('%s ready to run', array_pop(explode('\\', get_class($this)))));
$classParts = explode('\\', get_class($this));
Benchmark::measure(sprintf('%s ready to run', array_pop($classParts)));
}
protected function applyAllFilters()

View File

@ -73,7 +73,7 @@ class Statusdat extends AbstractBackend
* @param $host
* @return MonitoringObjectList|null
*/
public function fetchHost($host)
public function fetchHost($host, $fetchAll = false)
{
$objs = & $this->reader->getObjects();

View File

@ -130,6 +130,6 @@ class HostStatusView extends ObjectRemappingView
*/
public function __construct(IReader $reader)
{
$this->state = & $reader->getState();
$this->state = $reader->getState();
}
}

View File

@ -158,6 +158,6 @@ class ServiceStatusView extends ObjectRemappingView
*/
public function __construct(IReader $reader)
{
$this->state = & $reader->getState();
$this->state = $reader->getState();
}
}

View File

@ -138,7 +138,7 @@ abstract class GroupsummaryQuery extends Query
foreach ($subIndices as $objName) {
$obj = & $this->reader->getObjectByName($type, $objName);
$obj = $this->reader->getObjectByName($type, $objName);
$statetype = $this->getStateType($obj);
foreach ($obj->group as $group) {
if (!isset($result[$group])) {

View File

@ -250,7 +250,8 @@ abstract class Query extends AbstractQuery
{
$view = $this->viewClass;
if (!$this->cursor) {
$this->cursor = new MList($this->baseQuery->getResult(), new $view($this->reader));
$result = $this->baseQuery->getResult();
$this->cursor = new MList($result, new $view($this->reader));
}
return $this->cursor;
}

View File

@ -638,7 +638,9 @@ class Meta
*/
private function getObjectType(\stdClass $object)
{
return array_shift(explode('_', array_shift(array_keys(get_object_vars($object))), 2));
$objectKeys = array_keys(get_object_vars($object));
$firstKeys = explode('_', array_shift($objectKeys), 2);
return array_shift($firstKeys);
}
/**

View File

@ -233,12 +233,13 @@ class MonitoringView extends AbstractQuery
{
if ($this->query === null) {
$class = substr(
array_pop(preg_split('|\\\|', get_class($this))),
0,
-4
) . 'Query';
$class = '\\' . get_class($this->ds) . '\\Query\\' . $class;
$classParts = preg_split('|\\\|', get_class($this));
$class = substr(
array_pop($classParts),
0,
-4
) . 'Query';
$class = '\\' . get_class($this->ds) . '\\Query\\' . $class;
$query = new $class($this->ds, $this->columns);
foreach ($this->filters as $f) {
$query->where($f[0], $f[1]);

View File

@ -79,11 +79,15 @@ namespace Icinga\Web
namespace Test\Monitoring\Testlib
{
require_once 'Zend/View.php';
use Icinga\Protocol\Statusdat\Reader;
use Icinga\Web\ActionController;
use Test\Monitoring\Testlib\DataSource\TestFixture;
use Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
use Monitoring\Backend\Ido;
use Monitoring\Backend\Statusdat;
use \Zend_View;
/**
* Base class for monitoring controllers that loads required dependencies
@ -227,8 +231,13 @@ namespace Test\Monitoring\Testlib
{
require_once($this->moduleDir.'/application/controllers/'.$controller.'.php');
$controllerName = '\Monitoring_'.ucfirst($controller);
/** @var ActionController $controller */
$controller = new $controllerName;
$controller->setBackend($this->getBackendFor($backend));
// Many controllers need a view to work properly
$controller->view = new Zend_View();
return $controller;
}

View File

@ -21,6 +21,12 @@ use \Icinga\Application\Logger as Logger;
**/
class LoggerTest extends \PHPUnit_Framework_TestCase
{
private $timeZone;
protected function setUp()
{
date_default_timezone_set('GMT');
}
public function testOverwrite() {
$cfg1 = new \Zend_Config(array(

View File

@ -41,6 +41,10 @@ abstract class LibraryLoader {
}
}
abstract public static function requireLibrary();
/**
* Should be abstract but in php this should not be
*/
public static function requireLibrary()
{
}
}

View File

@ -22,7 +22,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$query = new Statusdat\Query($readerMock);
$result = & $query->from("services")->getResult();
$result = $query->from("services")->getResult();
$objects = $readerMock->getObjects();
$this->assertCount(count($objects["service"]), $result);
@ -33,7 +33,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$query = new Statusdat\Query($readerMock);
$result = & $query->from("hosts")->getResult();
$result = $query->from("hosts")->getResult();
$objects = $readerMock->getObjects();
$this->assertCount(count($objects["host"]), $result);
@ -45,7 +45,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->limit(2)->getResult();
$result = $query->from("services")->limit(2)->getResult();
$this->assertCount(2, $result);
}
@ -56,7 +56,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = & $query->from("services")->limit(2, 4)->getResult();
$result = $query->from("services")->limit(2, 4)->getResult();
$this->assertCount(2, $result);
}
@ -66,7 +66,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->groupByColumns("numeric_val")->getResult();
$result = $query->from("services")->groupByColumns("numeric_val")->getResult();
$this->assertCount(3,$result);
foreach($result as $value) {
$this->assertTrue(isset($value->count));
@ -81,7 +81,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->order('numeric_val ASC')->groupByColumns("numeric_val")->getResult();
$result = $query->from("services")->order('numeric_val ASC')->groupByColumns("numeric_val")->getResult();
$this->assertCount(3,$result);
$lastIdx = ~PHP_INT_MAX;
foreach($result as $sstatus) {
@ -101,7 +101,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->order('numeric_val ASC')->getResult();
$result = $query->from("services")->order('numeric_val ASC')->getResult();
$lastIdx = ~PHP_INT_MAX;
foreach($result as $sstatus) {
$this->assertGreaterThanOrEqual($lastIdx,$sstatus->numeric_val);
@ -114,7 +114,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->order('numeric_val DESC')->getResult();
$result = $query->from("services")->order('numeric_val DESC')->getResult();
$lastIdx = PHP_INT_MAX;
foreach($result as $sstatus) {
$this->assertLessThanOrEqual($lastIdx,$sstatus->numeric_val);
@ -131,17 +131,17 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$readerMock = $this->getServiceTestReader();
$objects = $readerMock->getObjects();
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->where('numeric_val = ?',array(1))->getResult();
$result = $query->from("services")->where('numeric_val = ?',array(1))->getResult();
foreach($result as $testresult) {
$this->assertEquals($testresult->numeric_val,1);
}
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->getResult();
$result = $query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->getResult();
foreach($result as $testresult) {
$this->assertNotEquals($testresult->numeric_val,2);
}
$query = new Statusdat\Query($readerMock);
$result = &$query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->where("numeric_val = ?",array(1))->getResult();
$result = $query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->where("numeric_val = ?",array(1))->getResult();
foreach($result as $testresult) {
$this->assertEquals($testresult->numeric_val,1);
}