Skip to content

Commit ebdfa8d

Browse files
Merge pull request #17 from cleverage/14_quality
14 quality
2 parents 16d92bb + f4bdfbb commit ebdfa8d

13 files changed

+87
-33
lines changed

phpstan.neon

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 8
33
paths:
44
- src
55
- tests
6-
excludePaths:
7-
- src/DependencyInjection/Configuration.php
8-
ignoreErrors:
9-
- '#type has no value type specified in iterable type#'
10-
- '#has parameter .* with no value type specified in iterable type#'
11-
- '#has no value type specified in iterable type array#'
12-
- '#configureOptions\(\) has no return type specified.#'
13-
- '#configure\(\) has no return type specified#'
14-
- '#process\(\) has no return type specified#'
15-
- '#should return Iterator but returns Traversable#'
16-
- '#Negated boolean expression is always false#'
17-
-
18-
identifier: missingType.generics
19-
-
20-
identifier: doctrine.columnType
21-
reportUnmatchedIgnoredErrors: false
22-
inferPrivatePropertyTypeFromConstructor: true
23-
treatPhpDocTypesAsCertain: false

src/Admin/Filter/LogProcessFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class LogProcessFilter implements FilterInterface
2626
{
2727
use FilterTrait;
2828

29+
/**
30+
* @param string[] $choices
31+
*/
2932
public static function new(
3033
mixed $label,
3134
array $choices,

src/Entity/ProcessExecution.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ class ProcessExecution implements \Stringable
4040
#[ORM\Column(type: Types::STRING, enumType: ProcessExecutionStatus::class)]
4141
public ProcessExecutionStatus $status = ProcessExecutionStatus::Started;
4242

43+
/**
44+
* @var array<string, mixed>
45+
*/
4346
#[ORM\Column(type: Types::JSON)]
4447
private array $report = [];
4548

49+
/**
50+
* @var array<string|int, mixed>
51+
*/
4652
#[ORM\Column(type: Types::JSON, nullable: true)]
4753
private ?array $context = [];
4854

@@ -51,9 +57,13 @@ public function getId(): ?int
5157
return $this->id;
5258
}
5359

60+
/**
61+
* @param array<string|int, mixed> $context
62+
*/
5463
public function __construct(
5564
string $code,
56-
#[ORM\Column(type: Types::STRING, length: 255)] public readonly string $logFilename, ?array $context = [],
65+
#[ORM\Column(type: Types::STRING, length: 255)] public readonly string $logFilename,
66+
?array $context = [],
5767
) {
5868
$this->code = (string) (new UnicodeString($code))->truncate(255);
5969
$this->startDate = \DateTimeImmutable::createFromMutable(new \DateTime());
@@ -104,11 +114,17 @@ public function getCode(): string
104114
return $this->code;
105115
}
106116

117+
/**
118+
* @return array<string|int, mixed>
119+
*/
107120
public function getContext(): ?array
108121
{
109122
return $this->context;
110123
}
111124

125+
/**
126+
* @param array<string|int, mixed> $context
127+
*/
112128
public function setContext(array $context): void
113129
{
114130
$this->context = $context;

src/Entity/ProcessSchedule.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ProcessSchedule
3232

3333
#[ORM\Column(length: 255)]
3434
#[IsValidProcessCode]
35-
private ?string $process = null;
35+
private string $process;
3636

3737
#[ORM\Column(length: 6)]
3838
private ProcessScheduleType $type;
@@ -43,11 +43,14 @@ class ProcessSchedule
4343
#[Assert\When(
4444
expression: 'this.getType().value == "every"', constraints: [new EveryExpression()]
4545
)]
46-
private ?string $expression = null;
46+
private string $expression;
4747

4848
#[ORM\Column(type: Types::TEXT, nullable: true)]
4949
private ?string $input = null;
5050

51+
/**
52+
* @var string|array<string|int, mixed>
53+
*/
5154
#[ORM\Column(type: Types::JSON)]
5255
private string|array $context = [];
5356

@@ -68,11 +71,17 @@ public function setProcess(string $process): static
6871
return $this;
6972
}
7073

74+
/**
75+
* @return array<string|int, mixed>
76+
*/
7177
public function getContext(): array
7278
{
7379
return \is_array($this->context) ? $this->context : json_decode($this->context);
7480
}
7581

82+
/**
83+
* @param array<string|int, mixed> $context
84+
*/
7685
public function setContext(array $context): void
7786
{
7887
$this->context = $context;
@@ -100,7 +109,7 @@ public function getExpression(): ?string
100109
return $this->expression;
101110
}
102111

