Skip to content

Commit 0b34edc

Browse files
authored
Decrease psalm error level (#85)
1 parent f16f39d commit 0b34edc

14 files changed

+22
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"kevinrob/guzzle-cache-middleware": "^3",
2525
"phpunit/php-code-coverage": "^9",
2626
"phpunit/phpunit": "^9",
27-
"vimeo/psalm": "4.9.2"
27+
"vimeo/psalm": "^4.0"
2828
},
2929
"suggest": {
3030
"guzzlehttp/guzzle": "(^7) Required when using GuzzleEventPublisher or the default FeatureRequester",

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="4"
3+
errorLevel="2"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

src/LaunchDarkly/FeatureFlagsState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FeatureFlagsState implements \JsonSerializable
2121
/** @var array */
2222
protected $_flagValues;
2323

24-
/** @var array */
24+
/** @var array<string, array{debugEventsUntilDate?: int|null, reason?: EvaluationReason, trackEvents?: true, variation?: int|null, version?: int}> **/
2525
protected $_flagMetadata;
2626

2727
/**

src/LaunchDarkly/FeatureRequester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getSegment(string $key): ?Segment;
3333
/**
3434
* Gets all feature flags.
3535
*
36-
* @return array|null The decoded FeatureFlags, or null if missing
36+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
3737
*/
3838
public function getAllFeatures(): ?array;
3939
}

