diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 00000000..e26a4294 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,47 @@ +name: PHP Tests + +on: + push: + branches: + - master + - release/* + pull_request: + branches: + - master + +jobs: + lint: + name: Static analysis for php ${{ matrix.php }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + os: ['ubuntu-latest'] + include: + - php: '5.6' + allow_failure: true + - php: '7.0' + allow_failure: true + + steps: + - name: Checkout code base + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: phpcs + + - name: Setup dependencies + run: composer require -n --no-progress overtrue/phplint + + - name: PHP Lint + if: success() || matrix.allow_failure + run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- . + + - name: PHP CodeSniffer + if: success() || matrix.allow_failure + run: phpcs diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 00000000..d1d0ed74 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,25 @@ + + + Sniff our code a while + + ./ + + vendor/* + + + + + + + + + + + + + + + + + + diff --git a/application/clicommands/Icinga2Command.php b/application/clicommands/Icinga2Command.php index eb2ba5ce..3ae13358 100644 --- a/application/clicommands/Icinga2Command.php +++ b/application/clicommands/Icinga2Command.php @@ -179,7 +179,7 @@ public function configAction() * * @return array[] */ - protected function cartesianProduct(array & $input) + protected function cartesianProduct(array &$input) { $results = [[]]; diff --git a/application/controllers/GraphController.php b/application/controllers/GraphController.php index 55eb4280..5f8a739b 100644 --- a/application/controllers/GraphController.php +++ b/application/controllers/GraphController.php @@ -99,10 +99,10 @@ public function serviceAction() /** * Do all monitored object type independend actions * - * @param MonitoredObject $monitoredObject The monitored object to render the graphs of - * @param string $checkCommand The check command of the monitored object we supply an image for - * @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object - * we display graphs for + * @param MonitoredObject $monitoredObject The monitored object to render the graphs of + * @param string $checkCommand The check command of the monitored object we supply an image for + * @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object + * we display graphs for */ protected function supplyImage(MonitoredObject $monitoredObject, $checkCommand, $obscuredCheckCommand) { @@ -139,6 +139,7 @@ protected function supplyImage(MonitoredObject $monitoredObject, $checkCommand, ->setShowLegend((bool) $this->graphParams['legend']) ->serveImage($this->getResponse()); + // not falling through, serveImage exits default: throw new HttpBadRequestException('%s', $this->translate( 'Graphite Web yields more than one metric for the given filter.' diff --git a/application/forms/TimeRangePicker/CustomForm.php b/application/forms/TimeRangePicker/CustomForm.php index a190b9d0..219e4344 100644 --- a/application/forms/TimeRangePicker/CustomForm.php +++ b/application/forms/TimeRangePicker/CustomForm.php @@ -130,7 +130,8 @@ protected function groupDateTime($part) $decorators = []; foreach ($elementDecorators as $key => $decorator) { if ($key === 'Zend_Form_Decorator_ViewHelper') { - $decorators['Zend_Form_Decorator_FormElements'] = $group->getDecorators()['Zend_Form_Decorator_FormElements']; + $decorators['Zend_Form_Decorator_FormElements'] = + $group->getDecorators()['Zend_Form_Decorator_FormElements']; } else { $decorators[$key] = (new Proxy())->setActualDecorator($decorator->setElement($element)); } diff --git a/library/Graphite/Graphing/GraphiteWebClient.php b/library/Graphite/Graphing/GraphiteWebClient.php index baa8fe3c..8f78aeff 100644 --- a/library/Graphite/Graphing/GraphiteWebClient.php +++ b/library/Graphite/Graphing/GraphiteWebClient.php @@ -92,7 +92,8 @@ public function request(Url $url, $method = 'GET', array $headers = [], $body = * * @return string */ - public function escapeMetricPath($metricPath) { + public function escapeMetricPath($metricPath) + { return preg_replace_callback( '/[[\]]/', function (array $matches) { diff --git a/library/Graphite/Graphing/Template.php b/library/Graphite/Graphing/Template.php index 6e337525..25302aa0 100644 --- a/library/Graphite/Graphing/Template.php +++ b/library/Graphite/Graphing/Template.php @@ -70,8 +70,12 @@ public function __construct() * * @return Chart[] */ - public function getCharts(MetricsDataSource $dataSource, MonitoredObject $monitoredObject, array $filter, array & $excludeMetrics = []) - { + public function getCharts( + MetricsDataSource $dataSource, + MonitoredObject $monitoredObject, + array $filter, + array &$excludeMetrics = [] + ) { $metrics = []; $metricsUsed = 0; $metricsExcluded = 0; @@ -167,8 +171,12 @@ public function getCharts(MetricsDataSource $dataSource, MonitoredObject $monito * @param string[][] $metricsCombinations * @param string[] $currentCombination */ - protected function combineMetrics(array & $metrics, array & $possibleCombinations, array & $metricsCombinations, array $currentCombination = []) - { + protected function combineMetrics( + array &$metrics, + array &$possibleCombinations, + array &$metricsCombinations, + array $currentCombination = [] + ) { if (empty($currentCombination)) { foreach ($metrics as $curveName => & $curveMetrics) { foreach ($curveMetrics as $metric => & $_) { diff --git a/library/Graphite/Graphing/Templates.php b/library/Graphite/Graphing/Templates.php index 05736f39..12e189b9 100644 --- a/library/Graphite/Graphing/Templates.php +++ b/library/Graphite/Graphing/Templates.php @@ -144,7 +144,7 @@ public function loadIni($path) $templateName, $path, implode(', ', array_map( - function($option) { + function ($option) { return "\"graph.$option\""; }, $standalone diff --git a/library/Graphite/Util/InternalProcessTracker.php b/library/Graphite/Util/InternalProcessTracker.php index 8efac05d..f7f2df61 100644 --- a/library/Graphite/Util/InternalProcessTracker.php +++ b/library/Graphite/Util/InternalProcessTracker.php @@ -1,6 +1,7 @@ getCharts( - static::getMetricsDataSource(), $this->monitoredObject, [], $excludeMetrics + static::getMetricsDataSource(), + $this->monitoredObject, + [], + $excludeMetrics ); if (! empty($charts)) { @@ -295,8 +298,8 @@ protected function getGraphsList() $img = '\"\""width\" height=\"$this->height\"" + . "\" src=\"$src\" data-actualimageurl=\"$imageUrl\" class=\"detach graphiteImg\"" + . " alt=\"\" width=\"$this->width\" height=\"$this->height\"" . " style=\"min-width: {$this->width}px; min-height: {$this->height}px;\">"; } diff --git a/library/Graphite/Web/Widget/Graphs/Service.php b/library/Graphite/Web/Widget/Graphs/Service.php index be3b68b3..c464c0aa 100644 --- a/library/Graphite/Web/Widget/Graphs/Service.php +++ b/library/Graphite/Web/Widget/Graphs/Service.php @@ -35,7 +35,7 @@ protected function filterImageUrl(Url $url) { return $url ->setParam('host.name', $this->monitoredObject->getHost()->getName()) - ->setParam('service.name', $this->monitoredObject->getName()); + ->setParam('service.name', $this->monitoredObject->getName()); } protected function getMonitoredObjectIdentifier()