Skip to content

Commit d62c1af

Browse files
committed
phpstan level 10
1 parent df56b37 commit d62c1af

9 files changed

Lines changed: 41 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.1.0] - 2024-09-03
5+
## [0.1.0] - 2025-12-09
66
Initial release

phpstan.neon

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 10
3+
treatPhpDocTypesAsCertain: false
34
paths:
4-
- src
5-
# - contao
6-
# universalObjectCratesClasses:
7-
# - Contao\Model
8-
# - Contao\Template
9-
includes:
10-
- vendor/phpstan/phpstan-symfony/extension.neon
5+
- src

src/Context/Gender/Gender.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public function getKey(): string
2424
return $this->value;
2525
}
2626

27+
/**
28+
* @return array<string, GenderInterface>
29+
*/
2730
public static function defaultMapping(): array
2831
{
2932
return [
@@ -46,6 +49,9 @@ public static function defaultMapping(): array
4649
];
4750
}
4851

52+
/**
53+
* @param array<string, GenderInterface>|null $mapping
54+
*/
4955
public static function tryFromString(string $value, ?self $fallback = null, ?array $mapping = null): ?GenderInterface
5056
{
5157
$value = strtolower(trim($value));

src/Context/Name/AbstractName.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public function build(): SalutationPartResult
1515
/**
1616
* Return the full name, e.g. "John Doe"
1717
*/
18-
abstract function getFullName();
18+
abstract function getFullName(): string;
1919

2020
/**
2121
* Return the formal name, e.g. "Mr. Doe". Used for formal salutations.
2222
*/
23-
abstract function getFormalName();
23+
abstract function getFormalName(): string;
2424

2525
/**
2626
* Return the given name, e.g. "John". Used for informal salutations.
2727
*/
28-
abstract function getGivenName();
28+
abstract function getGivenName(): string;
2929
}

src/Context/Name/GermanTypeName.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public function __construct(
99
private readonly string $lastName
1010
) {}
1111

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

17-
function getFormalName()
17+
function getFormalName(): string
1818
{
1919
return $this->lastName;
2020
}
2121

22-
function getGivenName()
22+
function getGivenName(): string
2323
{
2424
return $this->firstName;
2525
}

src/Helper/Titles.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class Titles
1111
{
12+
/**
13+
* @return array<string, array{0: class-string<AbstractTitle>, 1?: non-empty-list<string>}>
14+
*/
1215
public static function defaultMapping(): array
1316
{
1417
return [
@@ -29,7 +32,7 @@ public static function defaultMapping(): array
2932

3033
/**
3134
* @param string $value
32-
* @param array|null $mapping Override the default string title mapping
35+
* @param array<string, array{0: class-string<AbstractTitle>, 1?: non-empty-list<string>}>|null $mapping Override the default string title mapping
3336
* @return AbstractTitle[]
3437
*/
3538
public static function fromString(string $value, ?array $mapping = null): array
@@ -54,7 +57,9 @@ public static function fromString(string $value, ?array $mapping = null): array
5457
continue;
5558
}
5659

57-
$titles[] = new $mapping[$key][0](...($mapping[$key][1] ?? []));
60+
/** @var AbstractTitle $title */
61+
$title = new $mapping[$key][0](...($mapping[$key][1] ?? []));
62+
$titles[] = $title;
5863
}
5964

6065
return $titles;

src/SalutationContext.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function addTitle(AbstractTitle $title): self
4242
return $this;
4343
}
4444

45+
/**
46+
* @param AbstractTitle[] $titles
47+
* @return $this
48+
*/
4549
public function addTitles(array $titles): self
4650
{
4751
foreach ($titles as $title) {

src/SalutationCreator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function generate(SalutationContext $context): string
3333
'%suffix_titles%' => $suffixTitles,
3434
'%gender_name%' => $context->getGender()->build()->trans($this->translator),
3535
'%gender%' => $context->getGender()->getKey(),
36-
'%name%' => $context->getName()->getFullName(),
37-
'%formal_name%' => $context->getName()->getFormalName(),
38-
'%given_name%' => $context->getName()->getGivenName(),
36+
'%name%' => $context->getName()?->getFullName() ?? '',
37+
'%formal_name%' => $context->getName()?->getFormalName() ?? '',
38+
'%given_name%' => $context->getName()?->getGivenName() ?? '',
3939
];
4040

4141
return trim($this->translator->trans(
@@ -46,12 +46,16 @@ public function generate(SalutationContext $context): string
4646

4747
}
4848

49+
/**
50+
* @param array<SalutationPartInterface|array<SalutationPartInterface>> $array
51+
* @return string
52+
*/
4953
private function buildString(array $array): string
5054
{
5155
$string = '';
5256
array_walk_recursive($array, function ($value) use (&$string) {
5357
/**
54-
* @var AbstractTitle $value
58+
* @var SalutationPartInterface $value
5559
*/
5660
$string .= $value->build()->trans($this->translator);
5761
});

src/SalutationPartResult.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
readonly class SalutationPartResult implements TranslatableInterface, \Stringable
99
{
10+
/**
11+
* @param array<string,string|int|TranslatableInterface> $parameters
12+
*/
1013
public function __construct(
1114
private string $message,
1215
private array $parameters = [],
@@ -25,6 +28,9 @@ public function getMessage(): string
2528
return $this->message;
2629
}
2730

31+
/**
32+
* @return array<string,string|int|TranslatableInterface>
33+
*/
2834
public function getParameters(): array
2935
{
3036
return $this->parameters;

0 commit comments

Comments
 (0)