Skip to content

Commit 5c5aeef

Browse files
committed
style(cnpj-fmt): improve source code quality
1 parent 7c9968b commit 5c5aeef

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/CnpjFormatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,17 @@ private function toStringInput(mixed $cnpjInput): string
247247
}
248248

249249
if (is_array($cnpjInput)) {
250+
$joined = '';
251+
250252
foreach ($cnpjInput as $item) {
251253
if (!is_string($item)) {
252254
throw new CnpjFormatterInputTypeError($cnpjInput, 'string or string[]');
253255
}
256+
257+
$joined .= $item;
254258
}
255259

256-
return implode('', $cnpjInput);
260+
return $joined;
257261
}
258262

259263
throw new CnpjFormatterInputTypeError($cnpjInput, 'string or string[]');

src/CnpjFormatterOptions.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ public function __construct(
249249
public function __get(string $name): mixed
250250
{
251251
return match ($name) {
252-
'hidden' => $this->getHidden(),
253-
'hiddenKey' => $this->getHiddenKey(),
252+
'hidden' => $this->getHidden(),
253+
'hiddenKey' => $this->getHiddenKey(),
254254
'hiddenStart' => $this->getHiddenStart(),
255-
'hiddenEnd' => $this->getHiddenEnd(),
256-
'dotKey' => $this->getDotKey(),
257-
'slashKey' => $this->getSlashKey(),
258-
'dashKey' => $this->getDashKey(),
259-
'escape' => $this->getEscape(),
260-
'encode' => $this->getEncode(),
261-
'onFail' => $this->getOnFail(),
262-
default => throw new InvalidArgumentException("Unknown property: {$name}"),
255+
'hiddenEnd' => $this->getHiddenEnd(),
256+
'dotKey' => $this->getDotKey(),
257+
'slashKey' => $this->getSlashKey(),
258+
'dashKey' => $this->getDashKey(),
259+
'escape' => $this->getEscape(),
260+
'encode' => $this->getEncode(),
261+
'onFail' => $this->getOnFail(),
262+
default => throw new InvalidArgumentException("Unknown property: {$name}"),
263263
};
264264
}
265265

@@ -269,17 +269,17 @@ public function __get(string $name): mixed
269269
public function __set(string $name, mixed $value): void
270270
{
271271
match ($name) {
272-
'hidden' => $this->setHidden($value), // @phpstan-ignore-line argument.type
273-
'hiddenKey' => $this->setHiddenKey($value), // @phpstan-ignore-line method.notFound
272+
'hidden' => $this->setHidden($value), // @phpstan-ignore-line argument.type
273+
'hiddenKey' => $this->setHiddenKey($value), // @phpstan-ignore-line method.notFound
274274
'hiddenStart' => $this->setHiddenStart($value), // @phpstan-ignore-line method.notFound
275-
'hiddenEnd' => $this->setHiddenEnd($value), // @phpstan-ignore-line method.notFound
276-
'dotKey' => $this->setDotKey($value), // @phpstan-ignore-line method.notFound
277-
'slashKey' => $this->setSlashKey($value), // @phpstan-ignore-line method.notFound
278-
'dashKey' => $this->setDashKey($value), // @phpstan-ignore-line method.notFound
279-
'escape' => $this->setEscape($value), // @phpstan-ignore-line argument.type
280-
'encode' => $this->setEncode($value), // @phpstan-ignore-line argument.type
281-
'onFail' => $this->setOnFail($value), // @phpstan-ignore-line argument.type
282-
default => throw new InvalidArgumentException("Unknown property: {$name}"),
275+
'hiddenEnd' => $this->setHiddenEnd($value), // @phpstan-ignore-line method.notFound
276+
'dotKey' => $this->setDotKey($value), // @phpstan-ignore-line method.notFound
277+
'slashKey' => $this->setSlashKey($value), // @phpstan-ignore-line method.notFound
278+
'dashKey' => $this->setDashKey($value), // @phpstan-ignore-line method.notFound
279+
'escape' => $this->setEscape($value), // @phpstan-ignore-line argument.type
280+
'encode' => $this->setEncode($value), // @phpstan-ignore-line argument.type
281+
'onFail' => $this->setOnFail($value), // @phpstan-ignore-line argument.type
282+
default => throw new InvalidArgumentException("Unknown property: {$name}"),
283283
};
284284
}
285285

tests/Specs/CnpjFormatterOptions.spec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
'escape' => true,
6666
'encode' => true,
6767
'onFail' => function (mixed $value): string {
68-
return "ERROR: {$value}";
68+
return 'ERROR: ' . strval($value);
6969
},
7070
];
7171

@@ -758,7 +758,7 @@
758758
describe('when setting to a callable value', function () {
759759
it('sets `onFail` to the provided callback', function () {
760760
$callback = function (mixed $value, CnpjFormatterException $e): string {
761-
return "ERROR: {$value}";
761+
return 'ERROR: ' . strval($value);
762762
};
763763
$options = new CnpjFormatterOptions();
764764

@@ -771,7 +771,7 @@
771771
describe('when setting to a nullish value', function () use ($defaultParameters) {
772772
it('sets default callback for `null`', function () use ($defaultParameters) {
773773
$callback = function (mixed $value, CnpjFormatterException $e): string {
774-
return "ERROR: {$value}";
774+
return 'ERROR: ' . strval($value);
775775
};
776776
$options = new CnpjFormatterOptions(onFail: $callback);
777777

0 commit comments

Comments
 (0)