From 9dd85a0b19330e70e8c347036606e87a492e88c1 Mon Sep 17 00:00:00 2001 From: Ken Guest Date: Mon, 22 Oct 2018 23:40:18 +0100 Subject: [PATCH] Fix some coding standards (PSR2, short array syntax, @throws tags) --- examples/flush_adapter.php | 4 +- examples/metrics.php | 2 +- examples/pushgateway.php | 4 +- examples/some_counter.php | 2 +- examples/some_gauge.php | 3 +- examples/some_histogram.php | 2 +- src/Prometheus/Collector.php | 5 +- src/Prometheus/CollectorRegistry.php | 19 +- src/Prometheus/Counter.php | 9 +- .../Exception/MetricNotFoundException.php | 1 - .../MetricsRegistrationException.php | 1 - src/Prometheus/Exception/StorageException.php | 1 - src/Prometheus/Gauge.php | 19 +- src/Prometheus/Histogram.php | 14 +- src/Prometheus/MetricFamilySamples.php | 2 +- src/Prometheus/PushGateway.php | 10 +- src/Prometheus/RenderTextFormat.php | 8 +- src/Prometheus/Sample.php | 1 - src/Prometheus/Storage/APC.php | 76 ++-- src/Prometheus/Storage/InMemory.php | 9 +- src/Prometheus/Storage/Redis.php | 101 ++--- tests/Test/BlackBoxPushGatewayTest.php | 4 +- tests/Test/Prometheus/APC/CounterTest.php | 2 +- tests/Test/Prometheus/APC/GaugeTest.php | 2 +- tests/Test/Prometheus/APC/HistogramTest.php | 2 +- .../AbstractCollectorRegistryTest.php | 42 +- tests/Test/Prometheus/AbstractCounterTest.php | 90 ++--- tests/Test/Prometheus/AbstractGaugeTest.php | 220 +++++------ .../Test/Prometheus/AbstractHistogramTest.php | 372 +++++++++--------- .../Test/Prometheus/InMemory/CounterTest.php | 2 +- tests/Test/Prometheus/InMemory/GaugeTest.php | 2 +- .../Prometheus/InMemory/HistogramTest.php | 2 +- .../Redis/CollectorRegistryTest.php | 2 +- tests/Test/Prometheus/Redis/CounterTest.php | 4 +- tests/Test/Prometheus/Redis/GaugeTest.php | 4 +- tests/Test/Prometheus/Redis/HistogramTest.php | 4 +- tests/Test/Prometheus/Storage/RedisTest.php | 2 +- 37 files changed, 520 insertions(+), 529 deletions(-) diff --git a/examples/flush_adapter.php b/examples/flush_adapter.php index 0c3862d..3714a75 100644 --- a/examples/flush_adapter.php +++ b/examples/flush_adapter.php @@ -6,7 +6,7 @@ if ($adapter === 'redis') { define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'); - $redisAdapter = new Prometheus\Storage\Redis(array('host' => REDIS_HOST)); + $redisAdapter = new Prometheus\Storage\Redis(['host' => REDIS_HOST]); $redisAdapter->flushRedis(); } elseif ($adapter === 'apc') { $apcAdapter = new Prometheus\Storage\APC(); @@ -14,4 +14,4 @@ } elseif ($adapter === 'in-memory') { $inMemoryAdapter = new Prometheus\Storage\InMemory(); $inMemoryAdapter->flushMemory(); -} \ No newline at end of file +} diff --git a/examples/metrics.php b/examples/metrics.php index fa89247..74a111b 100644 --- a/examples/metrics.php +++ b/examples/metrics.php @@ -9,7 +9,7 @@ $adapter = $_GET['adapter']; if ($adapter === 'redis') { - Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); + Redis::setDefaultOptions(['host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1']); $adapter = new Prometheus\Storage\Redis(); } elseif ($adapter === 'apc') { $adapter = new Prometheus\Storage\APC(); diff --git a/examples/pushgateway.php b/examples/pushgateway.php index 984035d..702e72a 100644 --- a/examples/pushgateway.php +++ b/examples/pushgateway.php @@ -7,7 +7,7 @@ $adapter = $_GET['adapter']; if ($adapter === 'redis') { - Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); + Redis::setDefaultOptions(['host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1']); $adapter = new Prometheus\Storage\Redis(); } elseif ($adapter === 'apc') { $adapter = new Prometheus\Storage\APC(); @@ -21,4 +21,4 @@ $counter->incBy(6, ['blue']); $pushGateway = new \Prometheus\PushGateway('192.168.59.100:9091'); -$pushGateway->push($registry, 'my_job', array('instance'=>'foo')); +$pushGateway->push($registry, 'my_job', ['instance'=>'foo']); diff --git a/examples/some_counter.php b/examples/some_counter.php index 823bfac..71e7290 100644 --- a/examples/some_counter.php +++ b/examples/some_counter.php @@ -8,7 +8,7 @@ $adapter = $_GET['adapter']; if ($adapter === 'redis') { - Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); + Redis::setDefaultOptions(['host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1']); $adapter = new Prometheus\Storage\Redis(); } elseif ($adapter === 'apc') { $adapter = new Prometheus\Storage\APC(); diff --git a/examples/some_gauge.php b/examples/some_gauge.php index b3e2382..e8bceff 100644 --- a/examples/some_gauge.php +++ b/examples/some_gauge.php @@ -5,13 +5,12 @@ use Prometheus\CollectorRegistry; use Prometheus\Storage\Redis; - error_log('c='. $_GET['c']); $adapter = $_GET['adapter']; if ($adapter === 'redis') { - Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); + Redis::setDefaultOptions(['host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1']); $adapter = new Prometheus\Storage\Redis(); } elseif ($adapter === 'apc') { $adapter = new Prometheus\Storage\APC(); diff --git a/examples/some_histogram.php b/examples/some_histogram.php index 6b34809..babbced 100644 --- a/examples/some_histogram.php +++ b/examples/some_histogram.php @@ -10,7 +10,7 @@ $adapter = $_GET['adapter']; if ($adapter === 'redis') { - Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); + Redis::setDefaultOptions(['host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1']); $adapter = new Prometheus\Storage\Redis(); } elseif ($adapter === 'apc') { $adapter = new Prometheus\Storage\APC(); diff --git a/src/Prometheus/Collector.php b/src/Prometheus/Collector.php index edc5e80..95d9f17 100644 --- a/src/Prometheus/Collector.php +++ b/src/Prometheus/Collector.php @@ -2,7 +2,6 @@ namespace Prometheus; - use Prometheus\Storage\Adapter; abstract class Collector @@ -21,7 +20,7 @@ abstract class Collector * @param string $help * @param array $labels */ - public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $labels = array()) + public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $labels = []) { $this->storageAdapter = $storageAdapter; $metricName = ($namespace ? $namespace . '_' : '') . $name; @@ -41,7 +40,7 @@ public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $ /** * @return string */ - public abstract function getType(); + abstract public function getType(); public function getName() { diff --git a/src/Prometheus/CollectorRegistry.php b/src/Prometheus/CollectorRegistry.php index 9ff18e3..c915499 100644 --- a/src/Prometheus/CollectorRegistry.php +++ b/src/Prometheus/CollectorRegistry.php @@ -3,7 +3,6 @@ namespace Prometheus; - use Prometheus\Exception\MetricNotFoundException; use Prometheus\Exception\MetricsRegistrationException; use Prometheus\Storage\Adapter; @@ -23,15 +22,15 @@ class CollectorRegistry /** * @var Gauge[] */ - private $gauges = array(); + private $gauges = []; /** * @var Counter[] */ - private $counters = array(); + private $counters = []; /** * @var Histogram[] */ - private $histograms = array(); + private $histograms = []; public function __construct(Adapter $redisAdapter) { @@ -65,7 +64,7 @@ public function getMetricFamilySamples() * @return Gauge * @throws MetricsRegistrationException */ - public function registerGauge($namespace, $name, $help, $labels = array()) + public function registerGauge($namespace, $name, $help, $labels = []) { $metricIdentifier = self::metricIdentifier($namespace, $name); if (isset($this->gauges[$metricIdentifier])) { @@ -103,7 +102,7 @@ public function getGauge($namespace, $name) * @param array $labels e.g. ['controller', 'action'] * @return Gauge */ - public function getOrRegisterGauge($namespace, $name, $help, $labels = array()) + public function getOrRegisterGauge($namespace, $name, $help, $labels = []) { try { $gauge = $this->getGauge($namespace, $name); @@ -121,7 +120,7 @@ public function getOrRegisterGauge($namespace, $name, $help, $labels = array()) * @return Counter * @throws MetricsRegistrationException */ - public function registerCounter($namespace, $name, $help, $labels = array()) + public function registerCounter($namespace, $name, $help, $labels = []) { $metricIdentifier = self::metricIdentifier($namespace, $name); if (isset($this->counters[$metricIdentifier])) { @@ -159,7 +158,7 @@ public function getCounter($namespace, $name) * @param array $labels e.g. ['controller', 'action'] * @return Counter */ - public function getOrRegisterCounter($namespace, $name, $help, $labels = array()) + public function getOrRegisterCounter($namespace, $name, $help, $labels = []) { try { $counter = $this->getCounter($namespace, $name); @@ -178,7 +177,7 @@ public function getOrRegisterCounter($namespace, $name, $help, $labels = array() * @return Histogram * @throws MetricsRegistrationException */ - public function registerHistogram($namespace, $name, $help, $labels = array(), $buckets = null) + public function registerHistogram($namespace, $name, $help, $labels = [], $buckets = null) { $metricIdentifier = self::metricIdentifier($namespace, $name); if (isset($this->histograms[$metricIdentifier])) { @@ -218,7 +217,7 @@ public function getHistogram($namespace, $name) * @param array $buckets e.g. [100, 200, 300] * @return Histogram */ - public function getOrRegisterHistogram($namespace, $name, $help, $labels = array(), $buckets = null) + public function getOrRegisterHistogram($namespace, $name, $help, $labels = [], $buckets = null) { try { $histogram = $this->getHistogram($namespace, $name); diff --git a/src/Prometheus/Counter.php b/src/Prometheus/Counter.php index 3624c9c..45e54e7 100644 --- a/src/Prometheus/Counter.php +++ b/src/Prometheus/Counter.php @@ -2,7 +2,6 @@ namespace Prometheus; - use Prometheus\Storage\Adapter; class Counter extends Collector @@ -20,7 +19,7 @@ public function getType() /** * @param array $labels e.g. ['status', 'opcode'] */ - public function inc(array $labels = array()) + public function inc(array $labels = []) { $this->incBy(1, $labels); } @@ -29,12 +28,12 @@ public function inc(array $labels = array()) * @param int $count e.g. 2 * @param array $labels e.g. ['status', 'opcode'] */ - public function incBy($count, array $labels = array()) + public function incBy($count, array $labels = []) { $this->assertLabelsAreDefinedCorrectly($labels); $this->storageAdapter->updateCounter( - array( + [ 'name' => $this->getName(), 'help' => $this->getHelp(), 'type' => $this->getType(), @@ -42,7 +41,7 @@ public function incBy($count, array $labels = array()) 'labelValues' => $labels, 'value' => $count, 'command' => Adapter::COMMAND_INCREMENT_INTEGER - ) + ] ); } } diff --git a/src/Prometheus/Exception/MetricNotFoundException.php b/src/Prometheus/Exception/MetricNotFoundException.php index ff67175..559671c 100644 --- a/src/Prometheus/Exception/MetricNotFoundException.php +++ b/src/Prometheus/Exception/MetricNotFoundException.php @@ -3,7 +3,6 @@ namespace Prometheus\Exception; - /** * Exception thrown if a metric can't be found in the CollectorRegistry. */ diff --git a/src/Prometheus/Exception/MetricsRegistrationException.php b/src/Prometheus/Exception/MetricsRegistrationException.php index 17f70be..0dbaa93 100644 --- a/src/Prometheus/Exception/MetricsRegistrationException.php +++ b/src/Prometheus/Exception/MetricsRegistrationException.php @@ -3,7 +3,6 @@ namespace Prometheus\Exception; - /** * Exception thrown if an error occurs during metrics registration. */ diff --git a/src/Prometheus/Exception/StorageException.php b/src/Prometheus/Exception/StorageException.php index 782e6e3..5f3d57a 100644 --- a/src/Prometheus/Exception/StorageException.php +++ b/src/Prometheus/Exception/StorageException.php @@ -3,7 +3,6 @@ namespace Prometheus\Exception; - /** * Exception thrown if an error occurs during metrics storage. */ diff --git a/src/Prometheus/Gauge.php b/src/Prometheus/Gauge.php index 235e9ae..e12b67f 100644 --- a/src/Prometheus/Gauge.php +++ b/src/Prometheus/Gauge.php @@ -3,7 +3,6 @@ namespace Prometheus; - use Prometheus\Storage\Adapter; class Gauge extends Collector @@ -14,12 +13,12 @@ class Gauge extends Collector * @param double $value e.g. 123 * @param array $labels e.g. ['status', 'opcode'] */ - public function set($value, $labels = array()) + public function set($value, $labels = []) { $this->assertLabelsAreDefinedCorrectly($labels); $this->storageAdapter->updateGauge( - array( + [ 'name' => $this->getName(), 'help' => $this->getHelp(), 'type' => $this->getType(), @@ -27,7 +26,7 @@ public function set($value, $labels = array()) 'labelValues' => $labels, 'value' => $value, 'command' => Adapter::COMMAND_SET - ) + ] ); } @@ -39,17 +38,17 @@ public function getType() return self::TYPE; } - public function inc($labels = array()) + public function inc($labels = []) { $this->incBy(1, $labels); } - public function incBy($value, $labels = array()) + public function incBy($value, $labels = []) { $this->assertLabelsAreDefinedCorrectly($labels); $this->storageAdapter->updateGauge( - array( + [ 'name' => $this->getName(), 'help' => $this->getHelp(), 'type' => $this->getType(), @@ -57,16 +56,16 @@ public function incBy($value, $labels = array()) 'labelValues' => $labels, 'value' => $value, 'command' => Adapter::COMMAND_INCREMENT_FLOAT - ) + ] ); } - public function dec($labels = array()) + public function dec($labels = []) { $this->decBy(1, $labels); } - public function decBy($value, $labels = array()) + public function decBy($value, $labels = []) { $this->incBy(-$value, $labels); } diff --git a/src/Prometheus/Histogram.php b/src/Prometheus/Histogram.php index 9dbfda4..0676e91 100644 --- a/src/Prometheus/Histogram.php +++ b/src/Prometheus/Histogram.php @@ -2,7 +2,6 @@ namespace Prometheus; - use Prometheus\Storage\Adapter; class Histogram extends Collector @@ -18,8 +17,9 @@ class Histogram extends Collector * @param string $help * @param array $labels * @param array $buckets + * @throws InvalidArgumentException */ - public function __construct(Adapter $adapter, $namespace, $name, $help, $labels = array(), $buckets = null) + public function __construct(Adapter $adapter, $namespace, $name, $help, $labels = [], $buckets = null) { parent::__construct($adapter, $namespace, $name, $help, $labels); @@ -53,21 +53,21 @@ public function __construct(Adapter $adapter, $namespace, $name, $help, $labels */ public static function getDefaultBuckets() { - return array( + return [ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0 - ); + ]; } /** * @param double $value e.g. 123 * @param array $labels e.g. ['status', 'opcode'] */ - public function observe($value, $labels = array()) + public function observe($value, $labels = []) { $this->assertLabelsAreDefinedCorrectly($labels); $this->storageAdapter->updateHistogram( - array( + [ 'value' => $value, 'name' => $this->getName(), 'help' => $this->getHelp(), @@ -75,7 +75,7 @@ public function observe($value, $labels = array()) 'labelNames' => $this->getLabelNames(), 'labelValues' => $labels, 'buckets' => $this->buckets, - ) + ] ); } diff --git a/src/Prometheus/MetricFamilySamples.php b/src/Prometheus/MetricFamilySamples.php index e88e9aa..37a5334 100644 --- a/src/Prometheus/MetricFamilySamples.php +++ b/src/Prometheus/MetricFamilySamples.php @@ -8,7 +8,7 @@ class MetricFamilySamples private $type; private $help; private $labelNames; - private $samples = array(); + private $samples = []; /** * @param array $data diff --git a/src/Prometheus/PushGateway.php b/src/Prometheus/PushGateway.php index a4a3fd2..bce4b73 100644 --- a/src/Prometheus/PushGateway.php +++ b/src/Prometheus/PushGateway.php @@ -3,7 +3,6 @@ namespace Prometheus; - use GuzzleHttp\Client; class PushGateway @@ -69,13 +68,13 @@ private function doRequest(CollectorRegistry $collectorRegistry, $job, $grouping } } $client = new Client(); - $requestOptions = array( - 'headers' => array( + $requestOptions = [ + 'headers' => [ 'Content-Type' => RenderTextFormat::MIME_TYPE - ), + ], 'connect_timeout' => 10, 'timeout' => 20, - ); + ]; if ($method != 'delete') { $renderer = new RenderTextFormat(); $requestOptions['body'] = $renderer->render($collectorRegistry->getMetricFamilySamples()); @@ -87,5 +86,4 @@ private function doRequest(CollectorRegistry $collectorRegistry, $job, $grouping throw new \RuntimeException($msg); } } - } diff --git a/src/Prometheus/RenderTextFormat.php b/src/Prometheus/RenderTextFormat.php index 95fe2b5..074d832 100644 --- a/src/Prometheus/RenderTextFormat.php +++ b/src/Prometheus/RenderTextFormat.php @@ -2,7 +2,6 @@ namespace Prometheus; - class RenderTextFormat { const MIME_TYPE = 'text/plain; version=0.0.4'; @@ -13,12 +12,11 @@ class RenderTextFormat */ public function render(array $metrics) { - usort($metrics, function(MetricFamilySamples $a, MetricFamilySamples $b) - { + usort($metrics, function (MetricFamilySamples $a, MetricFamilySamples $b) { return strcmp($a->getName(), $b->getName()); }); - $lines = array(); + $lines = []; foreach ($metrics as $metric) { $lines[] = "# HELP " . $metric->getName() . " {$metric->getHelp()}"; @@ -32,7 +30,7 @@ public function render(array $metrics) private function renderSample(MetricFamilySamples $metric, Sample $sample) { - $escapedLabels = array(); + $escapedLabels = []; $labelNames = $metric->getLabelNames(); if ($metric->hasLabelNames() || $sample->hasLabelNames()) { diff --git a/src/Prometheus/Sample.php b/src/Prometheus/Sample.php index 9d9d1b3..3f19228 100644 --- a/src/Prometheus/Sample.php +++ b/src/Prometheus/Sample.php @@ -2,7 +2,6 @@ namespace Prometheus; - class Sample { private $name; diff --git a/src/Prometheus/Storage/APC.php b/src/Prometheus/Storage/APC.php index b608e49..43f75a6 100644 --- a/src/Prometheus/Storage/APC.php +++ b/src/Prometheus/Storage/APC.php @@ -3,7 +3,6 @@ namespace Prometheus\Storage; - use Prometheus\MetricFamilySamples; use RuntimeException; @@ -86,7 +85,7 @@ public function updateCounter(array $data) public function flushAPC() { - apcu_clear_cache(); + apcu_clear_cache(); } /** @@ -95,7 +94,7 @@ public function flushAPC() */ private function metaKey(array $data) { - return implode(':', array(self::PROMETHEUS_PREFIX, $data['type'], $data['name'], 'meta')); + return implode(':', [self::PROMETHEUS_PREFIX, $data['type'], $data['name'], 'meta']); } /** @@ -104,13 +103,13 @@ private function metaKey(array $data) */ private function valueKey(array $data) { - return implode(':', array( + return implode(':', [ self::PROMETHEUS_PREFIX, $data['type'], $data['name'], $this->encodeLabelValues($data['labelValues']), 'value' - )); + ]); } /** @@ -119,14 +118,14 @@ private function valueKey(array $data) */ private function histogramBucketValueKey(array $data, $bucket) { - return implode(':', array( + return implode(':', [ self::PROMETHEUS_PREFIX, $data['type'], $data['name'], $this->encodeLabelValues($data['labelValues']), $bucket, 'value' - )); + ]); } /** @@ -147,24 +146,24 @@ private function metaData(array $data) */ private function collectCounters() { - $counters = array(); + $counters = []; foreach (new \APCUIterator('/^prom:counter:.*:meta/') as $counter) { $metaData = json_decode($counter['value'], true); - $data = array( + $data = [ 'name' => $metaData['name'], 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], - ); + ]; foreach (new \APCUIterator('/^prom:counter:' . $metaData['name'] . ':.*:value/') as $value) { $parts = explode(':', $value['key']); $labelValues = $parts[3]; - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'], - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $this->decodeLabelValues($labelValues), 'value' => $value['value'] - ); + ]; } $this->sortSamples($data['samples']); $counters[] = new MetricFamilySamples($data); @@ -177,24 +176,24 @@ private function collectCounters() */ private function collectGauges() { - $gauges = array(); + $gauges = []; foreach (new \APCUIterator('/^prom:gauge:.*:meta/') as $gauge) { $metaData = json_decode($gauge['value'], true); - $data = array( + $data = [ 'name' => $metaData['name'], 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], - ); + ]; foreach (new \APCUIterator('/^prom:gauge:' . $metaData['name'] . ':.*:value/') as $value) { $parts = explode(':', $value['key']); $labelValues = $parts[3]; - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'], - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $this->decodeLabelValues($labelValues), 'value' => $this->fromInteger($value['value']) - ); + ]; } $this->sortSamples($data['samples']); @@ -208,21 +207,21 @@ private function collectGauges() */ private function collectHistograms() { - $histograms = array(); + $histograms = []; foreach (new \APCUIterator('/^prom:histogram:.*:meta/') as $histogram) { $metaData = json_decode($histogram['value'], true); - $data = array( + $data = [ 'name' => $metaData['name'], 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], 'buckets' => $metaData['buckets'] - ); + ]; // Add the Inf bucket so we can compute it later on $data['buckets'][] = '+Inf'; - $histogramBuckets = array(); + $histogramBuckets = []; foreach (new \APCUIterator('/^prom:histogram:' . $metaData['name'] . ':.*:value/') as $value) { $parts = explode(':', $value['key']); $labelValues = $parts[3]; @@ -240,39 +239,38 @@ private function collectHistograms() foreach ($data['buckets'] as $bucket) { $bucket = (string) $bucket; if (!isset($histogramBuckets[$labelValues][$bucket])) { - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'] . '_bucket', - 'labelNames' => array('le'), - 'labelValues' => array_merge($decodedLabelValues, array($bucket)), + 'labelNames' => ['le'], + 'labelValues' => array_merge($decodedLabelValues, [$bucket]), 'value' => $acc - ); + ]; } else { $acc += $histogramBuckets[$labelValues][$bucket]; - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'] . '_' . 'bucket', - 'labelNames' => array('le'), - 'labelValues' => array_merge($decodedLabelValues, array($bucket)), + 'labelNames' => ['le'], + 'labelValues' => array_merge($decodedLabelValues, [$bucket]), 'value' => $acc - ); + ]; } } // Add the count - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'] . '_count', - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $decodedLabelValues, 'value' => $acc - ); + ]; // Add the sum - $data['samples'][] = array( + $data['samples'][] = [ 'name' => $metaData['name'] . '_sum', - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $decodedLabelValues, 'value' => $this->fromInteger($histogramBuckets[$labelValues]['sum']) - ); - + ]; } $histograms[] = new MetricFamilySamples($data); } @@ -299,7 +297,7 @@ private function fromInteger($val) private function sortSamples(array &$samples) { - usort($samples, function($a, $b){ + usort($samples, function ($a, $b) { return strcmp(implode("", $a['labelValues']), implode("", $b['labelValues'])); }); } diff --git a/src/Prometheus/Storage/InMemory.php b/src/Prometheus/Storage/InMemory.php index 313dbf4..e8555ec 100644 --- a/src/Prometheus/Storage/InMemory.php +++ b/src/Prometheus/Storage/InMemory.php @@ -1,8 +1,6 @@ $decodedLabelValues, 'value' => $histogramBuckets[$labelValues]['sum'] ]; - } $histograms[] = new MetricFamilySamples($data); } @@ -238,8 +235,10 @@ private function metaKey(array $data) */ private function valueKey(array $data) { - return implode(':', - [$data['type'], $data['name'], $this->encodeLabelValues($data['labelValues']), 'value']); + return implode( + ':', + [$data['type'], $data['name'], $this->encodeLabelValues($data['labelValues']), 'value'] + ); } /** diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index f38391b..89cc938 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -2,7 +2,6 @@ namespace Prometheus\Storage; - use Prometheus\Counter; use Prometheus\Exception\StorageException; use Prometheus\Gauge; @@ -13,13 +12,13 @@ class Redis implements Adapter { const PROMETHEUS_METRIC_KEYS_SUFFIX = '_METRIC_KEYS'; - private static $defaultOptions = array(); + private static $defaultOptions = []; private static $prefix = 'PROMETHEUS_'; private $options; private $redis; - public function __construct(array $options = array()) + public function __construct(array $options = []) { // with php 5.3 we cannot initialize the options directly on the field definition // so we initialize them here for now @@ -116,7 +115,8 @@ public function updateHistogram(array $data) $metaData = $data; unset($metaData['value']); unset($metaData['labelValues']); - $this->redis->eval(<<redis->eval( + <<toMetricKey($data), - json_encode(array('b' => 'sum', 'labelValues' => $data['labelValues'])), - json_encode(array('b' => $bucketToIncrease, 'labelValues' => $data['labelValues'])), + json_encode(['b' => 'sum', 'labelValues' => $data['labelValues']]), + json_encode(['b' => $bucketToIncrease, 'labelValues' => $data['labelValues']]), self::$prefix . Histogram::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, $data['value'], json_encode($metaData), - ), + ], 4 ); } @@ -144,7 +144,8 @@ public function updateGauge(array $data) unset($metaData['value']); unset($metaData['labelValues']); unset($metaData['command']); - $this->redis->eval(<<redis->eval( + <<toMetricKey($data), $this->getRedisCommand($data['command']), self::$prefix . Gauge::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, json_encode($data['labelValues']), $data['value'], json_encode($metaData), - ), + ], 4 ); } @@ -179,7 +180,8 @@ public function updateCounter(array $data) unset($metaData['value']); unset($metaData['labelValues']); unset($metaData['command']); - $result = $this->redis->eval(<<redis->eval( + <<toMetricKey($data), $this->getRedisCommand($data['command']), self::$prefix . Counter::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, json_encode($data['labelValues']), $data['value'], json_encode($metaData), - ), + ], 4 ); return $result; @@ -205,17 +207,17 @@ private function collectHistograms() { $keys = $this->redis->sMembers(self::$prefix . Histogram::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX); sort($keys); - $histograms = array(); + $histograms = []; foreach ($keys as $key) { $raw = $this->redis->hGetAll($key); $histogram = json_decode($raw['__meta'], true); unset($raw['__meta']); - $histogram['samples'] = array(); + $histogram['samples'] = []; // Add the Inf bucket so we can compute it later on $histogram['buckets'][] = '+Inf'; - $allLabelValues = array(); + $allLabelValues = []; foreach (array_keys($raw) as $k) { $d = json_decode($k, true); if ($d['b'] == 'sum') { @@ -235,40 +237,40 @@ private function collectHistograms() // the previous one. $acc = 0; foreach ($histogram['buckets'] as $bucket) { - $bucketKey = json_encode(array('b' => $bucket, 'labelValues' => $labelValues)); + $bucketKey = json_encode(['b' => $bucket, 'labelValues' => $labelValues]); if (!isset($raw[$bucketKey])) { - $histogram['samples'][] = array( + $histogram['samples'][] = [ 'name' => $histogram['name'] . '_bucket', - 'labelNames' => array('le'), - 'labelValues' => array_merge($labelValues, array($bucket)), + 'labelNames' => ['le'], + 'labelValues' => array_merge($labelValues, [$bucket]), 'value' => $acc - ); + ]; } else { $acc += $raw[$bucketKey]; - $histogram['samples'][] = array( + $histogram['samples'][] = [ 'name' => $histogram['name'] . '_bucket', - 'labelNames' => array('le'), - 'labelValues' => array_merge($labelValues, array($bucket)), + 'labelNames' => ['le'], + 'labelValues' => array_merge($labelValues, [$bucket]), 'value' => $acc - ); + ]; } } // Add the count - $histogram['samples'][] = array( + $histogram['samples'][] = [ 'name' => $histogram['name'] . '_count', - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $labelValues, 'value' => $acc - ); + ]; // Add the sum - $histogram['samples'][] = array( + $histogram['samples'][] = [ 'name' => $histogram['name'] . '_sum', - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => $labelValues, - 'value' => $raw[json_encode(array('b' => 'sum', 'labelValues' => $labelValues))] - ); + 'value' => $raw[json_encode(['b' => 'sum', 'labelValues' => $labelValues])] + ]; } $histograms[] = $histogram; } @@ -279,21 +281,21 @@ private function collectGauges() { $keys = $this->redis->sMembers(self::$prefix . Gauge::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX); sort($keys); - $gauges = array(); + $gauges = []; foreach ($keys as $key) { $raw = $this->redis->hGetAll($key); $gauge = json_decode($raw['__meta'], true); unset($raw['__meta']); - $gauge['samples'] = array(); + $gauge['samples'] = []; foreach ($raw as $k => $value) { - $gauge['samples'][] = array( + $gauge['samples'][] = [ 'name' => $gauge['name'], - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => json_decode($k, true), 'value' => $value - ); + ]; } - usort($gauge['samples'], function($a, $b){ + usort($gauge['samples'], function ($a, $b) { return strcmp(implode("", $a['labelValues']), implode("", $b['labelValues'])); }); $gauges[] = $gauge; @@ -305,21 +307,21 @@ private function collectCounters() { $keys = $this->redis->sMembers(self::$prefix . Counter::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX); sort($keys); - $counters = array(); + $counters = []; foreach ($keys as $key) { $raw = $this->redis->hGetAll($key); $counter = json_decode($raw['__meta'], true); unset($raw['__meta']); - $counter['samples'] = array(); + $counter['samples'] = []; foreach ($raw as $k => $value) { - $counter['samples'][] = array( + $counter['samples'][] = [ 'name' => $counter['name'], - 'labelNames' => array(), + 'labelNames' => [], 'labelValues' => json_decode($k, true), 'value' => $value - ); + ]; } - usort($counter['samples'], function($a, $b){ + usort($counter['samples'], function ($a, $b) { return strcmp(implode("", $a['labelValues']), implode("", $b['labelValues'])); }); $counters[] = $counter; @@ -327,6 +329,12 @@ private function collectCounters() return $counters; } + /** + * @param integer $cmd Command + * + * @return string + * @throws InvalidArgumentException + */ private function getRedisCommand($cmd) { switch ($cmd) { @@ -347,7 +355,6 @@ private function getRedisCommand($cmd) */ private function toMetricKey(array $data) { - return implode(':', array(self::$prefix, $data['type'], $data['name'])); + return implode(':', [self::$prefix, $data['type'], $data['name']]); } - } diff --git a/tests/Test/BlackBoxPushGatewayTest.php b/tests/Test/BlackBoxPushGatewayTest.php index 26490c6..81d4ecb 100644 --- a/tests/Test/BlackBoxPushGatewayTest.php +++ b/tests/Test/BlackBoxPushGatewayTest.php @@ -22,7 +22,7 @@ public function pushGatewayShouldWork() $counter->incBy(6, ['blue']); $pushGateway = new PushGateway('pushgateway:9091'); - $pushGateway->push($registry, 'my_job', array('instance' => 'foo')); + $pushGateway->push($registry, 'my_job', ['instance' => 'foo']); $httpClient = new Client(); $metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents(); @@ -33,7 +33,7 @@ public function pushGatewayShouldWork() $metrics ); - $pushGateway->delete('my_job', array('instance' => 'foo')); + $pushGateway->delete('my_job', ['instance' => 'foo']); $httpClient = new Client(); $metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents(); diff --git a/tests/Test/Prometheus/APC/CounterTest.php b/tests/Test/Prometheus/APC/CounterTest.php index 5ca3b5d..1cc23cc 100644 --- a/tests/Test/Prometheus/APC/CounterTest.php +++ b/tests/Test/Prometheus/APC/CounterTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractCounterTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension apc */ class CounterTest extends AbstractCounterTest diff --git a/tests/Test/Prometheus/APC/GaugeTest.php b/tests/Test/Prometheus/APC/GaugeTest.php index f1b2c04..b22d592 100644 --- a/tests/Test/Prometheus/APC/GaugeTest.php +++ b/tests/Test/Prometheus/APC/GaugeTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractGaugeTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension apc */ class GaugeTest extends AbstractGaugeTest diff --git a/tests/Test/Prometheus/APC/HistogramTest.php b/tests/Test/Prometheus/APC/HistogramTest.php index 19d41eb..853fde6 100644 --- a/tests/Test/Prometheus/APC/HistogramTest.php +++ b/tests/Test/Prometheus/APC/HistogramTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractHistogramTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension apc */ class HistogramTest extends AbstractHistogramTest diff --git a/tests/Test/Prometheus/AbstractCollectorRegistryTest.php b/tests/Test/Prometheus/AbstractCollectorRegistryTest.php index 237685c..c733013 100644 --- a/tests/Test/Prometheus/AbstractCollectorRegistryTest.php +++ b/tests/Test/Prometheus/AbstractCollectorRegistryTest.php @@ -37,11 +37,11 @@ public function itShouldSaveGauges() { $registry = new CollectorRegistry($this->adapter); - $g = $registry->registerGauge('test', 'some_metric', 'this is for testing', array('foo')); - $g->set(35, array('bbb')); - $g->set(35, array('ddd')); - $g->set(35, array('aaa')); - $g->set(35, array('ccc')); + $g = $registry->registerGauge('test', 'some_metric', 'this is for testing', ['foo']); + $g->set(35, ['bbb']); + $g->set(35, ['ddd']); + $g->set(35, ['aaa']); + $g->set(35, ['ccc']); $registry = new CollectorRegistry($this->adapter); @@ -66,10 +66,10 @@ public function itShouldSaveGauges() public function itShouldSaveCounters() { $registry = new CollectorRegistry($this->adapter); - $metric = $registry->registerCounter('test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $metric->incBy(2, array('lalal', 'lululu')); - $registry->getCounter('test', 'some_metric', array('foo', 'bar'))->inc(array('lalal', 'lululu')); - $registry->getCounter('test', 'some_metric', array('foo', 'bar'))->inc(array('lalal', 'lvlvlv')); + $metric = $registry->registerCounter('test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $metric->incBy(2, ['lalal', 'lululu']); + $registry->getCounter('test', 'some_metric', ['foo', 'bar'])->inc(['lalal', 'lululu']); + $registry->getCounter('test', 'some_metric', ['foo', 'bar'])->inc(['lalal', 'lvlvlv']); $registry = new CollectorRegistry($this->adapter); $this->assertThat( @@ -91,12 +91,12 @@ public function itShouldSaveCounters() public function itShouldSaveHistograms() { $registry = new CollectorRegistry($this->adapter); - $metric = $registry->registerHistogram('test', 'some_metric', 'this is for testing', array('foo', 'bar'), array(0.1, 1, 5, 10)); - $metric->observe(2, array('lalal', 'lululu')); - $registry->getHistogram('test', 'some_metric', array('foo', 'bar'))->observe(7.1, array('lalal', 'lvlvlv')); - $registry->getHistogram('test', 'some_metric', array('foo', 'bar'))->observe(13, array('lalal', 'lululu')); - $registry->getHistogram('test', 'some_metric', array('foo', 'bar'))->observe(7.1, array('lalal', 'lululu')); - $registry->getHistogram('test', 'some_metric', array('foo', 'bar'))->observe(7.1, array('gnaaha', 'hihihi')); + $metric = $registry->registerHistogram('test', 'some_metric', 'this is for testing', ['foo', 'bar'], [0.1, 1, 5, 10]); + $metric->observe(2, ['lalal', 'lululu']); + $registry->getHistogram('test', 'some_metric', ['foo', 'bar'])->observe(7.1, ['lalal', 'lvlvlv']); + $registry->getHistogram('test', 'some_metric', ['foo', 'bar'])->observe(13, ['lalal', 'lululu']); + $registry->getHistogram('test', 'some_metric', ['foo', 'bar'])->observe(7.1, ['lalal', 'lululu']); + $registry->getHistogram('test', 'some_metric', ['foo', 'bar'])->observe(7.1, ['gnaaha', 'hihihi']); $registry = new CollectorRegistry($this->adapter); $this->assertThat( @@ -211,8 +211,8 @@ public function itShouldForbidRegisteringTheSameCounterTwice() public function itShouldForbidRegisteringTheSameCounterWithDifferentLabels() { $registry = new CollectorRegistry( $this->adapter); - $registry->registerCounter('foo', 'metric', 'help', array("foo", "bar")); - $registry->registerCounter('foo', 'metric', 'help', array("spam", "eggs")); + $registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]); + $registry->registerCounter('foo', 'metric', 'help', ["spam", "eggs"]); } /** @@ -233,8 +233,8 @@ public function itShouldForbidRegisteringTheSameHistogramTwice() public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels() { $registry = new CollectorRegistry( $this->adapter); - $registry->registerCounter('foo', 'metric', 'help', array("foo", "bar")); - $registry->registerCounter('foo', 'metric', 'help', array("spam", "eggs")); + $registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]); + $registry->registerCounter('foo', 'metric', 'help', ["spam", "eggs"]); } /** @@ -255,8 +255,8 @@ public function itShouldForbidRegisteringTheSameGaugeTwice() public function itShouldForbidRegisteringTheSameGaugeWithDifferentLabels() { $registry = new CollectorRegistry( $this->adapter); - $registry->registerGauge('foo', 'metric', 'help', array("foo", "bar")); - $registry->registerGauge('foo', 'metric', 'help', array("spam", "eggs")); + $registry->registerGauge('foo', 'metric', 'help', ["foo", "bar"]); + $registry->registerGauge('foo', 'metric', 'help', ["spam", "eggs"]); } /** diff --git a/tests/Test/Prometheus/AbstractCounterTest.php b/tests/Test/Prometheus/AbstractCounterTest.php index 188310c..0b1a0ce 100644 --- a/tests/Test/Prometheus/AbstractCounterTest.php +++ b/tests/Test/Prometheus/AbstractCounterTest.php @@ -10,7 +10,7 @@ use Prometheus\Storage\Adapter; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ abstract class AbstractCounterTest extends PHPUnit_Framework_TestCase { @@ -29,31 +29,31 @@ public function setUp() */ public function itShouldIncreaseWithLabels() { - $gauge = new Counter($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->inc(array('lalal', 'lululu')); - $gauge->inc(array('lalal', 'lululu')); - $gauge->inc(array('lalal', 'lululu')); + $gauge = new Counter($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->inc(['lalal', 'lululu']); + $gauge->inc(['lalal', 'lululu']); + $gauge->inc(['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'type' => Counter::TYPE, 'help' => 'this is for testing', 'name' => 'test_some_metric', - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ + 'labelValues' => ['lalal', 'lululu'], 'value' => 3, 'name' => 'test_some_metric', - 'labelNames' => array() - ), - ) - ) + 'labelNames' => [] + ], + ] + ] ) - ) + ] ) ); } @@ -68,24 +68,24 @@ public function itShouldIncreaseWithoutLabelWhenNoLabelsAreDefined() $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'type' => Counter::TYPE, 'help' => 'this is for testing', 'name' => 'test_some_metric', - 'labelNames' => array(), - 'samples' => array( - array( - 'labelValues' => array(), + 'labelNames' => [], + 'samples' => [ + [ + 'labelValues' => [], 'value' => 1, 'name' => 'test_some_metric', - 'labelNames' => array() - ), - ) - ) + 'labelNames' => [] + ], + ] + ] ) - ) + ] ) ); } @@ -95,30 +95,30 @@ public function itShouldIncreaseWithoutLabelWhenNoLabelsAreDefined() */ public function itShouldIncreaseTheCounterByAnArbitraryInteger() { - $gauge = new Counter($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->inc(array('lalal', 'lululu')); - $gauge->incBy(123, array('lalal', 'lululu')); + $gauge = new Counter($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->inc(['lalal', 'lululu']); + $gauge->incBy(123, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'type' => Counter::TYPE, 'help' => 'this is for testing', 'name' => 'test_some_metric', - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ + 'labelValues' => ['lalal', 'lululu'], 'value' => 124, 'name' => 'test_some_metric', - 'labelNames' => array() - ), - ) - ) + 'labelNames' => [] + ], + ] + ] ) - ) + ] ) ); } @@ -138,7 +138,7 @@ public function itShouldRejectInvalidMetricsNames() */ public function itShouldRejectInvalidLabelNames() { - new Counter($this->adapter, 'test', 'some_metric', 'help', array('invalid label')); + new Counter($this->adapter, 'test', 'some_metric', 'help', ['invalid label']); } /** @@ -150,8 +150,8 @@ public function itShouldRejectInvalidLabelNames() public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($value) { $label = 'foo'; - $histogram = new Counter($this->adapter, 'test', 'some_metric', 'help', array($label)); - $histogram->inc(array($value)); + $histogram = new Counter($this->adapter, 'test', 'some_metric', 'help', [$label]); + $histogram->inc([$value]); $metrics = $this->adapter->collect(); self::assertInternalType('array', $metrics); @@ -181,7 +181,7 @@ public function labelValuesDataProvider() // Basic Latin // See https://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin for ($i = 32; $i <= 121; $i++) { - $cases['ASCII code ' . $i] = array(chr($i)); + $cases['ASCII code ' . $i] = [chr($i)]; } return $cases; } diff --git a/tests/Test/Prometheus/AbstractGaugeTest.php b/tests/Test/Prometheus/AbstractGaugeTest.php index 33ad02c..9f5a4b8 100644 --- a/tests/Test/Prometheus/AbstractGaugeTest.php +++ b/tests/Test/Prometheus/AbstractGaugeTest.php @@ -10,7 +10,7 @@ use Prometheus\Storage\Adapter; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ abstract class AbstractGaugeTest extends PHPUnit_Framework_TestCase { @@ -29,29 +29,29 @@ public function setUp() */ public function itShouldAllowSetWithLabels() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->set(123, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->set(123, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 123, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); $this->assertThat($gauge->getHelp(), $this->equalTo('this is for testing')); @@ -68,24 +68,24 @@ public function itShouldAllowSetWithoutLabelWhenNoLabelsAreDefined() $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array(), - 'samples' => array( - array( + 'labelNames' => [], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 123, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); $this->assertThat($gauge->getHelp(), $this->equalTo('this is for testing')); @@ -102,24 +102,24 @@ public function itShouldAllowSetWithAFloatValue() $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array(), - 'samples' => array( - array( + 'labelNames' => [], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 123.5, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); $this->assertThat($gauge->getHelp(), $this->equalTo('this is for testing')); @@ -131,30 +131,30 @@ public function itShouldAllowSetWithAFloatValue() */ public function itShouldIncrementAValue() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->inc(array('lalal', 'lululu')); - $gauge->incBy(123, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->inc(['lalal', 'lululu']); + $gauge->incBy(123, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 124, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -164,30 +164,30 @@ public function itShouldIncrementAValue() */ public function itShouldIncrementWithFloatValue() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->inc(array('lalal', 'lululu')); - $gauge->incBy(123.5, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->inc(['lalal', 'lululu']); + $gauge->incBy(123.5, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 124.5, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -197,30 +197,30 @@ public function itShouldIncrementWithFloatValue() */ public function itShouldDecrementAValue() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->dec(array('lalal', 'lululu')); - $gauge->decBy(123, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->dec(['lalal', 'lululu']); + $gauge->decBy(123, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => -124, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -230,30 +230,30 @@ public function itShouldDecrementAValue() */ public function itShouldDecrementWithFloatValue() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->dec(array('lalal', 'lululu')); - $gauge->decBy(123, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->dec(['lalal', 'lululu']); + $gauge->decBy(123, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => -124, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -263,30 +263,30 @@ public function itShouldDecrementWithFloatValue() */ public function itShouldOverwriteWhenSettingTwice() { - $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); - $gauge->set(123, array('lalal', 'lululu')); - $gauge->set(321, array('lalal', 'lululu')); + $gauge = new Gauge($this->adapter, 'test', 'some_metric', 'this is for testing', ['foo', 'bar']); + $gauge->set(123, ['lalal', 'lululu']); + $gauge->set(321, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Gauge::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 321, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -306,7 +306,7 @@ public function itShouldRejectInvalidMetricsNames() */ public function itShouldRejectInvalidLabelNames() { - new Gauge($this->adapter, 'test', 'some_metric', 'help', array('invalid label')); + new Gauge($this->adapter, 'test', 'some_metric', 'help', ['invalid label']); } /** @@ -318,8 +318,8 @@ public function itShouldRejectInvalidLabelNames() public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($value) { $label = 'foo'; - $histogram = new Gauge($this->adapter, 'test', 'some_metric', 'help', array($label)); - $histogram->inc(array($value)); + $histogram = new Gauge($this->adapter, 'test', 'some_metric', 'help', [$label]); + $histogram->inc([$value]); $metrics = $this->adapter->collect(); self::assertInternalType('array', $metrics); @@ -349,7 +349,7 @@ public function labelValuesDataProvider() // Basic Latin // See https://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin for ($i = 32; $i <= 121; $i++) { - $cases['ASCII code ' . $i] = array(chr($i)); + $cases['ASCII code ' . $i] = [chr($i)]; } return $cases; } diff --git a/tests/Test/Prometheus/AbstractHistogramTest.php b/tests/Test/Prometheus/AbstractHistogramTest.php index 358fcad..06eff59 100644 --- a/tests/Test/Prometheus/AbstractHistogramTest.php +++ b/tests/Test/Prometheus/AbstractHistogramTest.php @@ -11,7 +11,7 @@ /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ abstract class AbstractHistogramTest extends PHPUnit_Framework_TestCase { @@ -35,62 +35,62 @@ public function itShouldObserveWithLabels() 'test', 'some_metric', 'this is for testing', - array('foo', 'bar'), - array(100, 200, 300) + ['foo', 'bar'], + [100, 200, 300] ); - $histogram->observe(123, array('lalal', 'lululu')); - $histogram->observe(245, array('lalal', 'lululu')); + $histogram->observe(123, ['lalal', 'lululu']); + $histogram->observe(245, ['lalal', 'lululu']); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Histogram::TYPE, - 'labelNames' => array('foo', 'bar'), - 'samples' => array( - array( + 'labelNames' => ['foo', 'bar'], + 'samples' => [ + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('lalal', 'lululu', 100), + 'labelNames' => ['le'], + 'labelValues' => ['lalal', 'lululu', 100], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('lalal', 'lululu', 200), + 'labelNames' => ['le'], + 'labelValues' => ['lalal', 'lululu', 200], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('lalal', 'lululu', 300), + 'labelNames' => ['le'], + 'labelValues' => ['lalal', 'lululu', 300], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('lalal', 'lululu', '+Inf'), + 'labelNames' => ['le'], + 'labelValues' => ['lalal', 'lululu', '+Inf'], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_count', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_sum', - 'labelNames' => array(), - 'labelValues' => array('lalal', 'lululu'), + 'labelNames' => [], + 'labelValues' => ['lalal', 'lululu'], 'value' => 368, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -105,61 +105,61 @@ public function itShouldObserveWithoutLabelWhenNoLabelsAreDefined() 'test', 'some_metric', 'this is for testing', - array(), - array(100, 200, 300) + [], + [100, 200, 300] ); $histogram->observe(245); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Histogram::TYPE, - 'labelNames' => array(), - 'samples' => array( - array( + 'labelNames' => [], + 'samples' => [ + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(100), + 'labelNames' => ['le'], + 'labelValues' => [100], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(200), + 'labelNames' => ['le'], + 'labelValues' => [200], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(300), + 'labelNames' => ['le'], + 'labelValues' => [300], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('+Inf'), + 'labelNames' => ['le'], + 'labelValues' => ['+Inf'], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_count', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_sum', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 245, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -174,62 +174,62 @@ public function itShouldObserveValuesOfTypeDouble() 'test', 'some_metric', 'this is for testing', - array(), - array(0.1, 0.2, 0.3) + [], + [0.1, 0.2, 0.3] ); $histogram->observe(0.11); $histogram->observe(0.3); $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Histogram::TYPE, - 'labelNames' => array(), - 'samples' => array( - array( + 'labelNames' => [], + 'samples' => [ + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.1), + 'labelNames' => ['le'], + 'labelValues' => [0.1], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.2), + 'labelNames' => ['le'], + 'labelValues' => [0.2], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.3), + 'labelNames' => ['le'], + 'labelValues' => [0.3], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('+Inf'), + 'labelNames' => ['le'], + 'labelValues' => ['+Inf'], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_count', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_sum', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 0.41, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -246,7 +246,7 @@ public function itShouldProvideDefaultBuckets() 'test', 'some_metric', 'this is for testing', - array() + [] ); $histogram->observe(0.11); @@ -254,120 +254,120 @@ public function itShouldProvideDefaultBuckets() $this->assertThat( $this->adapter->collect(), $this->equalTo( - array( + [ new MetricFamilySamples( - array( + [ 'name' => 'test_some_metric', 'help' => 'this is for testing', 'type' => Histogram::TYPE, - 'labelNames' => array(), - 'samples' => array( - array( + 'labelNames' => [], + 'samples' => [ + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.005), + 'labelNames' => ['le'], + 'labelValues' => [0.005], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.01), + 'labelNames' => ['le'], + 'labelValues' => [0.01], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.025), + 'labelNames' => ['le'], + 'labelValues' => [0.025], 'value' => 0, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.05), + 'labelNames' => ['le'], + 'labelValues' => [0.05], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.075), + 'labelNames' => ['le'], + 'labelValues' => [0.075], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.1), + 'labelNames' => ['le'], + 'labelValues' => [0.1], 'value' => 1, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.25), + 'labelNames' => ['le'], + 'labelValues' => [0.25], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.5), + 'labelNames' => ['le'], + 'labelValues' => [0.5], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(0.75), + 'labelNames' => ['le'], + 'labelValues' => [0.75], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(1.0), + 'labelNames' => ['le'], + 'labelValues' => [1.0], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(2.5), + 'labelNames' => ['le'], + 'labelValues' => [2.5], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(5), + 'labelNames' => ['le'], + 'labelValues' => [5], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(7.5), + 'labelNames' => ['le'], + 'labelValues' => [7.5], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array(10), + 'labelNames' => ['le'], + 'labelValues' => [10], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_bucket', - 'labelNames' => array('le'), - 'labelValues' => array('+Inf'), + 'labelNames' => ['le'], + 'labelValues' => ['+Inf'], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_count', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 2, - ), - array( + ], + [ 'name' => 'test_some_metric_sum', - 'labelNames' => array(), - 'labelValues' => array(), + 'labelNames' => [], + 'labelValues' => [], 'value' => 0.14, - ) - ) - ) + ] + ] + ] ) - ) + ] ) ); } @@ -379,7 +379,7 @@ public function itShouldProvideDefaultBuckets() */ public function itShouldThrowAnExceptionWhenTheBucketSizesAreNotIncreasing() { - new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', array(), array(1, 1)); + new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', [], [1, 1]); } /** @@ -389,7 +389,7 @@ public function itShouldThrowAnExceptionWhenTheBucketSizesAreNotIncreasing() */ public function itShouldThrowAnExceptionWhenThereIsLessThanOneBucket() { - new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', array(), array()); + new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', [], []); } /** @@ -399,7 +399,7 @@ public function itShouldThrowAnExceptionWhenThereIsLessThanOneBucket() */ public function itShouldThrowAnExceptionWhenThereIsALabelNamedLe() { - new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', array('le'), array(1)); + new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', ['le'], [1]); } /** @@ -409,7 +409,7 @@ public function itShouldThrowAnExceptionWhenThereIsALabelNamedLe() */ public function itShouldRejectInvalidMetricsNames() { - new Histogram($this->adapter, 'test', 'some invalid metric', 'help', array(), array(1)); + new Histogram($this->adapter, 'test', 'some invalid metric', 'help', [], [1]); } /** @@ -419,7 +419,7 @@ public function itShouldRejectInvalidMetricsNames() */ public function itShouldRejectInvalidLabelNames() { - new Histogram($this->adapter, 'test', 'some_metric', 'help', array('invalid label'), array(1)); + new Histogram($this->adapter, 'test', 'some_metric', 'help', ['invalid label'], [1]); } /** @@ -431,8 +431,8 @@ public function itShouldRejectInvalidLabelNames() public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($value) { $label = 'foo'; - $histogram = new Histogram($this->adapter, 'test', 'some_metric', 'help', array($label), array(1)); - $histogram->observe(1, array($value)); + $histogram = new Histogram($this->adapter, 'test', 'some_metric', 'help', [$label], [1]); + $histogram->observe(1, [$value]); $metrics = $this->adapter->collect(); self::assertInternalType('array', $metrics); @@ -462,7 +462,7 @@ public function labelValuesDataProvider() // Basic Latin // See https://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin for ($i = 32; $i <= 121; $i++) { - $cases['ASCII code ' . $i] = array(chr($i)); + $cases['ASCII code ' . $i] = [chr($i)]; } return $cases; } diff --git a/tests/Test/Prometheus/InMemory/CounterTest.php b/tests/Test/Prometheus/InMemory/CounterTest.php index 03ed614..21a16e6 100644 --- a/tests/Test/Prometheus/InMemory/CounterTest.php +++ b/tests/Test/Prometheus/InMemory/CounterTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractCounterTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ class CounterTest extends AbstractCounterTest { diff --git a/tests/Test/Prometheus/InMemory/GaugeTest.php b/tests/Test/Prometheus/InMemory/GaugeTest.php index 75e0f3c..aa2403e 100644 --- a/tests/Test/Prometheus/InMemory/GaugeTest.php +++ b/tests/Test/Prometheus/InMemory/GaugeTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractGaugeTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ class GaugeTest extends AbstractGaugeTest { diff --git a/tests/Test/Prometheus/InMemory/HistogramTest.php b/tests/Test/Prometheus/InMemory/HistogramTest.php index 283ec3e..3529fc4 100644 --- a/tests/Test/Prometheus/InMemory/HistogramTest.php +++ b/tests/Test/Prometheus/InMemory/HistogramTest.php @@ -7,7 +7,7 @@ use Test\Prometheus\AbstractHistogramTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ */ class HistogramTest extends AbstractHistogramTest { diff --git a/tests/Test/Prometheus/Redis/CollectorRegistryTest.php b/tests/Test/Prometheus/Redis/CollectorRegistryTest.php index 2e69ce9..b023e23 100644 --- a/tests/Test/Prometheus/Redis/CollectorRegistryTest.php +++ b/tests/Test/Prometheus/Redis/CollectorRegistryTest.php @@ -14,7 +14,7 @@ class CollectorRegistryTest extends AbstractCollectorRegistryTest { public function configureAdapter() { - $this->adapter = new Redis(array('host' => REDIS_HOST)); + $this->adapter = new Redis(['host' => REDIS_HOST]); $this->adapter->flushRedis(); } } diff --git a/tests/Test/Prometheus/Redis/CounterTest.php b/tests/Test/Prometheus/Redis/CounterTest.php index 088f9dd..c92e2d5 100644 --- a/tests/Test/Prometheus/Redis/CounterTest.php +++ b/tests/Test/Prometheus/Redis/CounterTest.php @@ -7,14 +7,14 @@ use Test\Prometheus\AbstractCounterTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension redis */ class CounterTest extends AbstractCounterTest { public function configureAdapter() { - $this->adapter = new Redis(array('host' => REDIS_HOST)); + $this->adapter = new Redis(['host' => REDIS_HOST]); $this->adapter->flushRedis(); } } diff --git a/tests/Test/Prometheus/Redis/GaugeTest.php b/tests/Test/Prometheus/Redis/GaugeTest.php index c359037..562626e 100644 --- a/tests/Test/Prometheus/Redis/GaugeTest.php +++ b/tests/Test/Prometheus/Redis/GaugeTest.php @@ -7,14 +7,14 @@ use Test\Prometheus\AbstractGaugeTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension redis */ class GaugeTest extends AbstractGaugeTest { public function configureAdapter() { - $this->adapter = new Redis(array('host' => REDIS_HOST)); + $this->adapter = new Redis(['host' => REDIS_HOST]); $this->adapter->flushRedis(); } } diff --git a/tests/Test/Prometheus/Redis/HistogramTest.php b/tests/Test/Prometheus/Redis/HistogramTest.php index da15c25..bf71716 100644 --- a/tests/Test/Prometheus/Redis/HistogramTest.php +++ b/tests/Test/Prometheus/Redis/HistogramTest.php @@ -7,14 +7,14 @@ use Test\Prometheus\AbstractHistogramTest; /** - * See https://prometheus.io/docs/instrumenting/exposition_formats/ + * @see https://prometheus.io/docs/instrumenting/exposition_formats/ * @requires extension redis */ class HistogramTest extends AbstractHistogramTest { public function configureAdapter() { - $this->adapter = new Redis(array('host' => REDIS_HOST)); + $this->adapter = new Redis(['host' => REDIS_HOST]); $this->adapter->flushRedis(); } } diff --git a/tests/Test/Prometheus/Storage/RedisTest.php b/tests/Test/Prometheus/Storage/RedisTest.php index 8175475..9a1d837 100644 --- a/tests/Test/Prometheus/Storage/RedisTest.php +++ b/tests/Test/Prometheus/Storage/RedisTest.php @@ -15,7 +15,7 @@ class RedisTest extends \PHPUnit_Framework_TestCase */ public function itShouldThrowAnExceptionOnConnectionFailure() { - $redis = new Redis(array('host' => 'doesntexist.test')); + $redis = new Redis(['host' => 'doesntexist.test']); $redis->flushRedis(); }