Skip to content

Commit 8057c0b

Browse files
authored
Merge pull request #255 from Icinga/add-lint-and-style-tests
Add php action workflow
2 parents e37aaf0 + 5374366 commit 8057c0b

File tree

11 files changed

+103
-16
lines changed

11 files changed

+103
-16
lines changed

.github/workflows/php.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: PHP Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/*
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
lint:
14+
name: Static analysis for php ${{ matrix.php }} on ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
21+
os: ['ubuntu-latest']
22+
include:
23+
- php: '5.6'
24+
allow_failure: true
25+
- php: '7.0'
26+
allow_failure: true
27+
28+
steps:
29+
- name: Checkout code base
30+
uses: actions/checkout@v2
31+
32+
- name: Setup PHP
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: ${{ matrix.php }}
36+
tools: phpcs
37+
38+
- name: Setup dependencies
39+
run: composer require -n --no-progress overtrue/phplint
40+
41+
- name: PHP Lint
42+
if: success() || matrix.allow_failure
43+
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- .
44+
45+
- name: PHP CodeSniffer
46+
if: success() || matrix.allow_failure
47+
run: phpcs

.phpcs.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<description>Sniff our code a while</description>
4+
5+
<file>./</file>
6+
7+
<exclude-pattern>vendor/*</exclude-pattern>
8+
9+
<arg value="wps"/>
10+
<arg name="report-width" value="auto"/>
11+
<arg name="report-full"/>
12+
<arg name="report-gitblame"/>
13+
<arg name="report-summary"/>
14+
<arg name="encoding" value="UTF-8"/>
15+
<arg name="extensions" value="php"/>
16+
17+
<rule ref="PSR2"/>
18+
19+
<rule ref="Generic.Files.LineLength">
20+
<properties>
21+
<property name="lineLimit" value="120"/>
22+
<property name="absoluteLineLimit" value="0"/>
23+
</properties>
24+
</rule>
25+
</ruleset>

application/clicommands/Icinga2Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function configAction()
179179
*
180180
* @return array[]
181181
*/
182-
protected function cartesianProduct(array & $input)
182+
protected function cartesianProduct(array &$input)
183183
{
184184
$results = [[]];
185185

application/controllers/GraphController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public function serviceAction()
9999
/**
100100
* Do all monitored object type independend actions
101101
*
102-
* @param MonitoredObject $monitoredObject The monitored object to render the graphs of
103-
* @param string $checkCommand The check command of the monitored object we supply an image for
104-
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
105-
* we display graphs for
102+
* @param MonitoredObject $monitoredObject The monitored object to render the graphs of
103+
* @param string $checkCommand The check command of the monitored object we supply an image for
104+
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
105+
* we display graphs for
106106
*/
107107
protected function supplyImage(MonitoredObject $monitoredObject, $checkCommand, $obscuredCheckCommand)
108108
{
@@ -139,6 +139,7 @@ protected function supplyImage(MonitoredObject $monitoredObject, $checkCommand,
139139
->setShowLegend((bool) $this->graphParams['legend'])
140140
->serveImage($this->getResponse());
141141

142+
// not falling through, serveImage exits
142143
default:
143144
throw new HttpBadRequestException('%s', $this->translate(
144145
'Graphite Web yields more than one metric for the given filter.'

application/forms/TimeRangePicker/CustomForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ protected function groupDateTime($part)
130130
$decorators = [];
131131
foreach ($elementDecorators as $key => $decorator) {
132132
if ($key === 'Zend_Form_Decorator_ViewHelper') {
133-
$decorators['Zend_Form_Decorator_FormElements'] = $group->getDecorators()['Zend_Form_Decorator_FormElements'];
133+
$decorators['Zend_Form_Decorator_FormElements'] =
134+
$group->getDecorators()['Zend_Form_Decorator_FormElements'];
134135
} else {
135136
$decorators[$key] = (new Proxy())->setActualDecorator($decorator->setElement($element));
136137
}

library/Graphite/Graphing/GraphiteWebClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function request(Url $url, $method = 'GET', array $headers = [], $body =
9292
*
9393
* @return string
9494
*/
95-
public function escapeMetricPath($metricPath) {
95+
public function escapeMetricPath($metricPath)
96+
{
9697
return preg_replace_callback(
9798
'/[[\]]/',
9899
function (array $matches) {

library/Graphite/Graphing/Template.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ public function __construct()
7070
*
7171
* @return Chart[]
7272
*/
73-
public function getCharts(MetricsDataSource $dataSource, MonitoredObject $monitoredObject, array $filter, array & $excludeMetrics = [])
74-
{
73+
public function getCharts(
74+
MetricsDataSource $dataSource,
75+
MonitoredObject $monitoredObject,
76+
array $filter,
77+
array &$excludeMetrics = []
78+
) {
7579
$metrics = [];
7680
$metricsUsed = 0;
7781
$metricsExcluded = 0;
@@ -167,8 +171,12 @@ public function getCharts(MetricsDataSource $dataSource, MonitoredObject $monito
167171
* @param string[][] $metricsCombinations
168172
* @param string[] $currentCombination
169173
*/
170-
protected function combineMetrics(array & $metrics, array & $possibleCombinations, array & $metricsCombinations, array $currentCombination = [])
171-
{
174+
protected function combineMetrics(
175+
array &$metrics,
176+
array &$possibleCombinations,
177+
array &$metricsCombinations,
178+
array $currentCombination = []
179+
) {
172180
if (empty($currentCombination)) {
173181
foreach ($metrics as $curveName => & $curveMetrics) {
174182
foreach ($curveMetrics as $metric => & $_) {

library/Graphite/Graphing/Templates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function loadIni($path)
144144
$templateName,
145145
$path,
146146
implode(', ', array_map(
147-
function($option) {
147+
function ($option) {
148148
return "\"graph.$option\"";
149149
},
150150
$standalone

library/Graphite/Util/InternalProcessTracker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace Icinga\Module\Graphite\Util;
4+
45
use Icinga\Authentication\Auth;
56
use Icinga\Security\SecurityException;
67

library/Graphite/Web/Widget/Graphs.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ protected function getGraphsList()
241241
IPT::indent();
242242

243243
$charts = $template->getCharts(
244-
static::getMetricsDataSource(), $this->monitoredObject, [], $excludeMetrics
244+
static::getMetricsDataSource(),
245+
$this->monitoredObject,
246+
[],
247+
$excludeMetrics
245248
);
246249

247250
if (! empty($charts)) {
@@ -295,8 +298,8 @@ protected function getGraphsList()
295298

296299
$img = '<img id="graphiteImg-'
297300
. md5((string) $imageUrl->without('cachebuster'))
298-
. "\" src=\"$src\" data-actualimageurl=\"$imageUrl\" class=\"detach graphiteImg\" alt=\"\""
299-
. " width=\"$this->width\" height=\"$this->height\""
301+
. "\" src=\"$src\" data-actualimageurl=\"$imageUrl\" class=\"detach graphiteImg\""
302+
. " alt=\"\" width=\"$this->width\" height=\"$this->height\""
300303
. " style=\"min-width: {$this->width}px; min-height: {$this->height}px;\">";
301304
}
302305

0 commit comments

Comments
 (0)