Skip to content

Commit 8393a31

Browse files
committed
Use array_map for smaller complexity
1 parent 8e58d12 commit 8393a31

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/PHPEncoder.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ class PHPEncoder
4444
public function __construct(array $options = [], array $encoders = null)
4545
{
4646
$this->options = self::$defaultOptions;
47-
$this->encoders = [];
4847

4948
if ($encoders === null) {
50-
$encoders = [
49+
$this->encoders = [
5150
new Encoder\NullEncoder(),
5251
new Encoder\BooleanEncoder(),
5352
new Encoder\IntegerEncoder(),
@@ -57,14 +56,12 @@ public function __construct(array $options = [], array $encoders = null)
5756
new Encoder\GMPEncoder(),
5857
new Encoder\ObjectEncoder(),
5958
];
59+
} else {
60+
$this->encoders = [];
61+
array_map([$this, 'addEncoder'], $encoders);
6062
}
6163

62-
foreach ($encoders as $encoder) {
63-
$this->addEncoder($encoder);
64-
}
65-
foreach ($options as $option => $value) {
66-
$this->setOption($option, $value);
67-
}
64+
array_map([$this, 'setOption'], array_keys($options), $options);
6865
}
6966

7067
/**

0 commit comments

Comments
 (0)