103-
public function setExpression(?string $expression): self
112+
public function setExpression(string $expression): self
104113
{
105114
$this->expression = $expression;
106115

src/Entity/User.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
2929
private ?int $id = null;
3030

3131
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
32-
private ?string $email = null;
32+
private string $email;
3333

3434
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
3535
private ?string $firstname = null;
3636

3737
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
3838
private ?string $lastname = null;
3939

40+
/**
41+
* @var string[]
42+
*/
4043
#[ORM\Column(type: Types::JSON)]
4144
private array $roles = [];
4245

@@ -95,7 +98,7 @@ public function setLastname(?string $lastname): self
9598

9699
public function getUserIdentifier(): string
97100
{
98-
if (null === $this->email || '' === $this->email || '0' === $this->email) {
101+
if ('' === $this->email) {
99102
throw new \LogicException('The User class must have an email.');
100103
}
101104

src/Form/Type/LaunchType.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Form\FormBuilderInterface;
2626
use Symfony\Component\OptionsResolver\OptionsResolver;
2727

28+
/** @template-extends AbstractType<array<string, mixed>> */
2829
class LaunchType extends AbstractType
2930
{
3031
public function __construct(
@@ -38,13 +39,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3839
$code = $options['process_code'];
3940
$configuration = $this->registry->getProcessConfiguration($code);
4041
$uiOptions = $this->configurationsManager->getUiOptions($code);
41-
$builder->add(
42-
'input',
43-
'file' === ($uiOptions['entrypoint_type'] ?? null) ? FileType::class : TextType::class,
44-
[
45-
'required' => $configuration->getEntryPoint() instanceof TaskConfiguration,
46-
]
47-
);
42+
if (isset($uiOptions['entrypoint_type'])) {
43+
$builder->add(
44+
'input',
45+
'file' === $uiOptions['entrypoint_type'] ? FileType::class : TextType::class,
46+
[
47+
'required' => $configuration->getEntryPoint() instanceof TaskConfiguration,
48+
]
49+
);
50+
}
4851
$builder->add(
4952
'context',
5053
CollectionType::class,

src/Form/Type/ProcessContextType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\OptionsResolver\OptionsResolver;
1919
use Symfony\Component\Validator\Constraints\NotBlank;
2020

21+
/** @template-extends AbstractType<null> */
2122
class ProcessContextType extends AbstractType
2223
{
2324
public function buildForm(FormBuilderInterface $builder, array $options): void

src/Form/Type/ProcessUploadFileType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Form\Extension\Core\Type\FileType;
1818
use Symfony\Component\OptionsResolver\OptionsResolver;
1919

20+
/** @template-extends AbstractType<null> */
2021
class ProcessUploadFileType extends AbstractType
2122
{
2223
public function configureOptions(OptionsResolver $resolver): void

src/Http/Model/HttpProcessExecution.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
final readonly class HttpProcessExecution
2121
{
22+
/**
23+
* @param array<string|int, mixed> $context
24+
*/
2225
public function __construct(
2326
#[Sequentially(constraints: [new NotNull(message: 'Process code is required.'), new IsValidProcessCode()])]
2427
public ?string $code = null,

src/Http/ValueResolver/HttpProcessExecuteValueResolver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function __construct(private string $storageDir)
2828
{
2929
}
3030

31+
/**
32+
* @return iterable<HttpProcessExecution>
33+
*/
3134
public function resolve(Request $request, ArgumentMetadata $argument): iterable
3235
{
3336
$input = $request->get('input', $request->files->get('input'));

src/Http/ValueResolver/ProcessConfigurationValueResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CleverAge\UiProcessBundle\Http\ValueResolver;
1515

16+
use CleverAge\ProcessBundle\Configuration\ProcessConfiguration;
1617
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
@@ -26,6 +27,9 @@ public function __construct(private ProcessConfigurationRegistry $registry)
2627
{
2728
}
2829

30+
/**
31+
* @return iterable<ProcessConfiguration>
32+
*/
2933
public function resolve(Request $request, ArgumentMetadata $argument): iterable
3034
{
3135
return [$this->registry->getProcessConfiguration($request->get('process'))];

src/Manager/ProcessConfigurationsManager.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@
1818
use CleverAge\ProcessBundle\Validator\ConstraintLoader;
1919
use Symfony\Component\OptionsResolver\Options;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
21+
use Symfony\Component\Validator\Constraint;
2122

23+
/**
24+
* @phpstan-type UiOptions array{
25+
* 'source': ?string,
26+
* 'target': ?string,
27+
* 'entrypoint_type': string,
28+
* 'constraints': Constraint[],
29+
* 'run': 'null|bool',
30+
* 'default': array{'input': mixed, 'context': array{array{'key': 'int|text', 'value':'int|text'}}}
31+
* }
32+
*/
2233
final readonly class ProcessConfigurationsManager
2334
{
2435
public function __construct(private ProcessConfigurationRegistry $registry)
@@ -37,6 +48,9 @@ public function getPrivateProcesses(): array
3748
return array_filter($this->getConfigurations(), fn (ProcessConfiguration $cfg) => !$cfg->isPublic());
3849
}
3950

51+
/**
52+
* @return UiOptions|null
53+
*/
4054
public function getUiOptions(string $processCode): ?array
4155
{
4256
if (false === $this->registry->hasProcessConfiguration($processCode)) {
@@ -48,6 +62,11 @@ public function getUiOptions(string $processCode): ?array
4862
return $this->resolveUiOptions($configuration->getOptions())['ui'];
4963
}
5064

65+
/**
66+
* @param array<int|string, mixed> $options
67+
*
68+
* @return array{'ui': UiOptions}
69+
*/
5170
private function resolveUiOptions(array $options): array
5271
{
5372
$resolver = new OptionsResolver();
@@ -77,8 +96,12 @@ private function resolveUiOptions(array $options): array
7796
$uiResolver->setAllowedValues('entrypoint_type', ['text', 'file']);
7897
$uiResolver->setNormalizer('constraints', fn (Options $options, array $values): array => (new ConstraintLoader())->buildConstraints($values));
7998
});
99+
/**
100+
* @var array{'ui': UiOptions} $options
101+
*/
102+
$options = $resolver->resolve($options);
80103

81-
return $resolver->resolve($options);
104+
return $options;
82105
}
83106

84107
/** @return ProcessConfiguration[] */

src/Message/ProcessExecuteMessage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
readonly class ProcessExecuteMessage
1717
{
18+
/**
19+
* @param mixed[] $context
20+
*/
1821
public function __construct(public string $code, public mixed $input, public array $context = [])
1922
{
2023
}

0 commit comments

Comments
 (0)