Skip to content

14 quality #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
parameters:
level: 6
level: 8
paths:
- src
- tests
excludePaths:
- src/DependencyInjection/Configuration.php
ignoreErrors:
- '#type has no value type specified in iterable type#'
- '#has parameter .* with no value type specified in iterable type#'
- '#has no value type specified in iterable type array#'
- '#configureOptions\(\) has no return type specified.#'
- '#configure\(\) has no return type specified#'
- '#process\(\) has no return type specified#'
- '#should return Iterator but returns Traversable#'
- '#Negated boolean expression is always false#'
-
identifier: missingType.generics
-
identifier: doctrine.columnType
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
3 changes: 3 additions & 0 deletions src/Admin/Filter/LogProcessFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class LogProcessFilter implements FilterInterface
{
use FilterTrait;

/**
* @param string[] $choices
*/
public static function new(
mixed $label,
array $choices,
Expand Down
18 changes: 17 additions & 1 deletion src/Entity/ProcessExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ class ProcessExecution implements \Stringable
#[ORM\Column(type: Types::STRING, enumType: ProcessExecutionStatus::class)]
public ProcessExecutionStatus $status = ProcessExecutionStatus::Started;

/**
* @var array<string, mixed>
*/
#[ORM\Column(type: Types::JSON)]
private array $report = [];

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

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

/**
* @param array<string|int, mixed> $context
*/
public function __construct(
string $code,
#[ORM\Column(type: Types::STRING, length: 255)] public readonly string $logFilename, ?array $context = [],
#[ORM\Column(type: Types::STRING, length: 255)] public readonly string $logFilename,
?array $context = [],
) {
$this->code = (string) (new UnicodeString($code))->truncate(255);
$this->startDate = \DateTimeImmutable::createFromMutable(new \DateTime());
Expand Down Expand Up @@ -104,11 +114,17 @@ public function getCode(): string
return $this->code;
}

/**
* @return array<string|int, mixed>
*/
public function getContext(): ?array
{
return $this->context;
}

/**
* @param array<string|int, mixed> $context
*/
public function setContext(array $context): void
{
$this->context = $context;
Expand Down
15 changes: 12 additions & 3 deletions src/Entity/ProcessSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProcessSchedule

#[ORM\Column(length: 255)]
#[IsValidProcessCode]
private ?string $process = null;
private string $process;

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

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

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

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

/**
* @return array<string|int, mixed>
*/
public function getContext(): array
{
return \is_array($this->context) ? $this->context : json_decode($this->context);
}

/**
* @param array<string|int, mixed> $context
*/
public function setContext(array $context): void
{
$this->context = $context;
Expand Down Expand Up @@ -100,7 +109,7 @@ public function getExpression(): ?string
return $this->expression;
}

public function setExpression(?string $expression): self
public function setExpression(string $expression): self
{
$this->expression = $expression;

Expand Down
7 changes: 5 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?int $id = null;

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

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

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

/**
* @var string[]
*/
#[ORM\Column(type: Types::JSON)]
private array $roles = [];

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

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

Expand Down
17 changes: 10 additions & 7 deletions src/Form/Type/LaunchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/** @template-extends AbstractType<array<string, mixed>> */
class LaunchType extends AbstractType
{
public function __construct(
Expand All @@ -38,13 +39,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$code = $options['process_code'];
$configuration = $this->registry->getProcessConfiguration($code);
$uiOptions = $this->configurationsManager->getUiOptions($code);
$builder->add(
'input',
'file' === ($uiOptions['entrypoint_type'] ?? null) ? FileType::class : TextType::class,
[
'required' => $configuration->getEntryPoint() instanceof TaskConfiguration,
]
);
if (isset($uiOptions['entrypoint_type'])) {
$builder->add(
'input',
'file' === $uiOptions['entrypoint_type'] ? FileType::class : TextType::class,
[
'required' => $configuration->getEntryPoint() instanceof TaskConfiguration,
]
);
}
$builder->add(
'context',
CollectionType::class,
Expand Down
1 change: 1 addition & 0 deletions src/Form/Type/ProcessContextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;

/** @template-extends AbstractType<null> */
class ProcessContextType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
1 change: 1 addition & 0 deletions src/Form/Type/ProcessUploadFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\OptionsResolver\OptionsResolver;

/** @template-extends AbstractType<null> */
class ProcessUploadFileType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
Expand Down
3 changes: 3 additions & 0 deletions src/Http/Model/HttpProcessExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

final readonly class HttpProcessExecution
{
/**
* @param array<string|int, mixed> $context
*/
public function __construct(
#[Sequentially(constraints: [new NotNull(message: 'Process code is required.'), new IsValidProcessCode()])]
public ?string $code = null,
Expand Down
3 changes: 3 additions & 0 deletions src/Http/ValueResolver/HttpProcessExecuteValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct(private string $storageDir)
{
}

/**
* @return iterable<HttpProcessExecution>
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
$input = $request->get('input', $request->files->get('input'));
Expand Down
4 changes: 4 additions & 0 deletions src/Http/ValueResolver/ProcessConfigurationValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CleverAge\UiProcessBundle\Http\ValueResolver;

use CleverAge\ProcessBundle\Configuration\ProcessConfiguration;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
Expand All @@ -26,6 +27,9 @@ public function __construct(private ProcessConfigurationRegistry $registry)
{
}

/**
* @return iterable<ProcessConfiguration>
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
return [$this->registry->getProcessConfiguration($request->get('process'))];
Expand Down
25 changes: 24 additions & 1 deletion src/Manager/ProcessConfigurationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
use CleverAge\ProcessBundle\Validator\ConstraintLoader;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraint;

/**
* @phpstan-type UiOptions array{
* 'source': ?string,
* 'target': ?string,
* 'entrypoint_type': string,
* 'constraints': Constraint[],
* 'run': 'null|bool',
* 'default': array{'input': mixed, 'context': array{array{'key': 'int|text', 'value':'int|text'}}}
* }
*/
final readonly class ProcessConfigurationsManager
{
public function __construct(private ProcessConfigurationRegistry $registry)
Expand All @@ -37,6 +48,9 @@ public function getPrivateProcesses(): array
return array_filter($this->getConfigurations(), fn (ProcessConfiguration $cfg) => !$cfg->isPublic());
}

/**
* @return UiOptions|null
*/
public function getUiOptions(string $processCode): ?array
{
if (false === $this->registry->hasProcessConfiguration($processCode)) {
Expand All @@ -48,6 +62,11 @@ public function getUiOptions(string $processCode): ?array
return $this->resolveUiOptions($configuration->getOptions())['ui'];
}

/**
* @param array<int|string, mixed> $options
*
* @return array{'ui': UiOptions}
*/
private function resolveUiOptions(array $options): array
{
$resolver = new OptionsResolver();
Expand Down Expand Up @@ -77,8 +96,12 @@ private function resolveUiOptions(array $options): array
$uiResolver->setAllowedValues('entrypoint_type', ['text', 'file']);
$uiResolver->setNormalizer('constraints', fn (Options $options, array $values): array => (new ConstraintLoader())->buildConstraints($values));
});
/**
* @var array{'ui': UiOptions} $options
*/
$options = $resolver->resolve($options);

return $resolver->resolve($options);
return $options;
}

/** @return ProcessConfiguration[] */
Expand Down
3 changes: 3 additions & 0 deletions src/Message/ProcessExecuteMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

readonly class ProcessExecuteMessage
{
/**
* @param mixed[] $context
*/
public function __construct(public string $code, public mixed $input, public array $context = [])
{
}
Expand Down
Loading