Skip to content

Commit 88ca898

Browse files
authored
Merge uc2 work into main (#140)
2 parents 56a2e22 + f269669 commit 88ca898

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2457
-1061
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ workflows:
99
- test-on-linux:
1010
matrix:
1111
parameters:
12-
php-version: ["8.0", "8.1"]
12+
php-version: ["8.1", "8.2"]
1313
composer-dependencies: ["lowest", "highest"]
1414
- test-on-windows
1515

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## Supported PHP versions
1414

15-
This version of the LaunchDarkly SDK is compatible with PHP 8.0 and higher.
15+
This version of the LaunchDarkly SDK is compatible with PHP 8.1 and higher.
1616

1717
## Getting started
1818

baseline.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=8.0",
17+
"php": ">=8.1",
1818
"monolog/monolog": "^2.0|^3.0",
1919
"psr/log": "^1.0|^2.0|^3.0"
2020
},
2121
"require-dev": {
22-
"friendsofphp/php-cs-fixer": "^3.12.0",
22+
"friendsofphp/php-cs-fixer": "^3.15.0",
2323
"guzzlehttp/guzzle": "^7",
2424
"kevinrob/guzzle-cache-middleware": "^4.0",
2525
"phpunit/php-code-coverage": "^9",
2626
"phpunit/phpunit": "^9",
27-
"vimeo/psalm": "^4.9"
27+
"vimeo/psalm": "^5.15"
2828
},
2929
"suggest": {
3030
"guzzlehttp/guzzle": "(^6.3 | ^7) Required when using GuzzleEventPublisher or the default FeatureRequester",

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" beStrictAboutResourceUsageDuringSmallTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true" defaultTimeLimit="10">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" beStrictAboutResourceUsageDuringSmallTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true" defaultTimeLimit="10">
33

44
<logging>
55
<junit outputFile="build/phpunit/junit.xml"/>

psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8-
errorBaseline="baseline.xml"
98
>
109
<projectFiles>
1110
<directory name="src" />

src/LaunchDarkly/EvaluationReason.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class EvaluationReason implements \JsonSerializable
8383
*/
8484
const EXCEPTION_ERROR = 'EXCEPTION';
8585

86+
/**
87+
* A possible value for getErrorKind(): indicates the value of the
88+
* evaluation did not match the PHP type expected.
89+
*/
90+
91+
const WRONG_TYPE_ERROR = 'WRONG_TYPE';
92+
8693
private string $_kind;
8794
private ?string $_errorKind;
8895
private ?int $_ruleIndex;

src/LaunchDarkly/Impl/Events/EventFactory.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ public function newEvalEvent(
5050
'default' => $default,
5151
'version' => $flag->getVersion()
5252
];
53+
5354
// the following properties are handled separately so we don't waste bandwidth on unused keys
55+
if ($flag->getExcludeFromSummaries()) {
56+
$e['excludeFromSummaries'] = true;
57+
}
58+
if ($flag->getSamplingRatio() !== 1) {
59+
$e['samplingRatio'] = $flag->getSamplingRatio();
60+
}
5461
if ($forceReasonTracking || $flag->isTrackEvents()) {
5562
$e['trackEvents'] = true;
5663
}
@@ -66,33 +73,6 @@ public function newEvalEvent(
6673
return $e;
6774
}
6875

69-
/**
70-
* @return mixed[]
71-
*/
72-
public function newDefaultEvent(FeatureFlag $flag, LDContext $context, EvaluationDetail $detail): array
73-
{
74-
$e = [
75-
'kind' => 'feature',
76-
'creationDate' => Util::currentTimeUnixMillis(),
77-
'key' => $flag->getKey(),
78-
'context' => $context,
79-
'value' => $detail->getValue(),
80-
'default' => $detail->getValue(),
81-
'version' => $flag->getVersion()
82-
];
83-
// the following properties are handled separately so we don't waste bandwidth on unused keys
84-
if ($flag->isTrackEvents()) {
85-
$e['trackEvents'] = true;
86-
}
87-
if ($flag->getDebugEventsUntilDate()) {
88-
$e['debugEventsUntilDate'] = $flag->getDebugEventsUntilDate();
89-
}
90-
if ($this->_withReasons) {
91-
$e['reason'] = $detail->getReason()->jsonSerialize();
92-
}
93-
return $e;
94-
}
95-
9676
/**
9777
* @return mixed[]
9878
*/
@@ -124,7 +104,7 @@ public function newIdentifyEvent(LDContext $context): array
124104
'context' => $context
125105
];
126106
}
127-
107+
128108
/**
129109
* @return mixed[]
130110
*/

src/LaunchDarkly/Impl/Events/EventProcessor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace LaunchDarkly\Impl\Events;
66

7+
use LaunchDarkly\Impl\Util;
78
use LaunchDarkly\Integrations\Curl;
89
use LaunchDarkly\Subsystems\EventPublisher;
910

@@ -21,7 +22,7 @@ class EventProcessor
2122
private int $_capacity;
2223

2324
/**
24-
* @psalm-param array{capacity: int} $options
25+
* @param array<string, mixed> $options
2526
*/
2627
public function __construct(string $sdkKey, array $options)
2728
{
@@ -50,6 +51,13 @@ public function enqueue(array $event): bool
5051
return false;
5152
}
5253

54+
if (isset($event['samplingRatio'])) {
55+
$samplingRatio = $event['samplingRatio'];
56+
if (is_int($samplingRatio) && !Util::sample($samplingRatio)) {
57+
return false;
58+
}
59+
}
60+
5361
$this->_queue[] = $event;
5462

5563
return true;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LaunchDarkly\Impl\Migrations;
6+
7+
use Closure;
8+
use Exception;
9+
use LaunchDarkly\Impl\Util;
10+
use LaunchDarkly\Migrations\OperationResult;
11+
use LaunchDarkly\Migrations\OpTracker;
12+
use LaunchDarkly\Migrations\Origin;
13+
use LaunchDarkly\Types\Result;
14+
15+
/**
16+
* Utility class for executing migration operations while also tracking our
17+
* built-in migration measurements.
18+
*/
19+
class Executor
20+
{
21+
/**
22+
* @param Closure(mixed): Result $fn
23+
*/
24+
public function __construct(
25+
public readonly Origin $origin,
26+
private Closure $fn,
27+
private OpTracker $tracker,
28+
private bool $trackLatency,
29+
private bool $trackErrors,
30+
private mixed $payload,
31+
) {
32+
}
33+
34+
public function run(): OperationResult
35+
{
36+
$start = Util::currentTimeUnixMillis();
37+
38+
try {
39+
$result = ($this->fn)($this->payload);
40+
} catch (Exception $e) {
41+
$result = Result::error($e->getMessage(), $e);
42+
}
43+
44+
if ($this->trackLatency) {
45+
$this->tracker->latency($this->origin, Util::currentTimeUnixMillis() - $start);
46+
}
47+
48+
if ($this->trackErrors && !$result->isSuccessful()) {
49+
$this->tracker->error($this->origin);
50+
}
51+
52+
$this->tracker->invoked($this->origin);
53+
54+
return new OperationResult($this->origin, $result);
55+
}
56+
}

0 commit comments

Comments
 (0)