Skip to content

Commit 03e64d1

Browse files
authored
Add cs-check to build process (#83)
1 parent bf54f4b commit 03e64d1

Some content is hidden

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

58 files changed

+813
-739
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
- run:
7373
name: psalm linting
7474
command: ./vendor/bin/psalm --no-cache
75+
- run:
76+
name: php-cs-fixer check
77+
command: composer cs-check
7578
- run: mkdir -p ~/phpunit
7679
- run:
7780
name: run tests with highest compatible dependency versions

.php-cs-fixer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()->in(__DIR__);
4+
5+
$config = new PhpCsFixer\Config();
6+
return $config
7+
->setFinder($finder)
8+
->setUsingCache(true)
9+
->setRules([
10+
'@PSR2' => true,
11+
'blank_line_after_opening_tag' => true,
12+
'ordered_imports' => true,
13+
'no_unused_imports' => true,
14+
'array_syntax' => ['syntax' => 'short'],
15+
]);

.php_cs

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

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"sort-packages": true
4545
},
4646
"scripts": {
47-
"cs": "vendor/bin/php-cs-fixer fix --diff --verbose"
47+
"cs-check": "vendor/bin/php-cs-fixer fix --diff --dry-run --verbose",
48+
"cs-fix": "vendor/bin/php-cs-fixer fix --diff --verbose"
4849
}
4950
}

src/LaunchDarkly/EvaluationDetail.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace LaunchDarkly;
44

