Skip to content

Commit

Permalink
Merge pull request #255 from Icinga/add-lint-and-style-tests
Browse files Browse the repository at this point in the history
Add php action workflow
  • Loading branch information
nilmerg authored Apr 8, 2021
2 parents e37aaf0 + 5374366 commit 8057c0b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 16 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>Sniff our code a while</description>

<file>./</file>

<exclude-pattern>vendor/*</exclude-pattern>

<arg value="wps"/>
<arg name="report-width" value="auto"/>
<arg name="report-full"/>
<arg name="report-gitblame"/>
<arg name="report-summary"/>
<arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php"/>

<rule ref="PSR2"/>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion application/clicommands/Icinga2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function configAction()
*
* @return array[]
*/
protected function cartesianProduct(array & $input)
protected function cartesianProduct(array &$input)
{
$results = [[]];

Expand Down
9 changes: 5 additions & 4 deletions application/controllers/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.'
Expand Down
3 changes: 2 additions & 1 deletion application/forms/TimeRangePicker/CustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion library/Graphite/Graphing/GraphiteWebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions library/Graphite/Graphing/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => & $_) {
Expand Down
2 changes: 1 addition & 1 deletion library/Graphite/Graphing/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function loadIni($path)
$templateName,
$path,
implode(', ', array_map(
function($option) {
function ($option) {
return "\"graph.$option\"";
},
$standalone
Expand Down
1 change: 1 addition & 0 deletions library/Graphite/Util/InternalProcessTracker.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Icinga\Module\Graphite\Util;

use Icinga\Authentication\Auth;
use Icinga\Security\SecurityException;

Expand Down
9 changes: 6 additions & 3 deletions library/Graphite/Web/Widget/Graphs.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ protected function getGraphsList()
IPT::indent();

$charts = $template->getCharts(
static::getMetricsDataSource(), $this->monitoredObject, [], $excludeMetrics
static::getMetricsDataSource(),
$this->monitoredObject,
[],
$excludeMetrics
);

if (! empty($charts)) {
Expand Down Expand Up @@ -295,8 +298,8 @@ protected function getGraphsList()

$img = '<img id="graphiteImg-'
. md5((string) $imageUrl->without('cachebuster'))
. "\" src=\"$src\" data-actualimageurl=\"$imageUrl\" class=\"detach graphiteImg\" alt=\"\""
. " width=\"$this->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;\">";
}

Expand Down
2 changes: 1 addition & 1 deletion library/Graphite/Web/Widget/Graphs/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8057c0b

Please sign in to comment.