Skip to content

Commit 7c7bfd1

Browse files
committed
style: apply code style fixes for consistency and readability
- Updated `ConditionalTransformer`: - Updated `TemplateTransformer`
1 parent 6c4bbd7 commit 7c7bfd1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Processor/Composite/ConditionalTransformer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
class ConditionalTransformer extends AbstractTransformerProcessor implements ConfigurableProcessor
1111
{
1212
private ?AbstractTransformerProcessor $transformer = null;
13-
private ?callable $condition = null;
13+
14+
/** @var callable|null */
15+
private mixed $condition = null;
16+
1417
private mixed $defaultValue = null;
1518
private bool $useDefaultOnError = true;
1619

@@ -41,12 +44,14 @@ public function process(mixed $input): mixed
4144

4245
if (!$this->transformer->isValid() && $this->useDefaultOnError) {
4346
$this->setInvalid($this->transformer->getErrorKey());
47+
4448
return $this->defaultValue ?? $input;
4549
}
4650

4751
return $result;
4852
} catch (\Exception $e) {
4953
$this->setInvalid('transformationError');
54+
5055
return $this->defaultValue ?? $input;
5156
}
5257
}
@@ -59,4 +64,4 @@ private function shouldTransform(mixed $input): bool
5964
return false;
6065
}
6166
}
62-
}
67+
}

src/Processor/String/TemplateTransformer.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class TemplateTransformer extends AbstractTransformerProcessor implements Config
1515
private string $template = '';
1616
private string $openTag = '{{';
1717
private string $closeTag = '}}';
18-
private ?callable $missingValueHandler = null;
18+
19+
/** @var callable|null */
20+
private mixed $missingValueHandler = null;
21+
1922
private bool $removeUnmatchedTags = false;
2023

2124
public function configure(array $options): void
@@ -31,11 +34,13 @@ public function process(mixed $input): string
3134
{
3235
if (!is_array($input)) {
3336
$this->setInvalid('notArray');
37+
3438
return $this->template;
3539
}
3640

3741
if (empty($this->template)) {
3842
$this->setInvalid('noTemplate');
43+
3944
return '';
4045
}
4146

@@ -45,19 +50,19 @@ public function process(mixed $input): string
4550
private function replacePlaceholders(array $data): string
4651
{
4752
$pattern = '/' . preg_quote($this->openTag, '/') . '\s*(.+?)\s*' . preg_quote($this->closeTag, '/') . '/';
48-
49-
return preg_replace_callback($pattern, function($matches) use ($data) {
53+
54+
return preg_replace_callback($pattern, function ($matches) use ($data) {
5055
$key = trim($matches[1]);
51-
56+
5257
if (isset($data[$key])) {
5358
return $data[$key];
5459
}
55-
56-
if ($this->missingValueHandler !== null) {
60+
61+
if (null !== $this->missingValueHandler) {
5762
return call_user_func($this->missingValueHandler, $key);
5863
}
59-
64+
6065
return $this->removeUnmatchedTags ? '' : $matches[0];
6166
}, $this->template);
6267
}
63-
}
68+
}

0 commit comments

Comments
 (0)