Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Fix some coding standards (PSR2, short array syntax, @throws tags) #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions examples/flush_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
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();
$apcAdapter->flushAPC();
} elseif ($adapter === 'in-memory') {
$inMemoryAdapter = new Prometheus\Storage\InMemory();
$inMemoryAdapter->flushMemory();
}
}
2 changes: 1 addition & 1 deletion examples/metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions examples/pushgateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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']);
2 changes: 1 addition & 1 deletion examples/some_counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions examples/some_gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/some_histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/Prometheus/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Prometheus;


use Prometheus\Storage\Adapter;

abstract class Collector
Expand All @@ -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;
Expand All @@ -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()
{
Expand Down
19 changes: 9 additions & 10 deletions src/Prometheus/CollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Prometheus;


use Prometheus\Exception\MetricNotFoundException;
use Prometheus\Exception\MetricsRegistrationException;
use Prometheus\Storage\Adapter;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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);
Expand All @@ -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])) {
Expand Down Expand Up @@ -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);
Expand All @@ -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])) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/Prometheus/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Prometheus;


use Prometheus\Storage\Adapter;

class Counter extends Collector
Expand All @@ -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);
}
Expand All @@ -29,20 +28,20 @@ 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(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => $count,
'command' => Adapter::COMMAND_INCREMENT_INTEGER
)
]
);
}
}
1 change: 0 additions & 1 deletion src/Prometheus/Exception/MetricNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Prometheus\Exception;


/**
* Exception thrown if a metric can't be found in the CollectorRegistry.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Prometheus/Exception/MetricsRegistrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Prometheus\Exception;


/**
* Exception thrown if an error occurs during metrics registration.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Prometheus/Exception/StorageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Prometheus\Exception;


/**
* Exception thrown if an error occurs during metrics storage.
*/
Expand Down
19 changes: 9 additions & 10 deletions src/Prometheus/Gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Prometheus;


use Prometheus\Storage\Adapter;

class Gauge extends Collector
Expand All @@ -14,20 +13,20 @@ 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(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'value' => $value,
'command' => Adapter::COMMAND_SET
)
]
);
}

Expand All @@ -39,34 +38,34 @@ 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(),
'labelNames' => $this->getLabelNames(),
'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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Prometheus/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Prometheus;


use Prometheus\Storage\Adapter;

class Histogram extends Collector
Expand All @@ -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);

Expand Down Expand Up @@ -53,29 +53,29 @@ 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(),
'type' => $this->getType(),
'labelNames' => $this->getLabelNames(),
'labelValues' => $labels,
'buckets' => $this->buckets,
)
]
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/MetricFamilySamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MetricFamilySamples
private $type;
private $help;
private $labelNames;
private $samples = array();
private $samples = [];

/**
* @param array $data
Expand Down
Loading