Skip to content

Commit 8fe8574

Browse files
[FSSDK-9630] Fix: Code examples (#281)
* Fix: Add ReturnTypeWillChange attribute * Enhancement: Keep packages sorted in composer.json * Fix: Wrap arguments in code examples * Fix: Code examples --------- Co-authored-by: Andreas Möller <[email protected]>
1 parent 4963820 commit 8fe8574

12 files changed

+50
-4
lines changed

Diff for: README.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,55 @@ php composer.phar require optimizely/optimizely-sdk
3737
Create the Optimizely client, for example:
3838

3939
```php
40+
<?php
41+
42+
use Optimizely\Optimizely;
43+
4044
$optimizely = new Optimizely(<<DATAFILE>>);
4145
```
4246

4347
Or you may also use OptimizelyFactory method to create an optimizely client using your SDK key, an optional fallback datafile and an optional datafile access token. Using this method internally creates an HTTPProjectConfigManager. See [HTTPProjectConfigManager](#use-httpprojectconfigmanager) for further detail.
4448

4549
```php
46-
$optimizelyClient = OptimizelyFactory::createDefaultInstance("your-sdk-key", <<DATAFILE>>, <<DATAFILE_AUTH_TOKEN>>);
50+
<?php
51+
52+
use Optimizely\OptimizelyFactory;
53+
54+
$optimizelyClient = OptimizelyFactory::createDefaultInstance(
55+
"your-sdk-key",
56+
<<DATAFILE>>,
57+
<<DATAFILE_AUTH_TOKEN>>
58+
);
4759
```
4860
To access your HTTPProjectConfigManager:
4961

5062
```php
63+
<?php
64+
65+
use Optimizely\Optimizely;
66+
67+
/** @var Optimizely $optimizelyClient */
5168
$configManager = $optimizelyClient->configManager;
5269
```
5370

5471
Or you can also provide an implementation of the [`ProjectConfigManagerInterface`](https://github.com/optimizely/php-sdk/blob/master/src/Optimizely/ProjectConfigManager/ProjectConfigManagerInterface.php) in the constructor:
5572

5673
```php
74+
<?php
75+
76+
use Optimizely\Optimizely;
77+
use Optimizely\ProjectConfigManager\HTTPProjectConfigManager;
78+
5779
$configManager = new HTTPProjectConfigManager(<<SDK_KEY>>);
58-
$optimizely = new Optimizely(<<DATAFILE>>, null, null, null, false, null, $configManager);
80+
$optimizely = new Optimizely(
81+
<<DATAFILE>>,
82+
null,
83+
null,
84+
null,
85+
false,
86+
null,
87+
$configManager
88+
);
5989
```
6090

6191
### ProjectConfigManagerInterface
@@ -74,6 +104,10 @@ Calling `fetch` will update the internal ProjectConfig instance that will be ret
74104
### Use HTTPProjectConfigManager
75105

76106
```php
107+
<?php
108+
109+
use Optimizely\ProjectConfigManager\HTTPProjectConfigManager;
110+
77111
$configManager = new HTTPProjectConfigManager(<<SDK_KEY>>);
78112
```
79113

Diff for: composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"require": {
1818
"php": ">=8.1",
19+
"guzzlehttp/guzzle": ">=6.2",
1920
"justinrainbow/json-schema": "^1.6 || ^2.0 || ^4.0 || ^5.0",
2021
"lastguest/murmurhash": "^1.3.0",
21-
"guzzlehttp/guzzle": ">=6.2",
2222
"monolog/monolog": ">=1.21"
2323
},
2424
"require-dev": {
@@ -31,5 +31,8 @@
3131
"psr-4": {
3232
"Optimizely\\": "src/Optimizely"
3333
}
34+
},
35+
"config": {
36+
"sort-packages": true
3437
}
3538
}

Diff for: composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Optimizely/Decide/OptimizelyDecision.php

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function getReasons()
8181
return $this->reasons;
8282
}
8383

84+
#[\ReturnTypeWillChange]
8485
public function jsonSerialize()
8586
{
8687
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyAttribute.php

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function getKey()
5353
/**
5454
* @return string JSON representation of the object.
5555
*/
56+
#[\ReturnTypeWillChange]
5657
public function jsonSerialize()
5758
{
5859
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyAudience.php

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function getConditions()
6868
/**
6969
* @return string JSON representation of the object.
7070
*/
71+
#[\ReturnTypeWillChange]
7172
public function jsonSerialize()
7273
{
7374
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyConfig.php

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public function getEvents()
166166
/**
167167
* @return string JSON representation of the object.
168168
*/
169+
#[\ReturnTypeWillChange]
169170
public function jsonSerialize()
170171
{
171172
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyEvent.php

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function getExperimentIds()
6868
/**
6969
* @return string JSON representation of the object.
7070
*/
71+
#[\ReturnTypeWillChange]
7172
public function jsonSerialize()
7273
{
7374
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyExperiment.php

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function getVariationsMap()
8383
/**
8484
* @return string JSON representation of the object.
8585
*/
86+
#[\ReturnTypeWillChange]
8687
public function jsonSerialize()
8788
{
8889
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyFeature.php

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function getVariablesMap()
118118
/**
119119
* @return string JSON representation of the object.
120120
*/
121+
#[\ReturnTypeWillChange]
121122
public function jsonSerialize()
122123
{
123124
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyVariable.php

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function getValue()
8282
/**
8383
* @return string JSON representation of the object.
8484
*/
85+
#[\ReturnTypeWillChange]
8586
public function jsonSerialize()
8687
{
8788
return get_object_vars($this);

Diff for: src/Optimizely/OptimizelyConfig/OptimizelyVariation.php

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function getVariablesMap()
8484
* @return string JSON representation of the object.
8585
* Unsets featureEnabled property for variations of ab experiments.
8686
*/
87+
#[\ReturnTypeWillChange]
8788
public function jsonSerialize()
8889
{
8990
$props = get_object_vars($this);

0 commit comments

Comments
 (0)