Skip to content

Commit

Permalink
Merge pull request #8 from flownative/task/cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
robertlemke authored Aug 25, 2022
2 parents de2521b + 28a11aa commit e4c6742
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 73 deletions.
9 changes: 5 additions & 4 deletions Classes/Collector/AbstractCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus\Collector;

/*
Expand All @@ -14,22 +15,22 @@ abstract class AbstractCollector
/**
* @var StorageInterface
*/
protected $storage;
protected StorageInterface $storage;

/**
* @var string
*/
protected $name;
protected string $name;

/**
* @var string
*/
protected $help = '';
protected string $help = '';

/**
* @var array
*/
protected $labels = [];
protected array $labels = [];

/**
* @param StorageInterface $storage
Expand Down
3 changes: 2 additions & 1 deletion Classes/Collector/Counter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus\Collector;

/*
Expand All @@ -23,7 +24,7 @@ public function getType(): string
}

/**
* @param int|float|double $amount
* @param int|float $amount
* @param array $labels
*/
public function inc($amount = 1, array $labels = []): void
Expand Down
7 changes: 4 additions & 3 deletions Classes/Collector/Gauge.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus\Collector;

/*
Expand All @@ -25,7 +26,7 @@ public function getType(): string
/**
* Increase the gauge's value
*
* @param int|float|double $amount
* @param int|float $amount
* @param array $labels
*/
public function inc($amount = 1, array $labels = []): void
Expand All @@ -36,7 +37,7 @@ public function inc($amount = 1, array $labels = []): void
/**
* Decrease the gauge's value
*
* @param int|float|double $amount
* @param int|float $amount
* @param array $labels
*/
public function dec($amount = 1, array $labels = []): void
Expand All @@ -47,7 +48,7 @@ public function dec($amount = 1, array $labels = []): void
/**
* Set the gauge's value
*
* @param int|float|double $value
* @param int|float $value
* @param array $labels
*/
public function set($value, array $labels = []): void
Expand Down
8 changes: 4 additions & 4 deletions Classes/CollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class CollectorRegistry
/**
* @var StorageInterface
*/
protected $storage;
protected StorageInterface $storage;

/**
* @var array
*/
protected $counters = [];
protected array $counters = [];

/**
* @var array
*/
protected $gauges = [];
protected array $gauges = [];

/**
* @param StorageInterface $storage
Expand All @@ -52,7 +52,7 @@ public function registerMany(array $collectorConfigurations): void
/**
* @param string $name
* @param string $type
* @param string|null $help
* @param string $help
* @param array $labels
* @throws InvalidCollectorTypeException
*/
Expand Down
7 changes: 4 additions & 3 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus;

/*
Expand All @@ -16,17 +17,17 @@ class Configuration
/**
* @var string
*/
protected $type;
protected string $type;

/**
* @var string
*/
protected $help = '';
protected string $help = '';

/**
* @var array
*/
protected $labels = [];
protected array $labels = [];

/**
* @param string $type
Expand Down
2 changes: 1 addition & 1 deletion Classes/DefaultCollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class DefaultCollectorRegistry extends CollectorRegistry
* @Flow\InjectConfiguration(path="metrics")
* @var array
*/
protected $settings;
protected array $settings = [];

/**
* @throws Exception\InvalidCollectorTypeException
Expand Down
8 changes: 4 additions & 4 deletions Classes/Http/MetricsExporterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class MetricsExporterMiddleware implements MiddlewareInterface
/**
* @var CollectorRegistry
*/
protected $collectorRegistry;
protected CollectorRegistry $collectorRegistry;

/**
* @var LoggerInterface
* @var LoggerInterface|null
*/
protected $logger;
protected ?LoggerInterface $logger = null;

