From f47f0275dc2309a7d3a7cf762feb36e04b88d721 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Nov 2020 17:31:20 +0100 Subject: [PATCH] remove some getter/setter --- Models/Promotion.php | 70 ++----------------------- Theme/Backend/promotion-list.tpl.php | 2 +- Theme/Backend/promotion-profile.tpl.php | 2 +- tests/Models/PromotionMapperTest.php | 28 +++++----- tests/Models/PromotionTest.php | 14 ++--- 5 files changed, 27 insertions(+), 89 deletions(-) diff --git a/Models/Promotion.php b/Models/Promotion.php index 52d57b9..b150223 100755 --- a/Models/Promotion.php +++ b/Models/Promotion.php @@ -56,7 +56,7 @@ class Promotion * @var string * @since 1.0.0 */ - private string $description = ''; + public string $description = ''; private $calendar = null; @@ -78,7 +78,7 @@ class Promotion * @var \DateTimeImmutable * @since 1.0.0 */ - private \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; /** * Created by. @@ -86,7 +86,7 @@ class Promotion * @var Account * @since 1.0.0 */ - private Account $createdBy; + public Account $createdBy; private $tasks = []; @@ -368,33 +368,7 @@ class Promotion public function setName(string $name) : void { $this->name = $name; - $this->calendar->setName($name); - } - - /** - * Get description - * - * @return string - * - * @since 1.0.0 - */ - public function getDescription() : string - { - return $this->description; - } - - /** - * Set description - * - * @param string $description Description - * - * @return void - * - * @since 1.0.0 - */ - public function setDescription(string $description) : void - { - $this->description = $description; + $this->calendar->name = $name; } /** @@ -474,40 +448,4 @@ class Promotion { $this->earnings = $earnings; } - - /** - * Get created at - * - * @return \DateTimeImmutable - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTimeImmutable - { - return $this->createdAt; - } - - /** - * Get created by - * - * @return Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : Account - { - return $this->createdBy; - } - - /** - * Set creator - * - * @param Account $createdBy Creator - * - * @since 1.0.0 - */ - public function setCreatedBy(Account $createdBy) : void - { - $this->createdBy = $createdBy; - } } diff --git a/Theme/Backend/promotion-list.tpl.php b/Theme/Backend/promotion-list.tpl.php index 81c6730..e56d80c 100755 --- a/Theme/Backend/promotion-list.tpl.php +++ b/Theme/Backend/promotion-list.tpl.php @@ -35,7 +35,7 @@ echo $this->getData('nav')->render(); ?> $value) : ++$count; $url = \phpOMS\Uri\UriFactory::build('{/prefix}marketing/promotion/profile?{?}&id=' . $value->getId()); ?> - printHtml($value->getName()); ?> + printHtml($value->name); ?> printHtml($value->getStart()->format('Y-m-d')); ?> printHtml($value->getEnd()->format('Y-m-d')); ?> diff --git a/Theme/Backend/promotion-profile.tpl.php b/Theme/Backend/promotion-profile.tpl.php index 4eb8c28..836dff6 100755 --- a/Theme/Backend/promotion-profile.tpl.php +++ b/Theme/Backend/promotion-profile.tpl.php @@ -32,7 +32,7 @@ echo $this->getData('nav')->render(); ?> - + diff --git a/tests/Models/PromotionMapperTest.php b/tests/Models/PromotionMapperTest.php index b648d65..8cdcba8 100755 --- a/tests/Models/PromotionMapperTest.php +++ b/tests/Models/PromotionMapperTest.php @@ -36,8 +36,8 @@ class PromotionMapperTest extends \PHPUnit\Framework\TestCase $promotion = new Promotion(); $promotion->setName('Promotionname'); - $promotion->setDescription('Description'); - $promotion->setCreatedBy(new NullAccount(1)); + $promotion->description = 'Description'; + $promotion->createdBy = new NullAccount(1); $promotion->setStart(new \DateTime('2000-05-05')); $promotion->setEnd(new \DateTime('2005-05-05')); @@ -49,23 +49,23 @@ class PromotionMapperTest extends \PHPUnit\Framework\TestCase $promotion->setEarnings($money); $task = new Task(); - $task->setTitle('PromotionTask 1'); + $task->title = 'PromotionTask 1'; $task->setCreatedBy(new NullAccount(1)); $task2 = new Task(); - $task2->setTitle('PromotionTask 2'); + $task2->title = 'PromotionTask 2'; $task2->setCreatedBy(new NullAccount(1)); $promotion->addTask($task); $promotion->addTask($task2); $media = new Media(); - $media->setCreatedBy(new NullAccount(1)); - $media->setDescription('desc'); + $media->createdBy = new NullAccount(1); + $media->description = 'desc'; $media->setPath('some/path'); - $media->setSize(11); - $media->setExtension('png'); - $media->setName('Promotion Media'); + $media->size = 11; + $media->extension = 'png'; + $media->name = 'Promotion Media'; $promotion->addMedia($media); $id = PromotionMapper::create($promotion); @@ -75,19 +75,19 @@ class PromotionMapperTest extends \PHPUnit\Framework\TestCase $promotionR = PromotionMapper::get($promotion->getId()); self::assertEquals($promotion->getName(), $promotionR->getName()); - self::assertEquals($promotion->getDescription(), $promotionR->getDescription()); + self::assertEquals($promotion->description, $promotionR->description); self::assertEquals($promotion->countTasks(), $promotionR->countTasks()); self::assertEquals($promotion->getCosts()->getAmount(), $promotionR->getCosts()->getAmount()); self::assertEquals($promotion->getBudget()->getAmount(), $promotionR->getBudget()->getAmount()); self::assertEquals($promotion->getEarnings()->getAmount(), $promotionR->getEarnings()->getAmount()); - self::assertEquals($promotion->getCreatedAt()->format('Y-m-d'), $promotionR->getCreatedAt()->format('Y-m-d')); + self::assertEquals($promotion->createdAt->format('Y-m-d'), $promotionR->createdAt->format('Y-m-d')); self::assertEquals($promotion->getStart()->format('Y-m-d'), $promotionR->getStart()->format('Y-m-d')); self::assertEquals($promotion->getEnd()->format('Y-m-d'), $promotionR->getEnd()->format('Y-m-d')); $expected = $promotion->getMedia(); $actual = $promotionR->getMedia(); - self::assertEquals(\end($expected)->getName(), \end($actual)->getName()); + self::assertEquals(\end($expected)->name, \end($actual)->name); } /** @@ -114,8 +114,8 @@ class PromotionMapperTest extends \PHPUnit\Framework\TestCase $promotion = new Promotion(); $promotion->setName($text->generateText(\mt_rand(3, 7))); - $promotion->setDescription($text->generateText(\mt_rand(20, 100))); - $promotion->setCreatedBy(new NullAccount(1)); + $promotion->description = $text->generateText(\mt_rand(20, 100)); + $promotion->createdBy = new NullAccount(1); $promotion->setStart(new \DateTime('2000-05-05')); $promotion->setEnd(new \DateTime('2005-05-05')); diff --git a/tests/Models/PromotionTest.php b/tests/Models/PromotionTest.php index 7974f8d..328b181 100755 --- a/tests/Models/PromotionTest.php +++ b/tests/Models/PromotionTest.php @@ -34,12 +34,12 @@ class PromotionTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $promotion->getId()); self::assertInstanceOf('\Modules\Calendar\Models\Calendar', $promotion->getCalendar()); - self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->getCreatedAt()->format('Y-m-d')); + self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->createdAt->format('Y-m-d')); self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $promotion->getStart()->format('Y-m-d')); self::assertEquals((new \DateTime('now'))->modify('+1 month')->format('Y-m-d'), $promotion->getEnd()->format('Y-m-d')); - self::assertEquals(0, $promotion->getCreatedBy()->getId()); + self::assertEquals(0, $promotion->createdBy->getId()); self::assertEquals('', $promotion->getName()); - self::assertEquals('', $promotion->getDescription()); + self::assertEquals('', $promotion->description); self::assertEquals(0, $promotion->getCosts()->getInt()); self::assertEquals(0, $promotion->getBudget()->getInt()); self::assertEquals(0, $promotion->getEarnings()->getInt()); @@ -59,8 +59,8 @@ class PromotionTest extends \PHPUnit\Framework\TestCase $promotion->setName('Promotion'); self::assertEquals('Promotion', $promotion->getName()); - $promotion->setDescription('Description'); - self::assertEquals('Description', $promotion->getDescription()); + $promotion->description = 'Description'; + self::assertEquals('Description', $promotion->description); $promotion->setStart($date = new \DateTime('2000-05-05')); self::assertEquals($date->format('Y-m-d'), $promotion->getStart()->format('Y-m-d')); @@ -81,12 +81,12 @@ class PromotionTest extends \PHPUnit\Framework\TestCase self::assertEquals($money->getAmount(), $promotion->getEarnings()->getAmount()); $task = new Task(); - $task->setTitle('Promo Task A'); + $task->title = 'Promo Task A'; $task->setCreatedBy(new NullAccount(1)); $promotion->addTask($task); - self::assertEquals('Promo Task A', $promotion->getTask(0)->getTitle()); + self::assertEquals('Promo Task A', $promotion->getTask(0)->title); self::assertCount(1, $promotion->getTasks()); self::assertTrue($promotion->removeTask(0)); self::assertEquals(0, $promotion->countTasks());