application: PSR2 fixes

This commit is contained in:
Thomas Gelf 2016-02-26 12:42:21 +01:00
parent f2a1ec91f7
commit 067c82c074
31 changed files with 162 additions and 104 deletions

View File

@ -15,8 +15,8 @@ class BenchmarkCommand extends Command
$flat = array();
$filter = Filter::fromQueryString(
// 'object_name=*ic*2*&object_type=object'
'vars.bpconfig=*'
// 'object_name=*ic*2*&object_type=object'
'vars.bpconfig=*'
);
Benchmark::measure('ready');
$objs = IcingaHost::loadAll($this->db());
@ -33,7 +33,10 @@ class BenchmarkCommand extends Command
$vars = IcingaHostVar::loadAll($this->db());
Benchmark::measure('vars loaded');
foreach ($vars as $var) {
if (! array_key_exists($var->host_id, $flat)) continue; // Templates?
if (! array_key_exists($var->host_id, $flat)) {
// Templates?
continue;
}
$flat[$var->host_id]->{'vars.' . $var->varname} = $var->varvalue;
}
Benchmark::measure('vars done');

View File

@ -8,9 +8,8 @@ use Icinga\Module\Director\KickstartHelper;
/**
* Kickstart a Director installation
*
* Once you prepared your DB resource and created
* This command retrieves information about unapplied database migration and
* helps applying them.
* Once you prepared your DB resource this command retrieves information about
* unapplied database migration and helps applying them.
*/
class KickstartCommand extends Command
{

View File

@ -25,7 +25,7 @@ class MigrationCommand extends Command
* }
*
* Exit code 0 means that there are pending migrations, code 1 that there
* are no such. Use --verbose
* are no such. Use --verbose
*/
public function pendingAction()
{

View File

@ -29,7 +29,7 @@ class CommandController extends ObjectController
->setCommandObject($this->object)
->setFilter(Filter::where('command', $this->params->get('name')));
$form = $this->view->form = $this
$form = $this->view->form = $this
->loadForm('icingaCommandArgument')
->setCommandObject($this->object);

View File

@ -120,8 +120,10 @@ class ConfigController extends ActionController
{
$config = IcingaConfig::generate($this->db());
$this->redirectNow(
Url::fromPath('director/config/show',
array('checksum' => $config->getHexChecksum()))
Url::fromPath(
'director/config/show',
array('checksum' => $config->getHexChecksum())
)
);
}
}

View File

