From 455d7720959a9758878480f4443d8d084ce0c9c8 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 2 May 2019 18:03:40 +0200 Subject: [PATCH] moved shared entity fields and functions to trait (#750) --- config/packages/doctrine.yaml | 4 +- src/Entity/Activity.php | 55 +-------------------------- src/Entity/Customer.php | 55 +-------------------------- src/Entity/Project.php | 55 +-------------------------- src/Entity/RatesTrait.php | 70 +++++++++++++++++++++++++++++++++++ src/Entity/Timesheet.php | 55 +-------------------------- symfony.lock | 12 ++++-- 7 files changed, 89 insertions(+), 217 deletions(-) create mode 100644 src/Entity/RatesTrait.php diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 60809917..f4bcb7d1 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -12,7 +12,9 @@ doctrine: default: url: '%env(resolve:DATABASE_URL)%' driver: 'pdo_mysql' - server_version: '5.7' + # this setting prevents automatic database detection and finds a lot of false-negatives on doctrine:migrations:diff + # for null columns with MariaDB. Each migration tries to convert EVERY nullable column. + # server_version: '5.7' charset: utf8mb4 default_table_options: charset: utf8mb4 diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index 0edca238..db409350 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -66,21 +66,8 @@ class Activity */ private $timesheets; - /** - * @var float - * - * @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $fixedRate = null; - - /** - * @var float - * - * @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $hourlyRate = null; + // keep the trait include exactly here, for placing the column at the correct position + use RatesTrait; /** * @return int @@ -174,44 +161,6 @@ class Activity return $this->visible; } - /** - * @return float - */ - public function getFixedRate(): ?float - { - return $this->fixedRate; - } - - /** - * @param float $fixedRate - * @return Activity - */ - public function setFixedRate(?float $fixedRate) - { - $this->fixedRate = $fixedRate; - - return $this; - } - - /** - * @return float - */ - public function getHourlyRate(): ?float - { - return $this->hourlyRate; - } - - /** - * @param float $hourlyRate - * @return Activity - */ - public function setHourlyRate(?float $hourlyRate) - { - $this->hourlyRate = $hourlyRate; - - return $this; - } - /** * @return string */ diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 993bb5a5..797de74e 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -147,21 +147,8 @@ class Customer */ private $timezone; - /** - * @var float - * - * @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $fixedRate = null; - - /** - * @var float - * - * @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $hourlyRate = null; + // keep the trait include exactly here, for placing the column at the correct position + use RatesTrait; /** * @return int @@ -523,44 +510,6 @@ class Customer return $this->projects; } - /** - * @return float - */ - public function getFixedRate(): ?float - { - return $this->fixedRate; - } - - /** - * @param float $fixedRate - * @return Customer - */ - public function setFixedRate(?float $fixedRate) - { - $this->fixedRate = $fixedRate; - - return $this; - } - - /** - * @return float - */ - public function getHourlyRate(): ?float - { - return $this->hourlyRate; - } - - /** - * @param float $hourlyRate - * @return Customer - */ - public function setHourlyRate(?float $hourlyRate) - { - $this->hourlyRate = $hourlyRate; - - return $this; - } - /** * @return string */ diff --git a/src/Entity/Project.php b/src/Entity/Project.php index a7bf75c3..6ea37beb 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -83,21 +83,8 @@ class Project */ private $activities; - /** - * @var float - * - * @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $fixedRate = null; - - /** - * @var float - * - * @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $hourlyRate = null; + // keep the trait include exactly here, for placing the column at the correct position + use RatesTrait; /** * @var Timesheet[] @@ -266,44 +253,6 @@ class Project return $this; } - /** - * @return float - */ - public function getFixedRate(): ?float - { - return $this->fixedRate; - } - - /** - * @param float $fixedRate - * @return Project - */ - public function setFixedRate(?float $fixedRate) - { - $this->fixedRate = $fixedRate; - - return $this; - } - - /** - * @return float - */ - public function getHourlyRate(): ?float - { - return $this->hourlyRate; - } - - /** - * @param float $hourlyRate - * @return Project - */ - public function setHourlyRate(?float $hourlyRate) - { - $this->hourlyRate = $hourlyRate; - - return $this; - } - /** * @return string */ diff --git a/src/Entity/RatesTrait.php b/src/Entity/RatesTrait.php new file mode 100644 index 00000000..b3e924e1 --- /dev/null +++ b/src/Entity/RatesTrait.php @@ -0,0 +1,70 @@ +fixedRate; + } + + /** + * @param float $fixedRate + * @return self + */ + public function setFixedRate(?float $fixedRate) + { + $this->fixedRate = $fixedRate; + + return $this; + } + + /** + * @return float + */ + public function getHourlyRate(): ?float + { + return $this->hourlyRate; + } + + /** + * @param float $hourlyRate + * @return self + */ + public function setHourlyRate(?float $hourlyRate) + { + $this->hourlyRate = $hourlyRate; + + return $this; + } +} diff --git a/src/Entity/Timesheet.php b/src/Entity/Timesheet.php index 91574964..c3a02282 100644 --- a/src/Entity/Timesheet.php +++ b/src/Entity/Timesheet.php @@ -111,21 +111,8 @@ class Timesheet */ private $rate = 0.00; - /** - * @var float - * - * @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $fixedRate = null; - - /** - * @var float - * - * @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true) - * @Assert\GreaterThanOrEqual(0) - */ - private $hourlyRate = null; + // keep the trait include exactly here, for placing the column at the correct position + use RatesTrait; /** * @var bool @@ -332,44 +319,6 @@ class Timesheet return $this->rate; } - /** - * @return float - */ - public function getFixedRate(): ?float - { - return $this->fixedRate; - } - - /** - * @param float $fixedRate - * @return Timesheet - */ - public function setFixedRate(?float $fixedRate) - { - $this->fixedRate = $fixedRate; - - return $this; - } - - /** - * @return float - */ - public function getHourlyRate(): ?float - { - return $this->hourlyRate; - } - - /** - * @param float $hourlyRate - * @return Timesheet - */ - public function setHourlyRate(?float $hourlyRate) - { - $this->hourlyRate = $hourlyRate; - - return $this; - } - /** * @return bool */ diff --git a/symfony.lock b/symfony.lock index a58ec314..2e6c2d53 100644 --- a/symfony.lock +++ b/symfony.lock @@ -72,7 +72,11 @@ "branch": "master", "version": "1.2", "ref": "c1431086fec31f17fbcfe6d6d7e92059458facc1" - } + }, + "files": [ + "config/packages/doctrine_migrations.yaml", + "src/Migrations/.gitignore" + ] }, "doctrine/event-manager": { "version": "v1.0.0" @@ -87,10 +91,10 @@ "version": "v1.0.1" }, "doctrine/migrations": { - "version": "v1.6.2" + "version": "v2.0.2" }, "doctrine/orm": { - "version": "v2.6.0" + "version": "v2.6.3" }, "doctrine/persistence": { "version": "v1.0.0" @@ -495,7 +499,7 @@ "version": "v4.0.3" }, "symfony/orm-pack": { - "version": "v1.0.5" + "version": "v1.0.6" }, "symfony/phpunit-bridge": { "version": "3.3",