5-
use \LaunchDarkly\EvaluationReason;
6-
75
/**
86
* An object that combines the result of a flag evaluation with an explanation of how it was calculated.
97
*

src/LaunchDarkly/EvaluationReason.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ private function __construct(
166166
?int $ruleIndex = null,
167167
?string $ruleId = null,
168168
?string $prerequisiteKey = null,
169-
bool $inExperiment = false)
170-
{
169+
bool $inExperiment = false
170+
) {
171171
$this->_kind = $kind;
172172
$this->_errorKind = $errorKind;
173173
$this->_ruleIndex = $ruleIndex;
@@ -258,7 +258,7 @@ public function __toString(): string
258258
*/
259259
public function jsonSerialize(): array
260260
{
261-
$ret = array('kind' => $this->_kind);
261+
$ret = ['kind' => $this->_kind];
262262
if ($this->_errorKind !== null) {
263263
$ret['errorKind'] = $this->_errorKind;
264264
}

src/LaunchDarkly/EventPublisher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace LaunchDarkly;
34

45
/**

src/LaunchDarkly/FeatureFlagsState.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2+
23
namespace LaunchDarkly;
34

45
use LaunchDarkly\Impl\Model\FeatureFlag;
5-
use LaunchDarkly\LDClient;
66

77
/**
88
* A snapshot of the state of all feature flags with regard to a specific user.
@@ -30,25 +30,25 @@ class FeatureFlagsState implements \JsonSerializable
3030
public function __construct(bool $valid)
3131
{
3232
$this->_valid = $valid;
33-
$this->_flagValues = array();
34-
$this->_flagMetadata = array();
33+
$this->_flagValues = [];
34+
$this->_flagMetadata = [];
3535
}
3636

3737
/**
3838
* Used internally to build the state map.
3939
*
4040
* @ignore
41-
*
41+
*
4242
* @return void
4343
*/
4444
public function addFlag(
4545
FeatureFlag $flag,
4646
EvaluationDetail $detail,
4747
bool $withReason = false,
48-
bool $detailsOnlyIfTracked = false): void
49-
{
48+
bool $detailsOnlyIfTracked = false
49+
): void {
5050
$this->_flagValues[$flag->getKey()] = $detail->getValue();
51-
$meta = array();
51+
$meta = [];
5252
if (!$detailsOnlyIfTracked || $flag->isTrackEvents() || $flag->getDebugEventsUntilDate()) {
5353
$meta['version'] = $flag->getVersion();
5454
if ($withReason) {
@@ -106,9 +106,9 @@ public function getFlagReason(string $key): ?EvaluationReason
106106

107107
/**
108108
* Returns an associative array of flag keys to flag values.
109-
*
109+
*
110110
* If a flag would have evaluated to the default value, its value will be null.
111-
*
111+
*
112112
* Do not use this method if you are passing data to the front end to "bootstrap" the JavaScript client.
113113
* Instead, use jsonSerialize().
114114
* @return array an associative array of flag keys to JSON values
@@ -121,17 +121,17 @@ public function toValuesMap(): array
121121
/**
122122
* Returns a JSON representation of the entire state map (as an associative array), in the format used
123123
* by the LaunchDarkly JavaScript SDK.
124-
*
124+
*
125125
* Use this method if you are passing data to the front end in order to "bootstrap" the JavaScript client.
126-
*
126+
*
127127
* Note that calling json_encode() on a FeatureFlagsState object will automatically use the
128128
* jsonSerialize() method.
129129
* @return array an associative array suitable for passing as a JSON object
130130
*/
131131
public function jsonSerialize(): array
132132
{
133133
$ret = array_replace([], $this->_flagValues);
134-
$metaMap = array();
134+
$metaMap = [];
135135
foreach ($this->_flagMetadata as $key => $meta) {
136136
$meta = array_replace([], $meta);
137137
if (isset($meta['reason'])) {

src/LaunchDarkly/FeatureRequester.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace LaunchDarkly;
34

45
use LaunchDarkly\Impl\Model\FeatureFlag;

src/LaunchDarkly/Impl/Events/EventFactory.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
namespace LaunchDarkly\Impl\Events;
34

45
use LaunchDarkly\EvaluationDetail;
56
use LaunchDarkly\EvaluationReason;
6-
use LaunchDarkly\LDUser;
7-
use LaunchDarkly\Impl\Util;
87
use LaunchDarkly\Impl\Model\FeatureFlag;
8+
use LaunchDarkly\Impl\Util;
9+
use LaunchDarkly\LDUser;
910

1011
/**
1112
* @ignore
@@ -34,10 +35,10 @@ public function newEvalEvent(
3435
LDUser $user,
3536
EvaluationDetail $detail,
3637
$default,
37-
$prereqOfFlag = null): array
38-
{
38+
$prereqOfFlag = null
39+
): array {
3940
$addExperimentData = static::isExperiment($flag, $detail->getReason());
40-
$e = array(
41+
$e = [
4142
'kind' => 'feature',
4243
'creationDate' => Util::currentTimeUnixMillis(),
4344
'key' => $flag->getKey(),
@@ -46,7 +47,7 @@ public function newEvalEvent(
4647
'value' => $detail->getValue(),
4748
'default' => $default,
4849
'version' => $flag->getVersion()
49-
);
50+
];
5051
// the following properties are handled separately so we don't waste bandwidth on unused keys
5152
if ($addExperimentData || $flag->isTrackEvents()) {
5253
$e['trackEvents'] = true;
@@ -71,15 +72,15 @@ public function newEvalEvent(
7172
*/
7273
public function newDefaultEvent(FeatureFlag $flag, LDUser $user, EvaluationDetail $detail): array
7374
{
74-
$e = array(
75+
$e = [
7576
'kind' => 'feature',
7677
'creationDate' => Util::currentTimeUnixMillis(),
7778
'key' => $flag->getKey(),
7879
'user' => $user,
7980
'value' => $detail->getValue(),
8081
'default' => $detail->getValue(),
8182
'version' => $flag->getVersion()
82-
);
83+
];
8384
// the following properties are handled separately so we don't waste bandwidth on unused keys
8485
if ($flag->isTrackEvents()) {
8586
$e['trackEvents'] = true;
@@ -101,14 +102,14 @@ public function newDefaultEvent(FeatureFlag $flag, LDUser $user, EvaluationDetai
101102
*/
102103
public function newUnknownFlagEvent(string $key, LDUser $user, EvaluationDetail $detail): array
103104
{
104-
$e = array(
105+
$e = [
105106
'kind' => 'feature',
106107
'creationDate' => Util::currentTimeUnixMillis(),
107108
'key' => $key,
108109
'user' => $user,
109110
'value' => $detail->getValue(),
110111
'default' => $detail->getValue()
111-
);
112+
];
112113
// the following properties are handled separately so we don't waste bandwidth on unused keys
113114
if ($this->_withReasons && $detail->getReason()) {
114115
$e['reason'] = $detail->getReason()->jsonSerialize();
@@ -124,12 +125,12 @@ public function newUnknownFlagEvent(string $key, LDUser $user, EvaluationDetail
124125
*/
125126
public function newIdentifyEvent(LDUser $user): array
126127
{
127-
return array(
128+
return [
128129
'kind' => 'identify',
129130
'creationDate' => Util::currentTimeUnixMillis(),
130131
'key' => strval($user->getKey()),
131132
'user' => $user
132-
);
133+
];
133134
}
134135

135136
/**
@@ -142,12 +143,12 @@ public function newIdentifyEvent(LDUser $user): array
142143
*/
143144
public function newCustomEvent(string $eventName, LDUser $user, $data, $metricValue): array
144145
{
145-
$e = array(
146+
$e = [
146147
'kind' => 'custom',
147148
'creationDate' => Util::currentTimeUnixMillis(),
148149
'key' => $eventName,
149150
'user' => $user
150-
);
151+
];
151152
if (isset($data)) {
152153
$e['data'] = $data;
153154
}
@@ -165,14 +166,14 @@ public function newCustomEvent(string $eventName, LDUser $user, $data, $metricVa
165166
*/
166167
public function newAliasEvent(LDUser $user, LDUser $previousUser): array
167168
{
168-
$e = array(
169+
$e = [
169170
'kind' => 'alias',
170171
'key' => strval($user->getKey()),
171172
'contextKind' => static::contextKind($user),
172173
'previousKey' => strval($previousUser->getKey()),
173174
'previousContextKind' => static::contextKind($previousUser),
174175
'creationDate' => Util::currentTimeUnixMillis()
175-
);
176+
];
176177

177178
return $e;
178179
}

0 commit comments

Comments
 (0)