src/Domain/Whater/Model/AnalyticalParameter.php line 17

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Whater\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Ramsey\Uuid\Uuid;
  8. use Whater\Domain\Common\Exception\InvalidUUIDException;
  9. /**
  10. * Class AnalyticalParameter
  11. *
  12. * @package Whater\Domain\Whater\Model
  13. */
  14. class AnalyticalParameter implements ContainsRecordedEvents
  15. {
  16. use EventRecorderCapabilities;
  17. /**
  18. * @var string
  19. */
  20. private $uuid;
  21. /**
  22. * @var string
  23. */
  24. private $parameterCode;
  25. /**
  26. * @var string
  27. */
  28. private $parameterName;
  29. /**
  30. * @var string
  31. */
  32. private $parameterMetric;
  33. /**
  34. * @var float
  35. */
  36. private $referenceMinValue;
  37. /**
  38. * @var float
  39. */
  40. private $referenceMaxValue;
  41. /**
  42. * @var float
  43. */
  44. private $limitMinValue;
  45. /**
  46. * @var float
  47. */
  48. private $limitMaxValue;
  49. /**
  50. * @var \DateTime
  51. */
  52. private $createdAt;
  53. public function __construct(
  54. string $analyticalParameterId = null,
  55. string $parameterCode,
  56. string $parameterName,
  57. string $parameterMetric,
  58. float $referenceMinValue = null,
  59. float $referenceMaxValue = null,
  60. float $limitMinValue = null,
  61. float $limitMaxValue = null
  62. ) {
  63. try {
  64. $this->uuid = Uuid::fromString($analyticalParameterId ?: Uuid::uuid4())->toString();
  65. } catch (\InvalidArgumentException $e) {
  66. throw new InvalidUUIDException();
  67. }
  68. $this->parameterCode = $parameterCode;
  69. $this->parameterName = $parameterName;
  70. $this->parameterMetric = $parameterMetric;
  71. $this->referenceMinValue = $referenceMinValue;
  72. $this->referenceMaxValue = $referenceMaxValue;
  73. $this->limitMinValue = $limitMinValue;
  74. $this->limitMaxValue = $limitMaxValue;
  75. $this->createdAt = new \DateTime();
  76. }
  77. public function updateAnalyticalParameter(
  78. string $parameterName,
  79. string $parameterMetric,
  80. float $referenceMinValue = null,
  81. float $referenceMaxValue = null,
  82. float $limitMinValue = null,
  83. float $limitMaxValue = null
  84. ) {
  85. $this->parameterName = $parameterName;
  86. $this->parameterMetric = $parameterMetric;
  87. $this->referenceMinValue = $referenceMinValue;
  88. $this->referenceMaxValue = $referenceMaxValue;
  89. $this->limitMinValue = $limitMinValue;
  90. $this->limitMaxValue = $limitMaxValue;
  91. }
  92. /**
  93. * @return string
  94. */
  95. public function id(): string
  96. {
  97. return $this->uuid;
  98. }
  99. /**
  100. * @return string
  101. */
  102. public function parameterCode(): string
  103. {
  104. return $this->parameterCode;
  105. }
  106. /**
  107. * @return string
  108. */
  109. public function parameterName(): string
  110. {
  111. return $this->parameterName;
  112. }
  113. /**
  114. * @return string
  115. */
  116. public function parameterMetric(): string
  117. {
  118. return $this->parameterMetric;
  119. }
  120. /**
  121. * @return float
  122. */
  123. public function referenceMinValue(): ?float
  124. {
  125. return $this->referenceMinValue;
  126. }
  127. /**
  128. * @return float
  129. */
  130. public function referenceMaxValue(): ?float
  131. {
  132. return $this->referenceMaxValue;
  133. }
  134. /**
  135. * @return float
  136. */
  137. public function limitMinValue(): ?float
  138. {
  139. return $this->limitMinValue;
  140. }
  141. /**
  142. * @return float
  143. */
  144. public function limitMaxValue(): ?float
  145. {
  146. return $this->limitMaxValue;
  147. }
  148. /**
  149. * @return \DateTime
  150. */
  151. public function createdAt(): \DateTime
  152. {
  153. return $this->createdAt;
  154. }
  155. /**
  156. * @return bool
  157. */
  158. public function equals(AnalyticalParameter $analyticalParameter)
  159. {
  160. return $this->id() === $analyticalParameter->id();
  161. }
  162. }