Skip to content

Commit a016bb7

Browse files
authored
Add PHPStan (#8)
* add phpstan * make phpstan happy
1 parent 7433aef commit a016bb7

25 files changed

+216
-19
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ jobs:
4242

4343
- name: Style check
4444
run: composer php-cs-fixer-check
45+
46+
- name: Static Analysis
47+
run: composer static-analysis

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"friendsofphp/php-cs-fixer": "^3.59",
2020
"league/statsd": "^2.0.0",
2121
"cosmastech/psr-logger-spy": "^0.0.2",
22-
"datadog/php-datadogstatsd": "^1.6.1"
22+
"datadog/php-datadogstatsd": "^1.6.1",
23+
"phpstan/phpstan": "^1.11"
2324
},
2425
"suggest": {
2526
"datadog/php-datadogstatsd": "For DataDog stats",
@@ -40,6 +41,9 @@
4041
"scripts": {
4142
"test": "phpunit tests",
4243
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix ./",
43-
"php-cs-fixer-check": "./vendor/bin/php-cs-fixer check ./"
44+
"php-cs-fixer-check": "./vendor/bin/php-cs-fixer check ./",
45+
"static-analysis": [
46+
"@php vendor/bin/phpstan analyse -c phpstan.neon"
47+
]
4448
}
4549
}

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src
5+
- tests

src/Adapters/Concerns/HasDefaultTagsTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
trait HasDefaultTagsTrait
66
{
7+
/**
8+
* @var array<mixed, mixed>
9+
*/
710
protected array $defaultTags = [];
811

912
/**
@@ -23,8 +26,8 @@ public function setDefaultTags(array $defaultTags = []): void
2326
}
2427

2528
/**
26-
* @param array<string, mixed> $tags
27-
* @return array<string, mixed>
29+
* @param array<mixed, mixed> $tags
30+
* @return array<mixed, mixed>
2831
*/
2932
protected function mergeTags(array $tags): array
3033
{

src/Adapters/Concerns/TagNormalizerAwareTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public function setTagNormalizer(TagNormalizer $tagNormalizer): void
1313
$this->tagNormalizer = $tagNormalizer;
1414
}
1515

16+
/**
17+
* @param array<mixed, mixed> $tags
18+
* @return array<mixed, mixed>
19+
*/
1620
protected function normalizeTags(array $tags): array
1721
{
1822
return $this->tagNormalizer->normalize($tags);

src/Adapters/Datadog/DatadogStatsDClientAdapter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class DatadogStatsDClientAdapter implements StatsDClientAdapter, TagNormalizerAw
1414
use HasDefaultTagsTrait;
1515
use TagNormalizerAwareTrait;
1616

17+
/**
18+
* @param DogStatsd $datadogClient
19+
* @param array<mixed, mixed> $defaultTags
20+
*/
1721
public function __construct(protected readonly DogStatsd $datadogClient, array $defaultTags = [])
1822
{
1923
$this->tagNormalizer = new NoopTagNormalizer();
@@ -90,7 +94,7 @@ public function decrement(array|string $stats, float $sampleRate = 1.0, array $t
9094
);
9195
}
9296

93-
public function updateStats(array|string $stats, int $delta = 1, $sampleRate = 1.0, $tags = null): void
97+
public function updateStats(array|string $stats, int $delta = 1, $sampleRate = 1.0, array $tags = null): void
9498
{
9599
$this->datadogClient->updateStats(
96100
$stats,

src/Adapters/InMemory/InMemoryClientAdapter.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class InMemoryClientAdapter implements StatsDClientAdapter, TagNormalizerAware
2525
protected InMemoryStatsRecord $stats;
2626
protected readonly ClockInterface $clock;
2727

28+
/**
29+
* @param ClockInterface $clock
30+
* @param array<mixed, mixed> $defaultTags
31+
*/
2832
public function __construct(ClockInterface $clock = new Clock(), array $defaultTags = [])
2933
{
3034
$this->clock = $clock;
@@ -34,6 +38,9 @@ public function __construct(ClockInterface $clock = new Clock(), array $defaultT
3438
$this->setDefaultTags($defaultTags);
3539
}
3640

41+
/**
42+
* @inheritDoc
43+
*/
3744
public function timing(string $stat, float $durationMs, float $sampleRate = 1.0, array $tags = []): void
3845
{
3946
$this->stats->timing[] = new InMemoryTimingRecord(
@@ -45,6 +52,9 @@ public function timing(string $stat, float $durationMs, float $sampleRate = 1.0,
4552
);
4653
}
4754

55+
/**
56+
* @inheritDoc
57+
*/
4858
public function gauge(string $stat, float $value, float $sampleRate = 1.0, array $tags = []): void
4959
{
5060
$this->stats->gauge[] = new InMemoryGaugeRecord(
@@ -103,7 +113,10 @@ public function decrement(array|string $stats, float $sampleRate = 1.0, array $t
103113
$this->updateStats($stats, $value, $sampleRate, $tags);
104114
}
105115

106-
public function updateStats(array|string $stats, int $delta = 1, $sampleRate = 1.0, $tags = null): void
116+
/**
117+
* @inheritDoc
118+
*/
119+
public function updateStats(array|string $stats, int $delta = 1, float $sampleRate = 1.0, array $tags = []): void
107120
{
108121
$stats = (array) $stats;
109122
$now = $this->clock->now();

src/Adapters/InMemory/Models/InMemoryCountRecord.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
class InMemoryCountRecord
88
{
9+
/**
10+
* @param string $stat
11+
* @param int $count
12+
* @param float $sampleRate
13+
* @param array<mixed, mixed> $tags
14+
* @param DateTimeImmutable $recordedAt
15+
*/
916
public function __construct(
1017
public string $stat,
1118
public int $count,

src/Adapters/InMemory/Models/InMemoryDistributionRecord.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
readonly class InMemoryDistributionRecord
88
{
9+
/**
10+
* @param string $stat
11+
* @param float $value
12+
* @param float $sampleRate
13+
* @param array<mixed, mixed> $tags
14+
* @param DateTimeImmutable $recordedAt
15+
*/
916
public function __construct(
1017
public string $stat,
1118
public float $value,

src/Adapters/InMemory/Models/InMemoryGaugeRecord.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
readonly class InMemoryGaugeRecord
88
{
9+
/**
10+
* @param string $stat
11+
* @param float $value
12+
* @param float $sampleRate
13+
* @param array<mixed, mixed> $tags
14+
* @param DateTimeImmutable $recordedAt
15+
*/
916
public function __construct(
1017
public string $stat,
1118
public float $value,

0 commit comments

Comments
 (0)