Skip to content

Commit

Permalink
* replace all patterns of setter(getter()) with plain assignment be…
Browse files Browse the repository at this point in the history
…tween props to reduce the overhead of invoking g/setter methods @ `App\DTO`

* expand visibility for props of entities with DTO from `private` to `protected` @ `App\Entity`
@ be
  • Loading branch information
n0099 committed Oct 25, 2024
1 parent 607bd97 commit be0d48b
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 70 deletions.
10 changes: 5 additions & 5 deletions be/src/DTO/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ trait Post
public static function fromEntity(\App\Entity\Post\Post $entity): self
{
$dto = self::fromTimestampedEntity($entity);
$dto->setAuthorUid($entity->getAuthorUid());
$dto->setPostedAt($entity->getPostedAt());
$dto->setLastSeenAt($entity->getLastSeenAt());
$dto->setAgreeCount($entity->getAgreeCount());
$dto->setDisagreeCount($entity->getDisagreeCount());
$dto->authorUid = $entity->authorUid;
$dto->postedAt = $entity->postedAt;
$dto->lastSeenAt = $entity->lastSeenAt;
$dto->agreeCount = $entity->agreeCount;
$dto->disagreeCount = $entity->disagreeCount;
return $dto;
}
}
12 changes: 6 additions & 6 deletions be/src/DTO/Post/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class Reply extends ReplyEntity
public static function fromEntity(ReplyEntity $entity): self
{
$dto = self::fromPostEntity($entity);
$dto->setTid($entity->getTid());
$dto->setPid($entity->getPid());
$dto->setFloor($entity->getFloor());
$dto->setSubReplyCount($entity->getSubReplyCount());
$dto->setIsFold($entity->getIsFold());
$dto->tid = $entity->tid;
$dto->pid = $entity->pid;
$dto->floor = $entity->floor;
$dto->subReplyCount = $entity->subReplyCount;
$dto->isFold = $entity->isFold;
$dto->geolocation = $entity->geolocation;
$dto->setSignatureId($entity->getSignatureId());
$dto->signatureId = $entity->signatureId;
return $dto;
}
}
6 changes: 3 additions & 3 deletions be/src/DTO/Post/SubReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class SubReply extends SubReplyEntity
public static function fromEntity(SubReplyEntity $entity): self
{
$dto = self::fromPostEntity($entity);
$dto->setTid($entity->getTid());
$dto->setPid($entity->getPid());
$dto->setSpid($entity->getSpid());
$dto->tid = $entity->tid;
$dto->pid = $entity->pid;
$dto->spid = $entity->spid;
return $dto;
}

