Skip to content

Commit 87e8227

Browse files
committed
Merge branch 'cleanup'
2 parents 203f9ea + 08ebf95 commit 87e8227

File tree

21 files changed

+416
-51
lines changed

21 files changed

+416
-51
lines changed

src/Toolkit/.gitignore

Whitespace-only changes.

src/Util/Cli/CliOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ private function filterValue($value, ?string $source = null, ?int $policy = null
924924
if ($invalid) {
925925
// "invalid --field values 'title','name' (expected one of: first,last)"
926926
$message = Inflect::format(
927+
$invalid,
927928
'invalid %s {{#:value}} %s%s%s',
928-
count($invalid),
929929
$this->DisplayName,
930930
"'" . implode("','", $invalid) . "'",
931931
$source !== null ? " in $source" : '',

src/Util/Concern/TCollection.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,58 @@ public function filter(callable $callback, int $mode = ICollection::CALLBACK_USE
119119
return $this->maybeReplaceItems($items, true);
120120
}
121121

122+
/**
123+
* @param TKey[] $keys
124+
* @return static A copy of the collection with items that have keys in
125+
* `$keys`.
126+
*/
127+
public function only(array $keys)
128+
{
129+
return $this->maybeReplaceItems(
130+
array_intersect_key($this->Items, array_flip($keys)),
131+
true
132+
);
133+
}
134+
135+
/**
136+
* @param array<TKey,true> $index
137+
* @return static A copy of the collection with items that have keys in
138+
* `$index`.
139+
*/
140+
public function onlyIn(array $index)
141+
{
142+
return $this->maybeReplaceItems(
143+
array_intersect_key($this->Items, $index),
144+
true
145+
);
146+
}
147+
148+
/**
149+
* @param TKey[] $keys
150+
* @return static A copy of the collection with items that have keys not in
151+
* `$keys`.
152+
*/
153+
public function except(array $keys)
154+
{
155+
return $this->maybeReplaceItems(
156+
array_diff_key($this->Items, array_flip($keys)),
157+
true
158+
);
159+
}
160+
161+
/**
162+
* @param array<TKey,true> $index
163+
* @return static A copy of the collection with items that have keys not in
164+
* `$index`.
165+
*/
166+
public function exceptIn(array $index)
167+
{
168+
return $this->maybeReplaceItems(
169+
array_diff_key($this->Items, $index),
170+
true
171+
);
172+
}
173+
122174
/**
123175
* @return static A copy of the collection with items starting from
124176
* `$offset`.

src/Util/Console/ConsoleWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ public function summary(
531531
return $this->write(Level::INFO, "$msg1 $successText", null, MessageType::SUCCESS);
532532
}
533533

534-
$msg2 = 'with ' . Inflect::format('{{#}} {{#:error}}', $this->State->Errors);
534+
$msg2 = 'with ' . Inflect::format($this->State->Errors, '{{#}} {{#:error}}');
535535
if ($this->State->Warnings) {
536-
$msg2 .= ' and ' . Inflect::format('{{#}} {{#:warning}}', $this->State->Warnings);
536+
$msg2 .= ' and ' . Inflect::format($this->State->Warnings, '{{#}} {{#:warning}}');
537537
}
538538

539539
return $this->write(

src/Util/Container/Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ private static function doReportMetrics(
645645

646646
$lines = [];
647647
$lines[] = Inflect::format(
648-
"Metrics: **{{#}}** {{#:event}} recorded by %s in group '**%s**':",
649648
$totalValue,
650-
Inflect::format('**{{#}}** {{#:counter}}', $count),
649+
"Metrics: **{{#}}** {{#:event}} recorded by %s in group '**%s**':",
650+
Inflect::format($count, '**{{#}}** {{#:counter}}'),
651651
$group,
652652
);
653653

@@ -688,8 +688,8 @@ private static function doReportMetrics(
688688

689689
$lines = [];
690690
$lines[] = Inflect::format(
691-
"Metrics: **%.3fms** recorded by **{{#}}** {{#:timer}} in group '**%s**':",
692691
$count,
692+
"Metrics: **%.3fms** recorded by **{{#}}** {{#:timer}} in group '**%s**':",
693693
$totalTime,
694694
$group,
695695
);

src/Util/Contract/ICollection.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,38 @@ public function filter(callable $callback, int $mode = ICollection::CALLBACK_USE
113113
*/
114114
public function find(callable $callback, int $mode = ICollection::CALLBACK_USE_VALUE);
115115

116+
/**
117+
* Reduce the collection to items with keys in an array
118+
*
119+
* @param TKey[] $keys
120+
* @return static
121+
*/
122+
public function only(array $keys);
123+
124+
/**
125+
* Reduce the collection to items with keys in an index
126+
*
127+
* @param array<TKey,true> $index
128+
* @return static
129+
*/
130+
public function onlyIn(array $index);
131+
132+
/**
133+
* Reduce the collection to items with keys not in an array
134+
*
135+
* @param TKey[] $keys
136+
* @return static
137+
*/
138+
public function except(array $keys);
139+
140+
/**
141+
* Reduce the collection to items with keys not in an index
142+
*
143+
* @param array<TKey,true> $index
144+
* @return static
145+
*/
146+
public function exceptIn(array $index);
147+
116148
/**
117149
* Extract a slice of the collection
118150
*

src/Util/Curler/Curler.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Lkrms\Concern\HasBuilder;
66
use Lkrms\Concern\Immutable;
77
use Lkrms\Contract\Buildable;
8-
use Lkrms\Contract\ICollection;
98
use Lkrms\Curler\Catalog\CurlerProperty;
109
use Lkrms\Curler\Contract\ICurlerPager;
1110
use Lkrms\Curler\Exception\CurlerCurlErrorException;
@@ -506,9 +505,7 @@ public function __construct(
506505
$this->AlwaysPaginate = $alwaysPaginate;
507506
$this->ObjectAsArray = $objectAsArray;
508507

509-
/** @var array<string,true> */
510-
$index = Arr::toIndex(Arr::lower(HttpHeaderGroup::SENSITIVE));
511-
$this->SensitiveHeaderIndex = $index;
508+
$this->SensitiveHeaderIndex = Arr::toIndex(Arr::lower(HttpHeaderGroup::SENSITIVE));
512509
}
513510

514511
/**
@@ -601,6 +598,14 @@ public function with(string $property, $value)
601598
return $this->withPropertyValue($property, $value);
602599
}
603600

601+
/**
602+
* Get request headers that are not considered sensitive
603+
*/
604+
public function getPublicHeaders(): HttpHeadersInterface
605+
{
606+
return $this->Headers->exceptIn($this->SensitiveHeaderIndex);
607+
}
608+
604609
/**
605610
* @return $this
606611
*/
@@ -1058,10 +1063,7 @@ private function getCacheKey(): ?string
10581063

10591064
$key = $this->ResponseCacheKeyCallback
10601065
? ($this->ResponseCacheKeyCallback)($this)
1061-
: $this->Headers->filter(
1062-
fn(string $key) => !($this->SensitiveHeaderIndex[$key] ?? false),
1063-
ICollection::CALLBACK_USE_KEY
1064-
)->getLines('%s:%s');
1066+
: $this->getPublicHeaders()->getLines('%s:%s');
10651067
if ($this->Method === HttpRequestMethod::POST) {
10661068
$key[] = $this->Body;
10671069
}

src/Util/Curler/CurlerBuilder.php

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Util/Http/HttpHeaders.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,50 @@ public function filter(callable $callback, int $mode = ICollection::CALLBACK_USE
384384
return $changed ? $this->replaceHeaders(null, $index) : $this;
385385
}
386386

387+
/**
388+
* @inheritDoc
389+
*/
390+
public function only(array $keys)
391+
{
392+
return $this->onlyIn(Arr::toIndex($keys));
393+
}
394+
395+
/**
396+
* @inheritDoc
397+
*/
398+
public function onlyIn(array $index)
399+
{
400+
return $this->maybeReplaceHeaders(
401+
null,
402+
array_intersect_key(
403+
$this->Index,
404+
array_change_key_case($index, \CASE_LOWER)
405+
)
406+
);
407+
}
408+
409+
/**
410+
* @inheritDoc
411+
*/
412+
public function except(array $keys)
413+
{
414+
return $this->exceptIn(Arr::toIndex($keys));
415+
}
416+
417+
/**
418+
* @inheritDoc
419+
*/
420+
public function exceptIn(array $index)
421+
{
422+
return $this->maybeReplaceHeaders(
423+
null,
424+
array_diff_key(
425+
$this->Index,
426+
array_change_key_case($index, \CASE_LOWER)
427+
)
428+
);
429+
}
430+
387431
/**
388432
* @inheritDoc
389433
*/

src/Util/Sync/Command/CheckSyncProviderHeartbeat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ function (string $providerClass) {
140140
$count = count($providers);
141141

142142
Console::info(Inflect::format(
143-
'Sending heartbeat request to {{#}} {{#:provider}}',
144143
$count,
144+
'Sending heartbeat request to {{#}} {{#:provider}}',
145145
));
146146

147147
$this->Store->checkHeartbeats(
@@ -151,8 +151,8 @@ function (string $providerClass) {
151151
);
152152

153153
Console::summary(Inflect::format(
154-
'{{#}} {{#:provider}} checked',
155154
$count,
155+
'{{#}} {{#:provider}} checked',
156156
));
157157
}
158158
}

0 commit comments

Comments
 (0)