Skip to content

Commit

Permalink
Rename MonthelableTrait as MonthYearTrait and add interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-ducrot committed Sep 19, 2024
1 parent 1d61f9f commit fb3b655
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG_add_trait_monthelable_and_created.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
### Added
`Entity::CreatableTrait` Trait with creation date
`Entity::MonthelableTrait` Trait with numeric representation of a month and his numeric year. Useful for statistics purposes.
`Entity::CreatableTrait` Trait & interface with creation date
`Entity::MonthYearTrait` Trait & interface with numeric representation of a month and his numeric year. Useful for statistics purposes.
11 changes: 11 additions & 0 deletions src/Entity/CreatableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Smart\CoreBundle\Entity;


interface CreatableInterface
{
public function getCreatedAt(): ?\DateTime;

public function setCreatedAt(?\DateTime $createdAt): static;
}
2 changes: 1 addition & 1 deletion src/Entity/CreatableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait CreatableTrait
* @ORM\Column(name="created_at", type="datetime")
*/
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTime $createdAt = null;
protected ?\DateTime $createdAt = null;

public function getCreatedAt(): ?\DateTime
{
Expand Down
18 changes: 18 additions & 0 deletions src/Entity/MonthYearInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Smart\CoreBundle\Entity;

interface MonthYearInterface
{
public function getMonth(): int;

public function setMonth(int $month): void;

public function getYear(): int;

public function setYear(int $year): void;

public function setMonthYearFromDate(\DateTime $date): void;

public function getFormattedMonth(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Smart\CoreBundle\Utils\DateUtils;
use Symfony\Component\Validator\Constraints as Assert;

trait MonthelableTrait
trait MonthYearTrait
{
/**
* @ORM\Column(type="integer", nullable=true)
Expand Down Expand Up @@ -45,7 +45,7 @@ public function setYear(int $year): void
$this->year = $year;
}

public function setMonthelableDate(\DateTime $date): void
public function setMonthYearFromDate(\DateTime $date): void
{
$this->month = (int) $date->format('n');
$this->year = (int) $date->format('Y');
Expand Down

0 comments on commit fb3b655

Please sign in to comment.