Expand Down
24 changes: 12 additions & 12 deletions be/src/DTO/Post/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class Thread extends ThreadEntity
public static function fromEntity(ThreadEntity $entity): self
{
$dto = self::fromPostEntity($entity);
$dto->setTid($entity->getTid());
$dto->setThreadType($entity->getThreadType());
$dto->setStickyType($entity->getStickyType());
$dto->setTopicType($entity->getTopicType());
$dto->setIsGood($entity->getIsGood());
$dto->setTitle($entity->getTitle());
$dto->setLatestReplyPostedAt($entity->getLatestReplyPostedAt());
$dto->setLatestReplierId($entity->getLatestReplierId());
$dto->setReplyCount($entity->getReplyCount());
$dto->setViewCount($entity->getViewCount());
$dto->setShareCount($entity->getShareCount());
$dto->tid = $entity->tid;
$dto->threadType = $entity->threadType;
$dto->stickyType = $entity->stickyType;
$dto->topicType = $entity->topicType;
$dto->isGood = $entity->isGood;
$dto->title = $entity->title;
$dto->latestReplyPostedAt = $entity->latestReplyPostedAt;
$dto->latestReplierId = $entity->latestReplierId;
$dto->replyCount = $entity->replyCount;
$dto->viewCount = $entity->viewCount;
$dto->shareCount = $entity->shareCount;
$dto->zan = $entity->zan;
$dto->geolocation = $entity->geolocation;
$dto->setAuthorPhoneType($entity->getAuthorPhoneType());
$dto->authorPhoneType = $entity->authorPhoneType;
return $dto;
}
}
4 changes: 2 additions & 2 deletions be/src/DTO/TimestampedDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ trait TimestampedDTO
public static function fromEntity(TimestampedEntity $entity): self
{
$dto = new self();
$dto->setCreatedAt($entity->getCreatedAt());
$dto->setUpdatedAt($entity->getUpdatedAt());
$dto->createdAt = $entity->createdAt;
$dto->updatedAt = $entity->updatedAt;
return $dto;
}
}
14 changes: 7 additions & 7 deletions be/src/DTO/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function setCurrentAuthorExpGrade(?AuthorExpGrade $currentAuthorExpGrade)
public static function fromEntity(UserEntity $entity): self
{
$dto = self::fromTimestampedEntity($entity);
$dto->setUid($entity->getUid());
$dto->setName($entity->getName());
$dto->uid = $entity->uid;
$dto->name = $entity->name;
$dto->displayName = $entity->displayName;
$dto->setPortrait($entity->getPortrait());
$dto->setPortraitUpdatedAt($entity->getPortraitUpdatedAt());
$dto->setGender($entity->getGender());
$dto->setFansNickname($entity->getFansNickname());
$dto->portrait = $entity->portrait;
$dto->portraitUpdatedAt = $entity->portraitUpdatedAt;
$dto->gender = $entity->gender;
$dto->fansNickname = $entity->fansNickname;
$dto->icon = $entity->icon;
$dto->setIpGeolocation($entity->getIpGeolocation());
$dto->ipGeolocation = $entity->ipGeolocation;
return $dto;
}
}
10 changes: 5 additions & 5 deletions be/src/Entity/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#[ORM\MappedSuperclass]
abstract class Post extends TimestampedEntity
{
#[ORM\Column] private int $authorUid;
#[ORM\Column] private int $postedAt;
#[ORM\Column] private ?int $lastSeenAt;
#[ORM\Column] private ?int $agreeCount;
#[ORM\Column] private ?int $disagreeCount;
#[ORM\Column] protected int $authorUid;
#[ORM\Column] protected int $postedAt;
#[ORM\Column] protected ?int $lastSeenAt;
#[ORM\Column] protected ?int $agreeCount;
#[ORM\Column] protected ?int $disagreeCount;

public function getAuthorUid(): int
{
Expand Down
12 changes: 6 additions & 6 deletions be/src/Entity/Post/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#[ORM\Entity(repositoryClass: ReplyRepository::class)]
class Reply extends Post
{
#[ORM\Column] private int $tid;
#[ORM\Column, ORM\Id] private int $pid;
#[ORM\Column] private int $floor;
#[ORM\Column] private ?int $subReplyCount;
#[ORM\Column] private ?int $isFold;
#[ORM\Column] protected int $tid;
#[ORM\Column, ORM\Id] protected int $pid;
#[ORM\Column] protected int $floor;
#[ORM\Column] protected ?int $subReplyCount;
#[ORM\Column] protected ?int $isFold;
/** @var ?resource */
#[ORM\Column] protected $geolocation;
#[ORM\Column] private ?int $signatureId;
#[ORM\Column] protected ?int $signatureId;

public function getTid(): int
{
Expand Down
6 changes: 3 additions & 3 deletions be/src/Entity/Post/SubReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#[ORM\Entity(repositoryClass: SubReplyRepository::class)]
class SubReply extends Post
{
#[ORM\Column] private int $tid;
#[ORM\Column] private int $pid;
#[ORM\Column, ORM\Id] private int $spid;
#[ORM\Column] protected int $tid;
#[ORM\Column] protected int $pid;
#[ORM\Column, ORM\Id] protected int $spid;

public function getTid(): int
{
Expand Down
24 changes: 12 additions & 12 deletions be/src/Entity/Post/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
#[ORM\Entity(repositoryClass: ThreadRepository::class)]
class Thread extends Post
{
#[ORM\Column, ORM\Id] private int $tid;
#[ORM\Column] private int $threadType;
#[ORM\Column] private ?string $stickyType;
#[ORM\Column] private ?string $topicType;
#[ORM\Column] private ?int $isGood;
#[ORM\Column] private string $title;
#[ORM\Column] private int $latestReplyPostedAt;
#[ORM\Column] private ?int $latestReplierId;
#[ORM\Column] private ?int $replyCount;
#[ORM\Column] private ?int $viewCount;
#[ORM\Column] private ?int $shareCount;
#[ORM\Column, ORM\Id] protected int $tid;
#[ORM\Column] protected int $threadType;
#[ORM\Column] protected ?string $stickyType;
#[ORM\Column] protected ?string $topicType;
#[ORM\Column] protected ?int $isGood;
#[ORM\Column] protected string $title;
#[ORM\Column] protected int $latestReplyPostedAt;
#[ORM\Column] protected ?int $latestReplierId;
#[ORM\Column] protected ?int $replyCount;
#[ORM\Column] protected ?int $viewCount;
#[ORM\Column] protected ?int $shareCount;
/** @var ?resource */
#[ORM\Column] protected $zan;
/** @var ?resource */
#[ORM\Column] protected $geolocation;
#[ORM\Column] private ?string $authorPhoneType;
#[ORM\Column] protected ?string $authorPhoneType;

public function getTid(): int
{
Expand Down
4 changes: 2 additions & 2 deletions be/src/Entity/TimestampedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#[ORM\MappedSuperclass]
abstract class TimestampedEntity
{
#[ORM\Column] private int $createdAt;
#[ORM\Column] private ?int $updatedAt;
#[ORM\Column] protected int $createdAt;
#[ORM\Column] protected ?int $updatedAt;

public function getCreatedAt(): int
{
Expand Down
14 changes: 7 additions & 7 deletions be/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
#[ORM\Table(name: '"tbmc_user"')]
class User extends TimestampedEntity
{
#[ORM\Column, ORM\Id] private int $uid;
#[ORM\Column] private ?string $name;
#[ORM\Column, ORM\Id] protected int $uid;
#[ORM\Column] protected ?string $name;
/** @var ?resource */
#[ORM\Column] protected $displayName;
#[ORM\Column] private string $portrait;
#[ORM\Column] private ?int $portraitUpdatedAt;
#[ORM\Column] private ?int $gender;
#[ORM\Column] private ?string $fansNickname;
#[ORM\Column] protected string $portrait;
#[ORM\Column] protected ?int $portraitUpdatedAt;
#[ORM\Column] protected ?int $gender;
#[ORM\Column] protected ?string $fansNickname;
/** @var ?resource */
#[ORM\Column] protected $icon;
#[ORM\Column] private ?string $ipGeolocation;
#[ORM\Column] protected ?string $ipGeolocation;

public function getUid(): ?int
{
Expand Down

0 comments on commit be0d48b

Please sign in to comment.