Don't perform static calls on traits

This commit is contained in:
Johannes Meyer 2022-01-14 11:32:00 +01:00
parent 6db579fe46
commit aff4079986
6 changed files with 28 additions and 35 deletions

View file

@ -3,11 +3,9 @@
namespace Icinga\Module\Graphite\Controllers;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRangePicker;
use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRangePickerFormTrait;
use Icinga\Module\Graphite\Util\TimeRangePickerTools;
use Icinga\Module\Graphite\Web\Controller\MonitoringAwareController;
use Icinga\Module\Graphite\Web\Controller\TimeRangePickerTrait;
use Icinga\Module\Graphite\Web\Widget\Graphs;
use Icinga\Module\Monitoring\DataView\DataView;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
@ -44,7 +42,7 @@ class ListController extends MonitoringAwareController
$hostsQuery->applyFilter(Filter::expression('host_perfdata', '!=', ''));
$this->view->baseUrl = $baseUrl = Url::fromPath('monitoring/host/show');
TimeRangePickerFormTrait::copyAllRangeParameters(
TimeRangePickerTools::copyAllRangeParameters(
$baseUrl->getParams(),
$this->getRequest()->getUrl()->getParams()
);
@ -82,13 +80,13 @@ class ListController extends MonitoringAwareController
$servicesQuery->applyFilter(Filter::expression('service_perfdata', '!=', ''));
$this->view->hostBaseUrl = $hostBaseUrl = Url::fromPath('monitoring/host/show');
TimeRangePickerFormTrait::copyAllRangeParameters(
TimeRangePickerTools::copyAllRangeParameters(
$hostBaseUrl->getParams(),
$this->getRequest()->getUrl()->getParams()
);
$this->view->serviceBaseUrl = $serviceBaseUrl = Url::fromPath('monitoring/service/show');
TimeRangePickerFormTrait::copyAllRangeParameters(
TimeRangePickerTools::copyAllRangeParameters(
$serviceBaseUrl->getParams(),
$this->getRequest()->getUrl()->getParams()
);
@ -127,7 +125,7 @@ class ListController extends MonitoringAwareController
null,
array_merge(
['format', 'stateType', 'addColumns', 'problems', 'graphs_limit'],
TimeRangePicker::getAllRangeParameters()
TimeRangePickerTools::getAllRangeParameters()
)
);
$this->handleFormatRequest($dataView);

View file

@ -2,14 +2,12 @@
namespace Icinga\Module\Graphite\Forms\TimeRangePicker;
use Icinga\Module\Graphite\Util\TimeRangePickerTools;
use Icinga\Web\Form;
use Zend_Form_Decorator_HtmlTag;
use Zend_Form_Element_Select;
class CommonForm extends Form
{
use TimeRangePickerTrait;
/**
* The selectable units with themselves in seconds
*
@ -101,7 +99,7 @@ class CommonForm extends Form
public function onSuccess()
{
$this->formToUrl();
$this->getRedirectUrl()->remove(array_values(static::getAbsoluteRangeParameters()));
$this->getRedirectUrl()->remove(array_values(TimeRangePickerTools::getAbsoluteRangeParameters()));
}
/**
@ -145,13 +143,13 @@ class CommonForm extends Form
protected function urlToForm()
{
$params = $this->getRedirectUrl()->getParams();
$seconds = $this->getRelativeSeconds($params);
$seconds = TimeRangePickerTools::getRelativeSeconds($params);
if ($seconds === null && count(array_intersect_key(
$params->toArray(false),
array_keys($this->getAllRangeParameters())
array_keys(TimeRangePickerTools::getAllRangeParameters())
)) === 0) {
$seconds = $this->getDefaultRelativeTimeRange();
$seconds = TimeRangePickerTools::getDefaultRelativeTimeRange();
}
if ($seconds !== null) {
@ -172,7 +170,7 @@ class CommonForm extends Form
}
}
$params->remove(static::getRelativeRangeParameter());
$params->remove(TimeRangePickerTools::getRelativeRangeParameter());
}
}
@ -185,7 +183,7 @@ class CommonForm extends Form
foreach ($this->rangeFactors as $unit => $factor) {
if ($formData[$unit] !== '' && $formData[$unit] !== $this->defaultFormData[$unit]) {
$this->getRedirectUrl()->setParam(
static::getRelativeRangeParameter(),
TimeRangePickerTools::getRelativeRangeParameter(),
(string) ((int) $formData[$unit] * $factor)
);
return;

View file

@ -5,13 +5,12 @@ namespace Icinga\Module\Graphite\Forms\TimeRangePicker;
use DateInterval;
use DateTime;
use DateTimeZone;
use Icinga\Module\Graphite\Util\TimeRangePickerTools;
use Icinga\Module\Graphite\Web\Form\Decorator\Proxy;
use Icinga\Web\Form;
class CustomForm extends Form
{
use TimeRangePickerTrait;
/**
* @var string
*/
@ -99,13 +98,13 @@ class CustomForm extends Form
$start = $this->formToUrl('start', '00:00');
$end = $this->formToUrl('end', '23:59', 'PT59S');
if ($start > $end) {
$absoluteRangeParameters = static::getAbsoluteRangeParameters();
$absoluteRangeParameters = TimeRangePickerTools::getAbsoluteRangeParameters();
$this->getRedirectUrl()->getParams()
->set($absoluteRangeParameters['start'], $end)
->set($absoluteRangeParameters['end'], $start);
}
$this->getRedirectUrl()->remove(static::getRelativeRangeParameter());
$this->getRedirectUrl()->remove(TimeRangePickerTools::getRelativeRangeParameter());
}
/**
@ -149,7 +148,7 @@ class CustomForm extends Form
protected function urlToForm($part, $defaultTimestamp = null)
{
$params = $this->getRedirectUrl()->getParams();
$absoluteRangeParameters = static::getAbsoluteRangeParameters();
$absoluteRangeParameters = TimeRangePickerTools::getAbsoluteRangeParameters();
$timestamp = $params->get($absoluteRangeParameters[$part], $defaultTimestamp);
if ($timestamp !== null) {
@ -176,7 +175,7 @@ class CustomForm extends Form
*/
protected function getRelativeTimestamp()
{
$seconds = $this->getRelativeSeconds($this->getRedirectUrl()->getParams());
$seconds = TimeRangePickerTools::getRelativeSeconds($this->getRedirectUrl()->getParams());
return is_int($seconds) ? $this->getNow()->getTimestamp() - $seconds : null;
}
@ -194,7 +193,7 @@ class CustomForm extends Form
$date = $this->getValue("{$part}_date");
$time = $this->getValue("{$part}_time");
$params = $this->getRedirectUrl()->getParams();
$absoluteRangeParameters = static::getAbsoluteRangeParameters();
$absoluteRangeParameters = TimeRangePickerTools::getAbsoluteRangeParameters();
if ($date === '' && $time === '') {
$params->remove($absoluteRangeParameters[$part]);

View file

@ -1,13 +1,13 @@
<?php
namespace Icinga\Module\Graphite\Forms\TimeRangePicker;
namespace Icinga\Module\Graphite\Util;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
use Icinga\Web\Url;
use Icinga\Web\UrlParams;
trait TimeRangePickerTrait
final class TimeRangePickerTools
{
/**
* @return string
@ -50,7 +50,7 @@ trait TimeRangePickerTrait
$copy = new UrlParams();
}
foreach (TimeRangePickerTrait::getAllRangeParameters() as $param) {
foreach (self::getAllRangeParameters() as $param) {
$value = $origin->get($param);
if ($value !== null) {
$copy->set($param, $value);
@ -67,9 +67,9 @@ trait TimeRangePickerTrait
*
* @return bool|int|null
*/
protected function getRelativeSeconds(UrlParams $params)
public static function getRelativeSeconds(UrlParams $params)
{
$seconds = $params->get(static::getRelativeRangeParameter());
$seconds = $params->get(self::getRelativeRangeParameter());
if ($seconds === null) {
return null;
}

View file

@ -4,7 +4,6 @@ namespace Icinga\Module\Graphite\Web\Controller;
use Icinga\Module\Graphite\Forms\TimeRangePicker\CommonForm;
use Icinga\Module\Graphite\Forms\TimeRangePicker\CustomForm;
use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRangePicker;
use Icinga\Web\Request;
use Icinga\Web\Url;
use Icinga\Web\View;

View file

@ -6,14 +6,13 @@ use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;
use Icinga\Exception\ConfigurationError;
use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait;
use Icinga\Module\Graphite\Graphing\Chart;
use Icinga\Module\Graphite\Graphing\GraphingTrait;
use Icinga\Module\Graphite\Graphing\Template;
use Icinga\Module\Graphite\Util\InternalProcessTracker as IPT;
use Icinga\Module\Graphite\Util\TimeRangePickerTools;
use Icinga\Module\Graphite\Web\Widget\Graphs\Host as HostGraphs;
use Icinga\Module\Graphite\Web\Widget\Graphs\Service as ServiceGraphs;
use Icinga\Module\Graphite\Web\Widget\InlineGraphImage;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Service;
@ -343,7 +342,7 @@ abstract class Graphs extends AbstractWidget
$view = $this->view();
$url = $this->getGraphsListBaseUrl();
TimeRangePickerTrait::copyAllRangeParameters($url->getParams(), $currentUrl->getParams());
TimeRangePickerTools::copyAllRangeParameters($url->getParams(), $currentUrl->getParams());
$result[] = "<p class='load-more'>{$view->qlink(
sprintf($view->translate('Load all %d graphs'), $total),
@ -418,15 +417,15 @@ abstract class Graphs extends AbstractWidget
protected function getRangeFromTimeRangePicker(Request $request)
{
$params = $request->getUrl()->getParams();
$relative = $params->get(TimeRangePickerTrait::getRelativeRangeParameter());
$relative = $params->get(TimeRangePickerTools::getRelativeRangeParameter());
if ($relative !== null) {
return ["-$relative", null];
}
$absolute = TimeRangePickerTrait::getAbsoluteRangeParameters();
$absolute = TimeRangePickerTools::getAbsoluteRangeParameters();
$start = $params->get($absolute['start']);
return [
$start === null ? -TimeRangePickerTrait::getDefaultRelativeTimeRange() : $start,
$start === null ? -TimeRangePickerTools::getDefaultRelativeTimeRange() : $start,
$params->get($absolute['end'])
];
}