From 41842bbe41ca3c04490b97cc81c2c2fac96204c6 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Wed, 20 May 2020 00:00:11 +0700 Subject: [PATCH] Remove timestampable trait --- .github/workflows/main.yml | 2 +- insights.php | 3 --- src/Entity/Bug.php | 30 ++++++++++++++++++++++-- src/Entity/Task.php | 29 +++++++++++++++++++++-- src/Entity/TimestampableTrait.php | 36 ----------------------------- src/Model/Bug.php | 37 ++++++++++++++++++++++++++++-- src/Model/BugInterface.php | 4 ++-- src/Model/Task.php | 37 ++++++++++++++++++++++++++++-- src/Model/TaskInterface.php | 4 ++-- src/Model/TimestampableTrait.php | 38 ------------------------------- 10 files changed, 130 insertions(+), 90 deletions(-) delete mode 100644 src/Entity/TimestampableTrait.php delete mode 100644 src/Model/TimestampableTrait.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bae47591..e8762a28 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: - name: PHP Insights uses: docker://tienvx/phpinsights-action with: - args: "-v --config-path=insights.php --min-quality=80 --min-complexity=80 --min-architecture=80 --min-style=90" + args: "-v --config-path=insights.php --min-quality=80 --min-complexity=80 --min-architecture=70 --min-style=90" test: name: Test PHP ${{ matrix.php }} diff --git a/insights.php b/insights.php index 4553c11a..b78dc675 100644 --- a/insights.php +++ b/insights.php @@ -64,9 +64,6 @@ // ExampleInsight::class, \PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterNotSniff::class, \NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses::class, - \NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits::class, - \PHP_CodeSniffer\Standards\Generic\Sniffs\Files\OneTraitPerFileSniff::class, - \SlevomatCodingStandard\Sniffs\Classes\SuperfluousTraitNamingSniff::class, \SlevomatCodingStandard\Sniffs\Classes\SuperfluousInterfaceNamingSniff::class, \SlevomatCodingStandard\Sniffs\Classes\SuperfluousAbstractClassNamingSniff::class, ], diff --git a/src/Entity/Bug.php b/src/Entity/Bug.php index ae5a6387..c9861842 100644 --- a/src/Entity/Bug.php +++ b/src/Entity/Bug.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Entity; +use DateTime; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Tienvx\Bundle\MbtBundle\Model\Bug as BugModel; @@ -14,8 +15,6 @@ */ class Bug extends BugModel { - use TimestampableTrait; - /** * @ORM\Column(type="integer") * @ORM\Id() @@ -77,8 +76,35 @@ class Bug extends BugModel */ protected $messagesCount = 0; + /** + * @ORM\Column(name="created_at", type="datetime", nullable=true) + */ + protected $createdAt; + + /** + * @ORM\Column(name="updated_at", type="datetime", nullable=true) + */ + protected $updatedAt; + public function getWorkflow(): WorkflowInterface { return new Workflow($this->workflow); } + + /** + * @ORM\PrePersist + */ + public function prePersist(): void + { + $this->createdAt = new DateTime(); + $this->updatedAt = new DateTime(); + } + + /** + * @ORM\PreUpdate + */ + public function preUpdate(): void + { + $this->updatedAt = new DateTime(); + } } diff --git a/src/Entity/Task.php b/src/Entity/Task.php index 3df67ff3..924ee5a4 100644 --- a/src/Entity/Task.php +++ b/src/Entity/Task.php @@ -2,6 +2,7 @@ namespace Tienvx\Bundle\MbtBundle\Entity; +use DateTime; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Tienvx\Bundle\MbtBundle\Model\GeneratorInterface; @@ -17,8 +18,6 @@ */ class Task extends TaskModel { - use TimestampableTrait; - /** * @ORM\Column(type="integer") * @ORM\Id() @@ -87,6 +86,15 @@ class Task extends TaskModel * @Assert\Type("bool") */ protected $takeScreenshots; + /** + * @ORM\Column(name="created_at", type="datetime", nullable=true) + */ + protected $createdAt; + + /** + * @ORM\Column(name="updated_at", type="datetime", nullable=true) + */ + protected $updatedAt; public function __construct() { @@ -121,4 +129,21 @@ public function getReducer(): ReducerInterface { return new Reducer($this->reducer); } + + /** + * @ORM\PrePersist + */ + public function prePersist(): void + { + $this->createdAt = new DateTime(); + $this->updatedAt = new DateTime(); + } + + /** + * @ORM\PreUpdate + */ + public function preUpdate(): void + { + $this->updatedAt = new DateTime(); + } } diff --git a/src/Entity/TimestampableTrait.php b/src/Entity/TimestampableTrait.php deleted file mode 100644 index 3bb73be1..00000000 --- a/src/Entity/TimestampableTrait.php +++ /dev/null @@ -1,36 +0,0 @@ -createdAt = new DateTime(); - $this->updatedAt = new DateTime(); - } - - /** - * @ORM\PreUpdate - */ - public function preUpdate(): void - { - $this->updatedAt = new DateTime(); - } -} diff --git a/src/Model/Bug.php b/src/Model/Bug.php index 3110386d..0c6ed0cf 100644 --- a/src/Model/Bug.php +++ b/src/Model/Bug.php @@ -2,13 +2,12 @@ namespace Tienvx\Bundle\MbtBundle\Model; +use DateTimeInterface; use Tienvx\Bundle\MbtBundle\Steps\Steps; use Tienvx\Bundle\MbtBundle\Workflow\BugWorkflow; class Bug implements BugInterface { - use TimestampableTrait; - /** * @var int|null */ @@ -54,6 +53,16 @@ class Bug implements BugInterface */ protected $messagesCount = 0; + /** + * @var ?DateTimeInterface + */ + protected $updatedAt; + + /** + * @var ?DateTimeInterface + */ + protected $createdAt; + public function __construct() { $this->status = BugWorkflow::NEW; @@ -159,4 +168,28 @@ public function setMessagesCount(int $messagesCount): BugInterface return $this; } + + public function setCreatedAt(DateTimeInterface $createdAt): BugInterface + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getCreatedAt(): ?DateTimeInterface + { + return $this->createdAt; + } + + public function setUpdatedAt(DateTimeInterface $updatedAt): BugInterface + { + $this->updatedAt = $updatedAt; + + return $this; + } + + public function getUpdatedAt(): ?DateTimeInterface + { + return $this->updatedAt; + } } diff --git a/src/Model/BugInterface.php b/src/Model/BugInterface.php index 6f8774f4..0138021a 100644 --- a/src/Model/BugInterface.php +++ b/src/Model/BugInterface.php @@ -41,11 +41,11 @@ public function getMessagesCount(): int; public function setMessagesCount(int $messagesCount): self; - public function setCreatedAt(DateTimeInterface $createdAt): void; + public function setCreatedAt(DateTimeInterface $createdAt): self; public function getCreatedAt(): ?DateTimeInterface; - public function setUpdatedAt(DateTimeInterface $updatedAt): void; + public function setUpdatedAt(DateTimeInterface $updatedAt): self; public function getUpdatedAt(): ?DateTimeInterface; } diff --git a/src/Model/Task.php b/src/Model/Task.php index 62cad842..4ad67bbb 100644 --- a/src/Model/Task.php +++ b/src/Model/Task.php @@ -2,14 +2,13 @@ namespace Tienvx\Bundle\MbtBundle\Model; +use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Tienvx\Bundle\MbtBundle\Workflow\TaskWorkflow; class Task implements TaskInterface { - use TimestampableTrait; - /** * @var int|null */ @@ -60,6 +59,16 @@ class Task implements TaskInterface */ protected $takeScreenshots; + /** + * @var ?DateTimeInterface + */ + protected $updatedAt; + + /** + * @var ?DateTimeInterface + */ + protected $createdAt; + public function __construct() { $this->bugs = new ArrayCollection(); @@ -201,4 +210,28 @@ public function getTakeScreenshots(): bool { return $this->takeScreenshots; } + + public function setCreatedAt(DateTimeInterface $createdAt): TaskInterface + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getCreatedAt(): ?DateTimeInterface + { + return $this->createdAt; + } + + public function setUpdatedAt(DateTimeInterface $updatedAt): TaskInterface + { + $this->updatedAt = $updatedAt; + + return $this; + } + + public function getUpdatedAt(): ?DateTimeInterface + { + return $this->updatedAt; + } } diff --git a/src/Model/TaskInterface.php b/src/Model/TaskInterface.php index b9ba9bc7..0c708fc9 100644 --- a/src/Model/TaskInterface.php +++ b/src/Model/TaskInterface.php @@ -47,11 +47,11 @@ public function getTakeScreenshots(): bool; public function setTakeScreenshots(bool $takeScreenshots): self; - public function setCreatedAt(DateTimeInterface $createdAt): void; + public function setCreatedAt(DateTimeInterface $createdAt): self; public function getCreatedAt(): ?DateTimeInterface; - public function setUpdatedAt(DateTimeInterface $updatedAt): void; + public function setUpdatedAt(DateTimeInterface $updatedAt): self; public function getUpdatedAt(): ?DateTimeInterface; } diff --git a/src/Model/TimestampableTrait.php b/src/Model/TimestampableTrait.php deleted file mode 100644 index c00dbe18..00000000 --- a/src/Model/TimestampableTrait.php +++ /dev/null @@ -1,38 +0,0 @@ -createdAt = $createdAt; - } - - public function getCreatedAt(): ?DateTimeInterface - { - return $this->createdAt; - } - - public function setUpdatedAt(DateTimeInterface $updatedAt): void - { - $this->updatedAt = $updatedAt; - } - - public function getUpdatedAt(): ?DateTimeInterface - { - return $this->updatedAt; - } -}