Skip to content

Commit

Permalink
Replace annotations with types on properties when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSuisse committed May 28, 2021
1 parent aa0b485 commit 08b06f7
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 60 deletions.
3 changes: 1 addition & 2 deletions src/Counter.php
Expand Up @@ -16,8 +16,7 @@
*/
final class Counter extends Metric
{
/** @var CounterStorage */
private $storage;
private CounterStorage $storage;

public function __construct(CounterStorage $storage, MetricName $name, string $help, ?MetricLabelNames $labelNames = null)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Gauge.php
Expand Up @@ -13,8 +13,7 @@
*/
final class Gauge extends Metric
{
/** @var GaugeStorage */
private $storage;
private GaugeStorage $storage;

public function __construct(GaugeStorage $storage, MetricName $name, string $help, ?MetricLabelNames $labelNames = null)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Histogram.php
Expand Up @@ -36,11 +36,10 @@ final class Histogram extends Metric
10.0,
];

/** @var HistogramStorage */
private $storage;
private HistogramStorage $storage;

/** @var float[] */
private $buckets;
private array $buckets;

/**
* @param float[] $buckets
Expand Down
13 changes: 5 additions & 8 deletions src/MetricFamilySamples.php
Expand Up @@ -11,16 +11,13 @@
*/
final class MetricFamilySamples
{
/** @var string */
private $name;
/** @var string */
private $type;
/** @var string */
private $help;
private string $name;
private string $type;
private string $help;
/** @var string[] */
private $labelNames;
private array $labelNames;
/** @var Sample[] */
private $samples;
private array $samples;

/**
* @param string[] $labelNames
Expand Down
12 changes: 4 additions & 8 deletions src/PushGateway/PSR18Pusher.php
Expand Up @@ -17,14 +17,10 @@

final class PSR18Pusher implements Pusher
{
/** @var string */
private $address;
/** @var ClientInterface */
private $client;
/** @var RequestFactoryInterface */
private $requestFactory;
/** @var StreamFactoryInterface */
private $streamFactory;
private string $address;
private ClientInterface $client;
private RequestFactoryInterface $requestFactory;
private StreamFactoryInterface $streamFactory;

public function __construct(string $address, ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory)
{
Expand Down
6 changes: 2 additions & 4 deletions src/PushGateway/PSR18UnexpectedPushGatewayResponse.php
Expand Up @@ -10,10 +10,8 @@

final class PSR18UnexpectedPushGatewayResponse extends UnexpectedPushGatewayResponse
{
/** @var RequestInterface */
private $request;
/** @var ResponseInterface|null */
private $response;
private RequestInterface $request;
private ?ResponseInterface $response;

private function __construct(RequestInterface $request, ?ResponseInterface $response, ?ClientExceptionInterface $clientException)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Registry/CollectorRegistry.php
Expand Up @@ -22,11 +22,11 @@ final class CollectorRegistry implements Registry, Collector
/** @var CounterStorage&GaugeStorage&HistogramStorage&Store */
private $storageAdapter;
/** @var Gauge[] */
private $gauges = [];
private array $gauges = [];
/** @var Counter[] */
private $counters = [];
private array $counters = [];
/** @var Histogram[] */
private $histograms = [];
private array $histograms = [];

/**
* @param CounterStorage|GaugeStorage|HistogramStorage|Store $storage
Expand Down
3 changes: 1 addition & 2 deletions src/Renderer/IncoherentMetricLabelNamesAndValues.php
Expand Up @@ -12,8 +12,7 @@

final class IncoherentMetricLabelNamesAndValues extends RuntimeException
{
/** @var MetricFamilySamples */
private $metric;
private MetricFamilySamples $metric;

public function __construct(MetricFamilySamples $metric, int $nbLabelNames, int $nbLabelValues)
{
Expand Down
10 changes: 4 additions & 6 deletions src/Sample.php
Expand Up @@ -11,14 +11,12 @@
*/
final class Sample
{
/** @var string */
private $name;
private string $name;
/** @var string[] */
private $labelNames;
private array $labelNames;
/** @var string[] */
private $labelValues;
/** @var float */
private $value;
private array $labelValues;
private float $value;

/**
* @param string[] $labelNames
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/InMemoryStore.php
Expand Up @@ -35,23 +35,23 @@ final class InMemoryStore implements Store, CounterStorage, GaugeStorage, Histog
* samples: array<string, float>
* }>
*/
private $counters = [];
private array $counters = [];
/**
* @var array<string,string[][]>
* @psalm-var array<string, array{
* meta: array{name:string, help:string, labelNames:string[]},
* samples: array<string, float>
* }>
*/
private $gauges = [];
private array $gauges = [];
/**
* @var array<string,string[][]>
* @psalm-var array<string, array{
* meta: array{name:string, help:string, labelNames:string[], buckets:array<int|float>},
* samples: array<string, float>
* }>
*/
private $histograms = [];
private array $histograms = [];

/**
* @inheritdoc
Expand Down
6 changes: 2 additions & 4 deletions src/Storage/RedisStore.php
Expand Up @@ -28,11 +28,9 @@ final class RedisStore implements Store, CounterStorage, GaugeStorage, Histogram
{
public const PROMETHEUS_METRIC_KEYS_SUFFIX = '_METRIC_KEYS';

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

/** @var Redis */
private $redis;
private Redis $redis;

public function __construct(Redis $redisClient, string $keyPrefix = 'PROMETHEUS_')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Value/HistogramLabelNames.php
Expand Up @@ -16,8 +16,7 @@ final class HistogramLabelNames implements LabelNames
{
private const RESERVED_LABEL_HISTOGRAM = 'le';

/** @var MetricLabelNames */
private $names;
private MetricLabelNames $names;

private function __construct(MetricLabelNames $names)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Value/MetricLabelNames.php
Expand Up @@ -20,7 +20,7 @@ final class MetricLabelNames implements LabelNames
private const RESERVED_LABEL_PREFIX = '__';

/** @var string[] */
private $names;
private array $names;

private function __construct(string ...$names)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Value/MetricName.php
Expand Up @@ -16,8 +16,7 @@ final class MetricName
{
private const METRIC_NAME_REGEX = '/^[a-zA-Z_:][a-zA-Z0-9_:]*$/';

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

private function __construct(string $name)
{
Expand Down
9 changes: 3 additions & 6 deletions tests/functionnal/BlackBoxTest.php
Expand Up @@ -16,13 +16,10 @@ final class BlackBoxTest extends TestCase
{
private const BASE_URI = 'http://nginx:80/';

/** @var HttpAsyncClient */
private $client;
/** @var RequestFactoryInterface */
private $requestFactory;
private HttpAsyncClient $client;
private RequestFactoryInterface $requestFactory;

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

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/Storage/CollectorRegistryBaseTest.php
Expand Up @@ -20,8 +20,7 @@

abstract class CollectorRegistryBaseTest extends TestCase
{
/** @var RenderTextFormat */
private $renderer;
private RenderTextFormat $renderer;

/**
* @return CounterStorage&GaugeStorage&HistogramStorage&Store
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/Storage/Redis/ConfigureRedisStorage.php
Expand Up @@ -11,8 +11,7 @@

trait ConfigureRedisStorage
{
/** @var RedisStore */
public $adapter;
public RedisStore $adapter;

private function getRedisClient(): Redis
{
Expand Down

0 comments on commit 08b06f7

Please sign in to comment.