Skip to content

Commit ababeae

Browse files
committed
run ecs
1 parent bb8a6fe commit ababeae

12 files changed

Lines changed: 41 additions & 42 deletions

src/Context/Gender/Gender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum Gender: string implements GenderInterface
1313
public function build(): SalutationPartResult
1414
{
1515
return new SalutationPartResult(
16-
'gender.' . $this->value,
16+
'gender.'.$this->value,
1717
domain: 'salutation_creator',
1818
fallback: ucfirst($this->value),
1919
);

src/Context/Name/GermanTypeName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(
1212

1313
public function getFullName(): string
1414
{
15-
return $this->firstName . ' ' . $this->lastName;
15+
return $this->firstName.' '.$this->lastName;
1616
}
1717

1818
public function getFormalName(): string

src/Parser/Name/AbstractParser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ abstract class AbstractParser
1313

1414
/**
1515
* @param class-string<RuleInterface>[] $rules
16-
* @param class-string<AbstractName> $format
16+
* @param class-string<AbstractName> $format
1717
*/
1818
final public function __construct(
1919
protected array $rules,
2020
protected string $format,
2121
) {
22-
if (!(is_a($this->format, AbstractName::class, true))) {
22+
if (!is_a($this->format, AbstractName::class, true)) {
2323
throw new \InvalidArgumentException(sprintf('Format class "%s" does not exist or is not a subclass of "%s".', $this->format, AbstractName::class));
2424
}
2525
}
@@ -33,12 +33,14 @@ public static function create(string $format): static
3333
$rules = static::defaultRules($format);
3434

3535
$instance = new static($rules, $format);
36+
3637
return $instance;
3738
}
3839

3940
public function allowIncomplete(bool $allow): static
4041
{
4142
$this->allowIncomplete = $allow;
43+
4244
return $this;
4345
}
4446

@@ -71,4 +73,4 @@ protected function buildNameFromResult(Result $result): ?AbstractName
7173
* @return class-string<RuleInterface>[]
7274
*/
7375
abstract public static function defaultRules(string $format): array;
74-
}
76+
}

src/Parser/Name/ArrayParser.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public function parse(array $data): ?AbstractName
2121
foreach ($data as $key => $value) {
2222
$entry = new RowValue($key, $value);
2323
foreach ($this->rules as $rule) {
24-
if (!(is_a($rule, RuleInterface::class, true))) {
24+
if (!is_a($rule, RuleInterface::class, true)) {
2525
continue;
2626
}
27-
$result->with((new $rule)->apply($entry));
27+
$result->with((new $rule())->apply($entry));
2828
if ($result->isComplete()) {
2929
break 2;
3030
}
@@ -36,6 +36,7 @@ public function parse(array $data): ?AbstractName
3636

3737
/**
3838
* @param class-string<AbstractName> $format
39+
*
3940
* @return class-string<RuleInterface>[]
4041
*/
4142
public static function defaultRules(string $format): array
@@ -50,4 +51,4 @@ public static function defaultRules(string $format): array
5051
],
5152
};
5253
}
53-
}
54+
}

src/Parser/Name/Rule/Array/EnglishKeyNameRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
namespace HeimrichHannot\SalutationCreator\Parser\Name\Rule\Array;
44

55
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\Result;
6-
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\RuleInterface;
76
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\RowValue;
7+
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\RuleInterface;
88
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\Value;
99

1010
class EnglishKeyNameRule implements RuleInterface
1111
{
1212
public function apply(Value $value): Result
1313
{
14-
if (!($value instanceof RowValue)) {
14+
if (!$value instanceof RowValue) {
1515
return new Result(false);
1616
}
1717

1818
if (!is_string($value->originalValue)) {
1919
return new Result(false);
2020
}
2121

22-
if ($value->normalizedKey === 'firstname') {
22+
if ('firstname' === $value->normalizedKey) {
2323
return new Result(true, firstName: $value->originalValue, origin: $value);
2424
}
2525
if (\in_array($value->normalizedKey, ['lastname', 'name'])) {
@@ -28,4 +28,4 @@ public function apply(Value $value): Result
2828

2929
return new Result(false);
3030
}
31-
}
31+
}

src/Parser/Name/Rule/Array/GermanKeyNameRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GermanKeyNameRule implements RuleInterface
1111
{
1212
public function apply(Value $value): Result
1313
{
14-
if (!($value instanceof RowValue)) {
14+
if (!$value instanceof RowValue) {
1515
return new Result(false);
1616
}
1717

@@ -28,4 +28,4 @@ public function apply(Value $value): Result
2828

2929
return new Result(false);
3030
}
31-
}
31+
}

src/Parser/Name/Rule/Result.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
class Result
66
{
77
public function __construct(
8-
public readonly bool $matched,
8+
public readonly bool $matched,
99
public readonly string $firstName = '',
1010
public readonly string $lastName = '',
11-
public readonly mixed $origin = null,
12-
) {}
11+
public readonly mixed $origin = null,
12+
) {
13+
}
1314

1415
public function with(Result $result): Result
1516
{
@@ -19,19 +20,19 @@ public function with(Result $result): Result
1920

2021
return new self(
2122
true,
22-
$result->firstName !== '' ? $result->firstName : $this->firstName,
23-
$result->lastName !== '' ? $result->lastName : $this->lastName,
23+
'' !== $result->firstName ? $result->firstName : $this->firstName,
24+
'' !== $result->lastName ? $result->lastName : $this->lastName,
2425
$this->origin // oder $result->origin, je nach gewünschter Semantik
2526
);
2627
}
2728

2829
public function isComplete(): bool
2930
{
30-
return $this->matched && $this->firstName !== '' && $this->lastName !== '';
31+
return $this->matched && '' !== $this->firstName && '' !== $this->lastName;
3132
}
3233

3334
public function isEmpty(): bool
3435
{
35-
return $this->firstName === '' && $this->lastName === '';
36+
return '' === $this->firstName && '' === $this->lastName;
3637
}
37-
}
38+
}

src/Parser/Name/Rule/RowValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class RowValue extends Value
99

1010
public function __construct(
1111
string|int $key,
12-
mixed $value
12+
mixed $value,
1313
) {
1414
parent::__construct($value);
1515

1616
$this->originalKey = (string) $key;
1717
$this->normalizedKey = strtolower((string) preg_replace('/[^a-z0-9]/i', '', $this->originalKey));
1818
}
19-
}
19+
}

src/Parser/Name/Rule/RuleInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace HeimrichHannot\SalutationCreator\Parser\Name\Rule;
44

5-
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\Result;
6-
use HeimrichHannot\SalutationCreator\Parser\Name\Rule\Value;
7-
85
interface RuleInterface
96
{
107
public function apply(Value $value): Result;
11-
}
8+
}

src/Parser/Name/Rule/Value.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
class Value
66
{
7-
public function __construct(public mixed $originalValue)
8-
{
7+
public function __construct(
8+
public mixed $originalValue,
9+
) {
910
}
10-
11-
12-
}
11+
}

0 commit comments

Comments
 (0)