@ -20,7 +20,7 @@ class DatalistController extends ActionController
{
$edit = false;
if($id = $this->params->get('id')) {
if ($id = $this->params->get('id')) {
$edit = true;
}

View File

@ -23,7 +23,7 @@ class DatalistentryController extends ActionController
$listId = $this->params->get('list_id');
$this->view->lastId = $listId;
if($this->params->get('list_id') && $entryName = $this->params->get('entry_name')) {
if ($this->params->get('list_id') && $entryName = $this->params->get('entry_name')) {
$edit = true;
}

View File

@ -35,7 +35,9 @@ class HostController extends ObjectController
{
$this->getTabs()->activate('services');
$this->view->title = $this->translate('Services');
$this->view->table = $this->loadTable('IcingaService')->enforceFilter('host_id', $this->object->id)->setConnection($this->db());
$this->view->table = $this->loadTable('IcingaService')
->enforceFilter('host_id', $this->object->id)
->setConnection($this->db());
$this->render('objects/table', null, true);
}
@ -61,10 +63,18 @@ class HostController extends ObjectController
{
$host = $this->object;
$db = $this->db();
if ($host->object_type !== 'object') return;
if ($host->getResolvedProperty('has_agent') !== 'y') return;
if ($host->object_type !== 'object') {
return;
}
if ($host->getResolvedProperty('has_agent') !== 'y') {
return;
}
$name = $host->object_name;
if (IcingaEndpoint::exists($name, $db)) continue;
if (IcingaEndpoint::exists($name, $db)) {
return;
}
$props = array(
'object_name' => $name,

View File

@ -66,15 +66,18 @@ class ImportsourceController extends ActionController
$id = $this->params->get('source_id');
$this->prepareTabs($id)->activate('modifier');
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add property modifier'),
'director/importsource/addmodifier',
array('source_id' => $id)
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add property modifier'),
'director/importsource/addmodifier',
array('source_id' => $id)
);
$this->view->title = $this->translate('Property modifiers');
$this->view->table = $this->loadTable('propertymodifier')->enforceFilter(Filter::where('source_id', $id))->setConnection($this->db());
$this->view->table = $this->loadTable('propertymodifier')
->enforceFilter(Filter::where('source_id', $id))
->setConnection($this->db());
$this->render('list/table', null, true);
}
@ -129,7 +132,10 @@ class ImportsourceController extends ActionController
$tabs = $this->prepareTabs($source_id)->activate('modifier');
$this->view->title = $this->translate('Modifier'); // add/edit
$this->view->table = $this->loadTable('propertymodifier')->enforceFilter(Filter::where('source_id', $source_id))->setConnection($this->db());
$this->view->table = $this->loadTable('propertymodifier')
->enforceFilter(Filter::where('source_id', $source_id))
->setConnection($this->db());
$this->render('list/table', null, true);
}

View File

@ -89,7 +89,8 @@ class InspectController extends ActionController
public function statusAction()
{
$this->view->status = $status = $this->api()->getStatus();
print_r($status); exit;
print_r($status);
exit;
}
protected function api($endpointName = null)

View File

@ -25,7 +25,7 @@ class ListController extends ActionController
$this->view->title = $this->translate('Deployments');
$this->prepareTable('deploymentLog');
try {
// Move elsewhere
$this->view->table->setActiveStageName(
$this->api()->getActiveStageName()
);
@ -57,11 +57,12 @@ class ListController extends ActionController
public function datalistAction()
{
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add list'),
'director/datalist/add'
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add list'),
'director/datalist/add'
);
$this->setConfigTabs()->activate('datalist');
$this->view->title = $this->translate('Data lists');
@ -73,11 +74,12 @@ class ListController extends ActionController
$listId = $this->params->get('list_id');
$this->view->lastId = $listId;
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add entry'),
'director/datalistentry/add' . '?list_id=' . $listId
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add entry'),
'director/datalistentry/add' . '?list_id=' . $listId
);
$this->view->title = $this->translate('List entries');
$this->getTabs()->add('editlist', array(
@ -93,11 +95,12 @@ class ListController extends ActionController
public function datafieldAction()
{
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add field'),
'director/datafield/add'
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add field'),
'director/datafield/add'
);
$this->setConfigTabs()->activate('datafield');
$this->view->title = $this->translate('Data fields');
@ -106,11 +109,12 @@ class ListController extends ActionController
public function importsourceAction()
{
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add import source'),
'director/importsource/add'
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add import source'),
'director/importsource/add'
);
$this->setImportTabs()->activate('importsource');
$this->view->title = $this->translate('Import source');
@ -127,11 +131,12 @@ class ListController extends ActionController
public function syncruleAction()
{
$this->view->addLink = $this->view->icon('plus') . ' '
. $this->view->qlink(
$this->translate('Add sync rule'),
'director/syncrule/add'
);
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add sync rule'),
'director/syncrule/add'
);
$this->setImportTabs()->activate('syncrule');
$this->view->title = $this->translate('Sync rule');
@ -155,8 +160,8 @@ class ListController extends ActionController
}
if (in_array('startup.log', $availableFiles)
&& in_array('status', $availableFiles))
{
&& in_array('status', $availableFiles)
) {
if ($api->getStagedFile($stage, 'status') === '0') {
$deployment->startup_succeeded = 'y';
} else {

View File

@ -107,11 +107,12 @@ class ShowController extends ActionController
. '</p>';
}
$this->view->output = $error . ' <pre'
. ($object->disabled === 'y' ? ' class="disabled"' : '').
'>' . $this->view->escape(
(string) $object
) . '</pre>';
$this->view->output = $error
. ' <pre'
. ($object->disabled === 'y' ? ' class="disabled"' : '')
. '>'
. $this->view->escape((string) $object)
. '</pre>';
}
protected function showInfo($entry)

View File

@ -75,12 +75,13 @@ class SyncruleController extends ActionController
$this->view->stayHere = true;
$id = $this->params->get('rule_id');
$this->view->addLink = $this->view->icon('plus') . ' '
$this->view->addLink = $this->view->icon('plus')
. ' '
. $this->view->qlink(
$this->translate('Add sync property rule'),
'director/syncrule/addproperty',
array('rule_id' => $id)
);
$this->translate('Add sync property rule'),
'director/syncrule/addproperty',
array('rule_id' => $id)
);
$this->getTabs()->add('edit', array(
'url' => 'director/syncrule/edit',
'urlParams' => array('id' => $id),
@ -92,7 +93,9 @@ class SyncruleController extends ActionController
))->activate('property');
$this->view->title = $this->translate('Sync properties: ');
$this->view->table = $this->loadTable('syncproperty')->enforceFilter(Filter::where('rule_id', $id))->setConnection($this->db());
$this->view->table = $this->loadTable('syncproperty')
->enforceFilter(Filter::where('rule_id', $id))
->setConnection($this->db());
$this->render('list/table', null, true);
}
@ -146,8 +149,9 @@ class SyncruleController extends ActionController
$tabs->activate('property');
$this->view->title = $this->translate('Sync property'); // add/edit
$this->view->table = $this->loadTable('syncproperty')->enforceFilter(Filter::where('rule_id', $rule_id))->setConnection($this->db());
$this->view->table = $this->loadTable('syncproperty')
->enforceFilter(Filter::where('rule_id', $rule_id))
->setConnection($this->db());
$this->render('list/table', null, true);
}
}

