Skip to content

Commit 4e659f6

Browse files
Improve quality on Entities
1 parent aa3e2f8 commit 4e659f6

File tree

7 files changed

+67
-67
lines changed

7 files changed

+67
-67
lines changed

src/Controller/Admin/ProcessScheduleCrudController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
use CleverAge\ProcessBundle\Configuration\ProcessConfiguration;
1717
use CleverAge\UiProcessBundle\Admin\Field\EnumField;
18+
use CleverAge\UiProcessBundle\Entity\Enum\ProcessScheduleType;
1819
use CleverAge\UiProcessBundle\Entity\ProcessSchedule;
19-
use CleverAge\UiProcessBundle\Entity\ProcessScheduleType;
2020
use CleverAge\UiProcessBundle\Form\Type\ProcessContextType;
2121
use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager;
2222
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the CleverAge/UiProcessBundle package.
7+
*
8+
* Copyright (c) Clever-Age
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace CleverAge\UiProcessBundle\Entity\Enum;
15+
16+
enum ProcessScheduleType: string
17+
{
18+
case CRON = 'cron';
19+
case EVERY = 'every';
20+
}

src/Entity/LogRecord.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,47 @@
1313

1414
namespace CleverAge\UiProcessBundle\Entity;
1515

16+
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\Mapping as ORM;
1718
use Symfony\Component\String\UnicodeString;
1819

1920
#[ORM\Entity]
20-
#[ORM\Index(columns: ['level'], name: 'idx_log_record_level')]
21-
#[ORM\Index(columns: ['created_at'], name: 'idx_log_record_created_at')]
21+
#[ORM\Index(name: 'idx_log_record_level', columns: ['level'])]
22+
#[ORM\Index(name: 'idx_log_record_created_at', columns: ['created_at'])]
2223
class LogRecord
2324
{
2425
#[ORM\Id]
2526
#[ORM\GeneratedValue]
2627
#[ORM\Column]
2728
private ?int $id = null;
2829

29-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 64)]
30+
#[ORM\Column(type: Types::STRING, length: 64)]
3031
public readonly string $channel;
3132

32-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
33+
#[ORM\Column(type: Types::INTEGER)]
3334
public readonly int $level;
3435

35-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 512)]
36+
#[ORM\Column(type: Types::STRING, length: 512)]
3637
public readonly string $message;
3738

38-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
39-
/** @var array<string, mixed> */
39+
/** @var array<string, mixed> $context */
40+
#[ORM\Column(type: Types::JSON)]
4041
public readonly array $context;
4142

42-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)]
43+
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
4344
public readonly \DateTimeImmutable $createdAt;
4445

4546
public function getId(): ?int
4647
{
4748
return $this->id;
4849
}
4950

50-
public function __construct(\Monolog\LogRecord $record, #[ORM\ManyToOne(targetEntity: ProcessExecution::class, cascade: ['all'])]
51+
public function __construct(
52+
\Monolog\LogRecord $record,
53+
#[ORM\ManyToOne(targetEntity: ProcessExecution::class, cascade: ['all'])]
5154
#[ORM\JoinColumn(name: 'process_execution_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
52-
private readonly ProcessExecution $processExecution)
53-
{
55+
private readonly ProcessExecution $processExecution,
56+
) {
5457
$this->channel = (string) (new UnicodeString($record->channel))->truncate(64);
5558
$this->level = $record->level->value;
5659
$this->message = (string) (new UnicodeString($record->message))->truncate(512);

src/Entity/ProcessExecution.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\String\UnicodeString;
2020

2121
#[ORM\Entity]
22-
#[ORM\Index(columns: ['code'], name: 'idx_process_execution_code')]
23-
#[ORM\Index(columns: ['start_date'], name: 'idx_process_execution_start_date')]
22+
#[ORM\Index(name: 'idx_process_execution_code', columns: ['code'])]
23+
#[ORM\Index(name: 'idx_process_execution_start_date', columns: ['start_date'])]
2424
class ProcessExecution implements \Stringable
2525
{
2626
#[ORM\Id]
@@ -51,14 +51,20 @@ public function getId(): ?int
5151
return $this->id;
5252
}
5353

54-
public function __construct(string $code, #[ORM\Column(type: Types::STRING, length: 255)]
55-
public readonly string $logFilename, ?array $context = [])
56-
{
54+
public function __construct(
55+
string $code,
56+
#[ORM\Column(type: Types::STRING, length: 255)] public readonly string $logFilename, ?array $context = [],
57+
) {
5758
$this->code = (string) (new UnicodeString($code))->truncate(255);
5859
$this->startDate = \DateTimeImmutable::createFromMutable(new \DateTime());
5960
$this->context = $context ?? [];
6061
}
6162

63+
public function __toString(): string
64+
{
65+
return \sprintf('%s (%s)', $this->id, $this->code);
66+
}
67+
6268
public function setStatus(ProcessExecutionStatus $status): void
6369
{
6470
$this->status = $status;
@@ -69,11 +75,6 @@ public function end(): void
6975
$this->endDate = \DateTimeImmutable::createFromMutable(new \DateTime());
7076
}
7177

72-
public function __toString(): string
73-
{
74-
return \sprintf('%s (%s)', $this->id, $this->code);
75-
}
76-
7778
public function addReport(string $key, mixed $value): void
7879
{
7980
$this->report[$key] = $value;

src/Entity/ProcessSchedule.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@
1313

1414
namespace CleverAge\UiProcessBundle\Entity;
1515

16+
use CleverAge\UiProcessBundle\Entity\Enum\ProcessScheduleType;
1617
use CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository;
1718
use CleverAge\UiProcessBundle\Validator\CronExpression;
1819
use CleverAge\UiProcessBundle\Validator\EveryExpression;
1920
use CleverAge\UiProcessBundle\Validator\IsValidProcessCode;
21+
use Doctrine\DBAL\Types\Types;
2022
use Doctrine\ORM\Mapping as ORM;
2123
use Symfony\Component\Validator\Constraints as Assert;
2224

23-
enum ProcessScheduleType: string
24-
{
25-
case CRON = 'cron';
26-
case EVERY = 'every';
27-
}
28-
2925
#[ORM\Entity(repositoryClass: ProcessScheduleRepository::class)]
3026
class ProcessSchedule
3127
{
@@ -49,10 +45,10 @@ class ProcessSchedule
4945
)]
5046
private ?string $expression = null;
5147

52-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)]
48+
#[ORM\Column(type: Types::TEXT, nullable: true)]
5349
private ?string $input = null;
5450

55-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
51+
#[ORM\Column(type: Types::JSON)]
5652
private string|array $context = [];
5753

5854
public function getId(): ?int

src/Entity/User.php

+16-36
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,43 @@
1313

1414
namespace CleverAge\UiProcessBundle\Entity;
1515

16+
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\Mapping as ORM;
1718
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
1819
use Symfony\Component\Security\Core\User\UserInterface;
1920

2021
#[ORM\Entity]
2122
#[ORM\Table(name: 'process_user')]
22-
#[ORM\Index(columns: ['email'], name: 'idx_process_user_email')]
23+
#[ORM\Index(name: 'idx_process_user_email', columns: ['email'])]
2324
class User implements UserInterface, PasswordAuthenticatedUserInterface
2425
{
2526
#[ORM\Id]
2627
#[ORM\GeneratedValue]
2728
#[ORM\Column]
2829
private ?int $id = null;
2930

30-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, unique: true)]
31+
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
3132
private ?string $email = null;
3233

