Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code style check into CI pipeline #21

Merged
merged 12 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
unit-config: &unit-config
environment:
COMPOSER_PREFER_LOWEST: 0
steps:
- checkout

- run:
name: Install latest composer
command: |
php -r "copy('https://raw.githubusercontent.com/composer/getcomposer.org/master/web/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

- run:
name: Write COMPOSER_PREFER_LOWEST to file
command: echo "$COMPOSER_PREFER_LOWEST" > ~/COMPOSER_PREFER_LOWEST.txt

# Download and cache dependencies
- restore_cache:
keys:
- v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}-{{ checksum "composer.json" }}
# Fall back to using the latest cache if no exact match is found.
- v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}

- run:
name: Validate composer files
command: composer validate --strict

- run:
name: Install PHP extensions
command: |
printf '\n' | sudo pecl install redis
sudo docker-php-ext-enable redis

- run:
name: Install composer packages
command: |
if [ $COMPOSER_PREFER_LOWEST -eq "1" ]; then
composer update --no-ansi --no-progress --optimize-autoloader --no-interaction --no-plugins --no-scripts --prefer-dist --prefer-stable --prefer-lowest
else
composer update --no-ansi --no-progress --optimize-autoloader --no-interaction --no-plugins --no-scripts --prefer-dist --prefer-stable
fi

- save_cache:
key: v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}-{{ checksum "composer.json" }}
paths:
- ./vendor

- run:
name: Wait for backing services to start
command: dockerize -wait tcp://127.0.0.1:6379 -timeout 30s

- run:
name: Run PHP Code Sniffer
command: ./vendor/bin/phpcs

- run:
name: Run tests
command: ./vendor/bin/phpunit

version: 2.1
jobs:
php73:
<<: *unit-config
docker:
- image: circleci/php:7.3-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 0

php73-lowest:
<<: *unit-config
docker:
- image: circleci/php:7.3-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 1

workflows:
version: 2
units:
jobs:
- php73
- php73-lowest
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text=auto
/.circleci/ export-ignore
/.github/ export-ignore
/examples/ export-ignore
/nginx/ export-ignore
/php-fpm/ export-ignore
/tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
docker-compose.yml export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

17 changes: 14 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "endclothing/prometheus_client_php",
"version": "1.0.1",
"description": "Prometheus instrumentation library for PHP applications.",
"type": "library",
"license": "Apache-2.0",
"authors": [
{
"name": "Daniel Noel-Davies",
Expand All @@ -17,7 +19,8 @@
"symfony/polyfill-apcu": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-redis": "Required if using Redis.",
Expand All @@ -33,5 +36,13 @@
"Test\\Prometheus\\": "tests/"
}
},
"license": "Apache-2.0"
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
},
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion examples/flush_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
} elseif ($adapter === 'in-memory') {
$inMemoryAdapter = new Prometheus\Storage\InMemory();
$inMemoryAdapter->flushMemory();
}
}
2 changes: 1 addition & 1 deletion examples/pushgateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
$counter->incBy(6, ['blue']);

$pushGateway = new PushGateway('192.168.59.100:9091');
$pushGateway->push($registry, 'my_job', ['instance'=>'foo']);
$pushGateway->push($registry, 'my_job', ['instance' => 'foo']);
2 changes: 1 addition & 1 deletion examples/some_gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Prometheus\Storage\Redis;


error_log('c='. $_GET['c']);
error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'];

Expand Down
2 changes: 1 addition & 1 deletion examples/some_histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Prometheus\CollectorRegistry;
use Prometheus\Storage\Redis;

error_log('c='. $_GET['c']);
error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'];

Expand Down
14 changes: 14 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>KASKO Coding standard.</description>

<file>src/</file>
<file>tests/</file>
<file>examples/</file>

<exclude-pattern type="relative">vendor/*</exclude-pattern>

<arg value="nps"/>

<rule ref="PSR12"/>
</ruleset>
23 changes: 13 additions & 10 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory>./tests/Test/Prometheus</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/Prometheus</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="Unit">
<directory>./tests/Test/Prometheus</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/Prometheus</directory>
</whitelist>
</filter>
</phpunit>
3 changes: 2 additions & 1 deletion src/Prometheus/Collector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $
/**
* @return string
*/
public abstract function getType();
abstract public function getType();

/**
* @return string
Expand Down
1 change: 1 addition & 0 deletions src/Prometheus/CollectorRegistry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus;
Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/Counter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/Gauge.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand Down
1 change: 1 addition & 0 deletions src/Prometheus/Histogram.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus;
Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/MetricFamilySamples.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/PushGateway.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand Down
5 changes: 3 additions & 2 deletions src/Prometheus/RenderTextFormat.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand All @@ -13,7 +14,7 @@ class RenderTextFormat
*/
public function render(array $metrics): string
{
usort( $metrics, function (MetricFamilySamples $a, MetricFamilySamples $b) {
usort($metrics, function (MetricFamilySamples $a, MetricFamilySamples $b) {
return strcmp($a->getName(), $b->getName());
});

Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/Sample.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus;

Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Storage/APC.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus\Storage;
Expand Down Expand Up @@ -284,7 +285,6 @@ private function collectHistograms(): array
'labelValues' => $decodedLabelValues,
'value' => $this->fromInteger($histogramBuckets[$labelValues]['sum']),
];

}
$histograms[] = new MetricFamilySamples($data);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Prometheus/Storage/Adapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Prometheus\Storage;

Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Storage/InMemory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus\Storage;
Expand Down Expand Up @@ -100,7 +101,6 @@ private function collectHistograms(): array
'labelValues' => $decodedLabelValues,
'value' => $histogramBuckets[$labelValues]['sum'],
];

}
$histograms[] = new MetricFamilySamples($data);
}
Expand Down
1 change: 1 addition & 0 deletions src/Prometheus/Storage/Redis.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Prometheus\Storage;
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/BlackBoxPushGatewayTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Test;

use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;

use Prometheus\CollectorRegistry;
use Prometheus\PushGateway;
use Prometheus\Storage\APC;
Expand Down
1 change: 1 addition & 0 deletions tests/Test/BlackBoxTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Test;

use GuzzleHttp\Client;
Expand Down
1 change: 0 additions & 1 deletion tests/Test/Prometheus/APC/HistogramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ public function configureAdapter()
$this->adapter->flushAPC();
}
}

4 changes: 1 addition & 3 deletions tests/Test/Prometheus/AbstractCollectorRegistryTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Test\Prometheus;


use PHPUnit\Framework\TestCase;
use Prometheus\CollectorRegistry;
use Prometheus\Histogram;
Expand Down Expand Up @@ -317,5 +315,5 @@ public function itShouldNotRegisterAHistogramTwice()
}


public abstract function configureAdapter();
abstract public function configureAdapter();
}
Loading