Skip to content

Commit db2d6a2

Browse files
committed
fix WARNING: array_map(): Argument #2 should be an array in vendor/launchdarkly/launchdarkly-php/src/LaunchDarkly/FeatureFlag.php on line 60 where FeatureFlag assumes prerequisites will always be an array. in an ld-relay test i see that prerequisites can be null so that must be handled here.
1 parent 241bca5 commit db2d6a2

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/LaunchDarkly/FeatureFlag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function getDecoder() {
5757
$v['key'],
5858
$v['version'],
5959
$v['on'],
60-
array_map(Prerequisite::getDecoder(), $v['prerequisites']),
60+
array_map(Prerequisite::getDecoder(), $v['prerequisites'] ?: []),
6161
$v['salt'],
6262
array_map(Target::getDecoder(), $v['targets']),
6363
array_map(Rule::getDecoder(), $v['rules']),

tests/FeatureFlagTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,52 @@ public function testDecode() {
140140
FeatureFlag::decode(\GuzzleHttp\json_decode(FeatureFlagTest::$json1, true));
141141
FeatureFlag::decode(\GuzzleHttp\json_decode(FeatureFlagTest::$json2, true));
142142
}
143+
144+
public function dataDecodeMulti()
145+
{
146+
return [
147+
'null-prerequisites' => [
148+
[
149+
'key' => 'sysops-test',
150+
'version' => 14,
151+
'on' => true,
152+
'prerequisites' => NULL,
153+
'salt' => 'c3lzb3BzLXRlc3Q=',
154+
'sel' => '8ed13de1bfb14507ba7e6dde01f3e035',
155+
'targets' => [
156+
[
157+
'values' => [],
158+
'variation' => 0,
159+
],
160+
[
161+
'values' => [],
162+
'variation' => 1,
163+
],
164+
],
165+
'rules' => [],
166+
'fallthrough' => [
167+
'variation' => 0,
168+
],
169+
'offVariation' => NULL,
170+
'variations' => [
171+
true,
172+
false,
173+
],
174+
'deleted' => false,
175+
]
176+
],
177+
];
178+
}
179+
180+
/**
181+
* @dataProvider dataDecodeMulti
182+
* @param array $feature
183+
*/
184+
public function testDecodeMulti(array $feature)
185+
{
186+
$featureFlag = FeatureFlag::decode($feature);
187+
188+
self::assertInstanceOf(FeatureFlag::class, $featureFlag);
189+
}
143190
}
144191

0 commit comments

Comments
 (0)