View File

@ -75,8 +75,7 @@ class ConfigForm extends QuickForm
if (! $this->hasBeenSent()) {
$hint = $this->translate(
'Configuration looks good, you should be ready to %s'
. ' Icinga Director'
'Configuration looks good, you should be ready to %s Icinga Director'
);
$link = $this->getView()->qlink(
$this->translate('start using'),
@ -94,7 +93,7 @@ class ConfigForm extends QuickForm
$hint = $this->translate(
'Please make sure that your database grants enough permissions'
. ' and that you deployed the correct %s.'
. ' and that you deployed the correct %s.'
);
$link = $this->getView()->qlink(
$this->translate('database schema'),

View File

@ -101,9 +101,15 @@ class DirectorDatafieldForm extends DirectorObjectForm
$global = array('varname', 'description', 'caption', 'datatype');
foreach ($this->getElements() as $el) {
if ($el->getIgnore()) continue;
if ($el->getIgnore()) {
continue;
}
$name = $el->getName();
if (in_array($name, $global)) continue;
if (in_array($name, $global)) {
continue;
}
$names[$name] = $name;
}

View File

@ -40,7 +40,7 @@ class IcingaAssignServiceToHostForm extends QuickForm
if ($this->icingaObject->isTemplate()) {
$this->addHtmlHint(
'Assign all services importing this service template to one or'
. ' more hosts'
. ' more hosts'
);
} else {
$this->addHtmlHint(

View File

@ -45,14 +45,15 @@ class IcingaCloneObjectForm extends QuickForm
);
$msg = sprintf(
'The %s "%s" has been cloned from "%s"',
'The %s "%s" has been cloned from "%s"',
$object->getShortTableName(),
$newname,
$object->object_name
);
$new = $object::fromPlainObject(
$object->toPlainObject($resolve), $object->getConnection()
$object->toPlainObject($resolve),
$object->getConnection()
)->set('object_name', $newname);
if ($new->store()) {

View File

@ -65,7 +65,7 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
protected function beforeValidation($data = array())
{
if (isset($data['argument_value']) && $value = $data['argument_value']) {
if (preg_match_all('/\$([a-z0-9_]+)\$/', $value, $m, PREG_PATTERN_ORDER)) {
if (preg_match_all('/\$([a-z0-9_]+)\$/', $value, $m, PREG_PATTERN_ORDER)) {
foreach ($m[1] as $var) {
// $this->addCustomVariable($var);
}

View File

@ -38,7 +38,12 @@ class IcingaCommandForm extends DirectorObjectForm
$this->addElement('text', 'command', array(
'label' => $this->translate('Command'),
'required' => ! $this->isTemplate(),
'description' => $this->translate('The command Icinga should run. Absolute paths are accepted as provided, relative paths are prefixed with "PluginDir + ", similar Constant prefixes are allowed. Spaces will lead to separation of command path and standalone arguments. Please note that this means that we do not support spaces in plugin names and paths right now.')
'description' => $this->translate(
'The command Icinga should run. Absolute paths are accepted as provided,'
. ' relative paths are prefixed with "PluginDir + ", similar Constant prefixes are allowed.'
. ' Spaces will lead to separation of command path and standalone arguments. Please note that'
. ' this means that we do not support spaces in plugin names and paths right now.'
)
));
$this->addElement('text', 'timeout', array(

View File

@ -24,7 +24,10 @@ class IcingaHostForm extends DirectorObjectForm
$this->addElement('text', 'address', array(
'label' => $this->translate('Host address'),
'description' => $this->translate('Host address. Usually an IPv4 address, but may be any kind of address your check plugin is able to deal with')
'description' => $this->translate(
'Host address. Usually an IPv4 address, but may be any kind of address'
. ' your check plugin is able to deal with'
)
));
$this->addElement('text', 'address6', array(

View File

@ -28,10 +28,10 @@ class IcingaObjectFieldForm extends DirectorObjectForm
$this->addHtmlHint(
'Custom data fields allow you to easily fill custom variables with'
. " meaningful data. It's perfectly legal to override inherited fields."
. ' You may for example want to allow "network devices" specifying any'
. ' string for vars.snmp_community, but restrict "customer routers" to'
. ' a specific set, shown as a dropdown.'
. " meaningful data. It's perfectly legal to override inherited fields."
. ' You may for example want to allow "network devices" specifying any'
. ' string for vars.snmp_community, but restrict "customer routers" to'
. ' a specific set, shown as a dropdown.'
);
// TODO: remove assigned ones!
@ -92,8 +92,7 @@ class IcingaObjectFieldForm extends DirectorObjectForm
if (empty($fields)) {
// TODO: show message depending on permissions
$msg = $this->translate(
'There are no data fields available.'
. ' Please ask an administrator to create such'
'There are no data fields available. Please ask an administrator to create such'
);
$this->getElement('datafield_id')->addError($msg);

View File

@ -13,7 +13,8 @@ class KickstartForm extends QuickForm
{
$this->addHtmlHint(
$this->translate(
'Your installation of Icinga Director has not yet been prepared for deployments. This kickstart wizard will assist you with setting up the connection to your Icinga 2 server'
'Your installation of Icinga Director has not yet been prepared for deployments.'
. ' This kickstart wizard will assist you with setting up the connection to your Icinga 2 server'
)
);

View File

@ -89,13 +89,13 @@ class SyncPropertyForm extends DirectorObjectForm
if ($this->hasObject()) {
if (($col = $this->getObject()->getSourceColumn()) === null) {
$this->setElementValue('source_column', self::EXPRESSION);
$this->addElement('text', 'source_expression', array(
'label' => $this->translate('Source Expression'),
'required' => true,
));
if ($this->getSentValue('source_column') === '${' . self::EXPRESSION . '}') {
unset($this->source_column);
}
$this->addElement('text', 'source_expression', array(
'label' => $this->translate('Source Expression'),
'required' => true,
));
if ($this->getSentValue('source_column') === '${' . self::EXPRESSION . '}') {
unset($this->source_column);
}
} else {
$this->setElementValue('source_column', $col);
}
@ -145,7 +145,9 @@ class SyncPropertyForm extends DirectorObjectForm
if ($isCustomvar || $destination === 'vars') {
$this->addElement('select', 'merge_policy', array(
'label' => $this->translate('Merge Policy'),
'description' => $this->translate('Whether you want to merge or replace the destination field. Makes no difference for strings'),
'description' => $this->translate(
'Whether you want to merge or replace the destination field. Makes no difference for strings'
),
'required' => true,
'multiOptions' => $this->optionalEnum(array(
'merge' => 'merge',
@ -244,7 +246,9 @@ class SyncPropertyForm extends DirectorObjectForm
}
foreach ($dummy->listProperties() as $prop) {
if ($prop === 'id') continue;
if ($prop === 'id') {
continue;
}
// TODO: allow those fields, but munge them (store ids)
//if (preg_match('~_id$~', $prop)) continue;

View File

@ -8,7 +8,7 @@ class SyncRuleForm extends DirectorObjectForm
{
public function setup()
{
$availableTypes = array(
$availableTypes = array(
'command' => $this->translate('Command'),
'endpoint' => $this->translate('Endpoint'),
'host' => $this->translate('Host'),
@ -39,7 +39,7 @@ class SyncRuleForm extends DirectorObjectForm
'label' => $this->translate('Update Policity'),
'description' => $this->translate('Whether the field should be merged, replaced or ignored'),
'required' => true,
'multiOptions' => $this->optionalEnum(array(
'multiOptions' => $this->optionalEnum(array(
'merge' => 'merge',
'override' => 'replace',
'ignore' => 'ignore'
@ -50,7 +50,7 @@ class SyncRuleForm extends DirectorObjectForm
'label' => $this->translate('Purge'),
'description' => $this->translate('Purge existing values.'),
'required' => true,
'multiOptions' => $this->optionalEnum(array(
'multiOptions' => $this->optionalEnum(array(
'y' => 'yes',
'n' => 'no'
))

View File

@ -35,8 +35,8 @@ class DeploymentLogTable extends QuickTable
}
if ($this->activeStageName !== null
&& $row->stage_name === $this->activeStageName)
{
&& $row->stage_name === $this->activeStageName
) {
$classes[] = 'running';
}

View File

@ -27,7 +27,13 @@ class GeneratedConfigFileTable extends QuickTable
protected function getActionUrl($row)
{
return $this->url('director/config/file', array('config_checksum' => $row->config_checksum, 'file_path' => $row->file_path));
return $this->url(
'director/config/file',
array(
'config_checksum' => $row->config_checksum,
'file_path' => $row->file_path
)
);
}
public function getTitles()

View File

@ -44,7 +44,7 @@ class ImportrunTable extends QuickTable
$db->select()->from(
array('sub' => $this->getBaseQuery()->columns($this->getColumns())),
'COUNT(*)'
)
)
);
}

View File

@ -111,7 +111,7 @@ class ImportsourceHookTable extends QuickTable
public function getBaseQuery()
{
$ds = new ArrayDatasource($this->sourceHook()->fetchData());
$ds = new ArrayDatasource($this->sourceHook()->fetchData());
return $ds->select();
}
}

View File

@ -48,7 +48,7 @@ class ImportsourceTable extends QuickTable
return array();
}
try {
$import = new Import(ImportSource::load($row->id,$this->connection()));
$import = new Import(ImportSource::load($row->id, $this->connection()));
if ($import->providesChanges()) {
$row->source_name = sprintf(
'%s (%s)',

View File

@ -80,8 +80,8 @@ class SyncruleTable extends QuickTable
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'sync_rule'),
array()
array('s' => 'sync_rule'),
array()
)->order('rule_name');
return $query;

View File

@ -1,8 +1,11 @@
<?php
// Avoid complaints about missing namespace and invalid class name
// @codingStandardsIgnoreStart
use Icinga\Module\Director\PlainObjectRenderer;
class Zend_View_Helper_RenderPlainObject extends Zend_View_Helper_Abstract
// @codingStandardsIgnoreEnd
{
public function renderPlainObject($object)
{