| Total Complexity | 9 |
| Total Lines | 82 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class SellForm extends Widget |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | public $actionUrl; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | public $validationUrl; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var Server[]|HubSellForm[] |
||
| 25 | */ |
||
| 26 | private $models = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function run() |
||
| 32 | { |
||
| 33 | return $this->render('SellForm', [ |
||
| 34 | 'defaultDateTime' => $this->getDefaultDateTime(), |
||
| 35 | 'model' => \reset($this->getModels()), |
||
| 36 | 'models' => $this->getModels(), |
||
| 37 | 'actionUrl' => $this->getActionUrl(), |
||
| 38 | 'validationUrl' => $this->getValidationUrl(), |
||
| 39 | ]); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return array |
||
| 44 | */ |
||
| 45 | public function getModels(): array |
||
| 46 | { |
||
| 47 | if ($this->isServer()) { |
||
| 48 | return ServerSort::byServerName()->values($this->models); |
||
| 49 | } |
||
| 50 | |||
| 51 | return $this->models; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param array $models |
||
| 56 | */ |
||
| 57 | public function setModels(array $models): void |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return bool |
||
| 64 | */ |
||
| 65 | public function isServer(): bool |
||
| 66 | { |
||
| 67 | return \count($this->models) > 0 && \reset($this->models) instanceof Server; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return DateTime |
||
| 72 | * @throws \Exception |
||
| 73 | */ |
||
| 74 | private function getDefaultDateTime(): DateTime |
||
| 75 | { |
||
| 76 | return new DateTime('first day of this month 00:00'); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | private function getActionUrl(): string |
||
| 83 | { |
||
| 84 | return $this->actionUrl; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | private function getValidationUrl(): string |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 |