33-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
34+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
3435
private ?string $firstname = null;
3536

36-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
37+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
3738
private ?string $lastname = null;
3839

39-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
40+
#[ORM\Column(type: Types::JSON)]
4041
private array $roles = [];
4142

42-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
43+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
4344
private ?string $password = null;
4445

45-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
46+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
4647
private ?string $timezone = null;
4748

48-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
49+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
4950
private ?string $locale = null;
5051

51-
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
52+
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
5253
private ?string $token = null;
5354

5455
public function getId(): ?int
@@ -92,14 +93,13 @@ public function setLastname(?string $lastname): self
9293
return $this;
9394
}
9495

95-
/**
96-
* A visual identifier that represents this user.
97-
*
98-
* @see UserInterface
99-
*/
10096
public function getUserIdentifier(): string
10197
{
102-
return (string) $this->email;
98+
if (null === $this->email || '' === $this->email || '0' === $this->email) {
99+
throw new \LogicException('The User class must have an email.');
100+
}
101+
102+
return $this->email;
103103
}
104104

105105
public function getUsername(): string
@@ -131,16 +131,13 @@ public function setLocale(?string $locale): self
131131
return $this;
132132
}
133133

134-
/**
135-
* @see UserInterface
136-
*/
137134
public function getRoles(): array
138135
{
139136
return array_merge(['ROLE_USER'], $this->roles);
140137
}
141138

142139
/**
143-
* @param array <int, string> $roles
140+
* @param array<int, string> $roles
144141
*/
145142
public function setRoles(array $roles): self
146143
{
@@ -149,9 +146,6 @@ public function setRoles(array $roles): self
149146
return $this;
150147
}
151148

152-
/**
153-
* @see PasswordAuthenticatedUserInterface
154-
*/
155149
public function getPassword(): ?string
156150
{
157151
return $this->password;
@@ -176,20 +170,6 @@ public function setToken(?string $token): self
176170
return $this;
177171
}
178172

179-
/**
180-
* Returning a salt is only needed, if you are not using a modern
181-
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
182-
*
183-
* @see UserInterface
184-
*/
185-
public function getSalt(): ?string
186-
{
187-
return null;
188-
}
189-
190-
/**
191-
* @see UserInterface
192-
*/
193173
public function eraseCredentials(): void
194174
{
195175
// If you store any temporary, sensitive data on the user, clear it here

src/Scheduler/CronScheduler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace CleverAge\UiProcessBundle\Scheduler;
1515

16-
use CleverAge\UiProcessBundle\Entity\ProcessScheduleType;
16+
use CleverAge\UiProcessBundle\Entity\Enum\ProcessScheduleType;
1717
use CleverAge\UiProcessBundle\Message\CronProcessMessage;
1818
use CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository;
1919
use Psr\Log\LoggerInterface;

0 commit comments

Comments
 (0)