/**
* @var array
*/
protected $options = [
protected array $options = [
'telemetryPath' => '/metrics',
'basicAuth' => []
];
Expand Down
6 changes: 3 additions & 3 deletions Classes/Renderer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus;

/*
Expand Down Expand Up @@ -41,19 +42,18 @@ public function render(array $sampleCollections): string
}
$lines[] = '# TYPE ' . $sampleCollection->getName() . " {$sampleCollection->getType()}";
foreach ($sampleCollection->getSamples() as $sample) {
$lines[] = $this->renderSample($sampleCollection, $sample);
$lines[] = $this->renderSample($sample);
}
$lines[] = '';
}
return trim(implode("\n", $lines));
}

/**
* @param SampleCollection $sampleCollection
* @param Sample $sample
* @return string
*/
private function renderSample(SampleCollection $sampleCollection, Sample $sample): string
private function renderSample(Sample $sample): string
{
$labelStatements = [];
foreach ($sample->getLabels() as $labelName => $labelValue) {
Expand Down
7 changes: 4 additions & 3 deletions Classes/Sample.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus;

/*
Expand All @@ -12,15 +13,15 @@ class Sample
/**
* @var string
*/
private $name;
private string $name;

/**
* @var array
*/
private $labels;
private array $labels;

/**
* @var int|double
* @var int|float
*/
private $value;

Expand Down
11 changes: 6 additions & 5 deletions Classes/SampleCollection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Flownative\Prometheus;

/*
Expand All @@ -12,27 +13,27 @@ class SampleCollection
/**
* @var string
*/
private $name;
private string $name;

/**
* @var string
*/
private $type;
private string $type;

/**
* @var string
*/
private $help;
private string $help;

/**
* @var array
*/
private $labels;
private array $labels;

/**
* @var Sample[]
*/
private $samples = [];
private array $samples;

/**
* @param string $name
Expand Down
8 changes: 4 additions & 4 deletions Classes/Storage/CounterUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class CounterUpdate
*
* @var string
*/
private $operation;
private string $operation;

/**
* A positive number
*
* @var int|double|float
* @var int|float
*/
private $value;

/**
* @var array
*/
private $labels;
private array $labels;

/**
* @param string $operation
Expand All @@ -40,7 +40,7 @@ public function __construct(string $operation, $value, array $labels)
throw new \InvalidArgumentException(sprintf('counter update: invalid operation type "%s"', $operation), 1573814341);
}
if (!is_numeric($value) || $value < 0) {
throw new \InvalidArgumentException(sprintf('invalid value for counter update, must be a positive number'), 1573814397);
throw new \InvalidArgumentException('invalid value for counter update, must be a positive number', 1573814397);
}
$this->operation = $operation;
$this->value = $value;
Expand Down
8 changes: 4 additions & 4 deletions Classes/Storage/GaugeUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class GaugeUpdate
*
* @var string
*/
private $operation;
private string $operation;

/**
* A positive number
*
* @var int|double|float
* @var int|float
*/
private $value;

/**
* @var array
*/
private $labels;
private array $labels;

/**
* @param string $operation
Expand All @@ -40,7 +40,7 @@ public function __construct(string $operation, $value, array $labels)
throw new \InvalidArgumentException(sprintf('gauge update: invalid operation type "%s"', $operation), 1574257299);
}
if (!is_numeric($value)) {
throw new \InvalidArgumentException(sprintf('invalid value for gauge update, must be a number'), 1574257303);
throw new \InvalidArgumentException('invalid value for gauge update, must be a number', 1574257303);
}
$this->operation = $operation;
$this->value = $value;
Expand Down
8 changes: 6 additions & 2 deletions Classes/Storage/InMemoryStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ class InMemoryStorage extends AbstractStorage
/**
* @var array
*/
private $countersData = [];
private array $countersData = [];

/**
* @var array
*/
private $gaugesData = [];
private array $gaugesData = [];

/**
* @return SampleCollection[]
* @throws \Exception
*/
public function collect(): array
{
Expand Down Expand Up @@ -79,6 +80,7 @@ public function registerCollector(AbstractCollector $collector): void
* @param Counter $counter
* @param CounterUpdate $update
* @return void
* @throws \Exception
*/
public function updateCounter(Counter $counter, CounterUpdate $update): void
{
Expand All @@ -102,6 +104,7 @@ public function updateCounter(Counter $counter, CounterUpdate $update): void
* @param Gauge $gauge
* @param GaugeUpdate $update
* @return void
* @throws \Exception
*/
public function updateGauge(Gauge $gauge, GaugeUpdate $update): void
{
Expand Down Expand Up @@ -130,6 +133,7 @@ public function updateGauge(Gauge $gauge, GaugeUpdate $update): void
/**
* @param array $collectorsData
* @return SampleCollection[]
* @throws \Exception
*/
private function prepareCollections(array $collectorsData): array
{
Expand Down
Loading

0 comments on commit e4c6742

Please sign in to comment.