src/LaunchDarkly/Impl/Events/EventFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function newEvalEvent(
5858
if ($prereqOfFlag) {
5959
$e['prereqOf'] = $prereqOfFlag->getKey();
6060
}
61-
if (($addExperimentData || $this->_withReasons) && $detail->getReason()) {
61+
if (($addExperimentData || $this->_withReasons)) {
6262
$e['reason'] = $detail->getReason()->jsonSerialize();
6363
}
6464
if ($user->getAnonymous()) {
@@ -88,7 +88,7 @@ public function newDefaultEvent(FeatureFlag $flag, LDUser $user, EvaluationDetai
8888
if ($flag->getDebugEventsUntilDate()) {
8989
$e['debugEventsUntilDate'] = $flag->getDebugEventsUntilDate();
9090
}
91-
if ($this->_withReasons && $detail->getReason()) {
91+
if ($this->_withReasons) {
9292
$e['reason'] = $detail->getReason()->jsonSerialize();
9393
}
9494
if ($user->getAnonymous()) {
@@ -111,7 +111,7 @@ public function newUnknownFlagEvent(string $key, LDUser $user, EvaluationDetail
111111
'default' => $detail->getValue()
112112
];
113113
// the following properties are handled separately so we don't waste bandwidth on unused keys
114-
if ($this->_withReasons && $detail->getReason()) {
114+
if ($this->_withReasons) {
115115
$e['reason'] = $detail->getReason()->jsonSerialize();
116116
}
117117
if ($user->getAnonymous()) {

src/LaunchDarkly/Impl/Events/EventProcessor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ class EventProcessor
2525
/** @var int */
2626
private $_capacity;
2727

28-
public function __construct(string $sdkKey, array $options = [])
28+
/**
29+
* @psalm-param array{capacity: int} $options
30+
*/
31+
public function __construct(string $sdkKey, array $options)
2932
{
3033
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
3134
$this->_eventSerializer = new EventSerializer($options);
32-
35+
3336
$this->_capacity = $options['capacity'];
3437
}
3538

src/LaunchDarkly/Impl/Integrations/FeatureRequesterBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getSegment(string $key): ?Segment
125125
/**
126126
* Gets all features
127127
*
128-
* @return array|null The decoded FeatureFlags, or null if missing
128+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
129129
*/
130130
public function getAllFeatures(): ?array
131131
{

src/LaunchDarkly/Impl/Integrations/FileDataFeatureRequester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getSegment(string $key): ?Segment
5555
/**
5656
* Gets all feature flags
5757
*
58-
* @return array|null The decoded FeatureFlags, or null if missing
58+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
5959
*/
6060
public function getAllFeatures(): ?array
6161
{

src/LaunchDarkly/Impl/Integrations/GuzzleEventPublisher.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function __construct(string $sdkKey, array $options = [])
4949
public function publish(string $payload): bool
5050
{
5151
$client = new Client(['base_uri' => $this->_eventsUri]);
52-
$response = null;
5352

5453
try {
5554
$options = $this->_requestOptions;

src/LaunchDarkly/Impl/Integrations/GuzzleFeatureRequester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getSegment(string $key): ?Segment
111111
/**
112112
* Gets all features from a likely cached store
113113
*
114-
* @return array|null The decoded FeatureFlags, or null if missing
114+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
115115
*/
116116
public function getAllFeatures(): ?array
117117
{

src/LaunchDarkly/Impl/Model/FeatureFlag.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ private function checkPrerequisites(LDUser $user, FeatureRequester $featureReque
183183
foreach ($this->_prerequisites as $prereq) {
184184
$prereqOk = true;
185185
try {
186-
$prereqEvalResult = null;
187186
$prereqFeatureFlag = $featureRequester->getFeature($prereq->getKey());
188187
if ($prereqFeatureFlag == null) {
189188
$prereqOk = false;
@@ -221,10 +220,9 @@ private function getOffValue(EvaluationReason $reason): EvaluationDetail
221220
}
222221
return $this->getVariation($this->_offVariation, $reason);
223222
}
224-
223+
225224
private function getValueForVariationOrRollout(VariationOrRollout $r, LDUser $user, EvaluationReason $reason): EvaluationDetail
226225
{
227-
$rollout = $r->getRollout();
228226
list($index, $inExperiment) = $r->variationIndexForUser($user, $this->_key, $this->_salt);
229227
if ($index === null) {
230228
return new EvaluationDetail(null, null, EvaluationReason::error(EvaluationReason::MALFORMED_FLAG_ERROR));

src/LaunchDarkly/Impl/Model/VariationOrRollout.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public static function bucketUser(
8686
?int $seed
8787
): float {
8888
$userValue = $user->getValueForEvaluation($attr);
89-
$idHash = null;
9089
if ($userValue != null) {
9190
if (is_int($userValue)) {
9291
$userValue = (string) $userValue;

src/LaunchDarkly/Impl/PreloadedFeatureRequester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getSegment(string $key): ?Segment
5454
/**
5555
* Gets all features from cached values
5656
*
57-
* @return array|null The decoded FeatureFlags, or null if missing
57+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
5858
*/
5959
public function getAllFeatures(): ?array
6060
{

src/LaunchDarkly/LDClient.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LDClient
4040
protected $_offline = false;
4141
/** @var bool */
4242
protected $_send_events = true;
43-
/** @var array|mixed */
43+
/** @var array */
4444
protected $_defaults = [];
4545
/** @var LoggerInterface */
4646
protected $_logger;
@@ -54,6 +54,8 @@ class LDClient
5454
/**
5555
* Creates a new client instance that connects to LaunchDarkly.
5656
*
57+
* @psalm-param array{capacity?: int, defaults?: array<string, mixed|null>} $options
58+
*
5759
* @param string $sdkKey The SDK key for your account
5860
* @param array $options Client configuration settings
5961
* - `base_uri`: Base URI of the LaunchDarkly service. Change this if you are connecting to a Relay Proxy instance instead of
@@ -220,7 +222,7 @@ private function variationDetailInternal(string $key, LDUser $user, $default, Ev
220222
{
221223
$default = $this->_get_default($key, $default);
222224

223-
$errorResult = function (string $errorKind) use ($key, $default): EvaluationDetail {
225+
$errorResult = function (string $errorKind) use ($default): EvaluationDetail {
224226
return new EvaluationDetail($default, null, EvaluationReason::error($errorKind));
225227
};
226228
$sendEvent = function (EvaluationDetail $detail, ?FeatureFlag $flag) use ($key, $user, $default, $eventFactory): void {
@@ -368,7 +370,7 @@ public function allFlagsState(LDUser $user, array $options = []): FeatureFlagsSt
368370
$clientOnly = isset($options['clientSideOnly']) && $options['clientSideOnly'];
369371
$withReasons = isset($options['withReasons']) && $options['withReasons'];
370372
$detailsOnlyIfTracked = isset($options['detailsOnlyForTrackedFlags']) && $options['detailsOnlyForTrackedFlags'];
371-
foreach ($flags as $key => $flag) {
373+
foreach ($flags as $flag) {
372374
if ($clientOnly && !$flag->isClientSide()) {
373375
continue;
374376
}

0 commit comments

Comments
 (0)