Completed
Push — master ( 65ec1d...8a8a83 )
by Jakub
05:39
created

NewChatMessageFormFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 13
c 2
b 0
f 1
dl 0
loc 20
ccs 10
cts 13
cp 0.7692
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A create() 0 13 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Chat;
5
6
use Nette\Application\UI\Form;
7
use Nette\Localization\ITranslator;
8
9
/**
10
 * NewChatMessageFormFactory
11
 *
12
 * @author Jakub Konečný
13
 */
14
final class NewChatMessageFormFactory {
15
  protected ITranslator $translator;
16
  
17
  public function __construct(ITranslator $translator) {
18 1
    $this->translator = $translator;
19 1
  }
20
  
21
  public function create(ChatControl $chatControl): Form {
22 1
    $form = new Form();
23 1
    $form->setTranslator($this->translator);
24 1
    $form->addText("message", "")
25 1
      ->setRequired("chat.newMessageForm.messageField.empty");
26 1
    $form->addSubmit("send", "chat.newMessageForm.submitButton.label");
27 1
    $form->addComponent($chatControl, "chat");
28 1
    $form->onSuccess[] = function(Form $form, array $values): void {
29
      /** @var ChatControl $chat */
30
      $chat = $form->getComponent("chat");
31
      $chat->newMessage($values["message"]);
32
    };
33 1
    return $form;
34
  }
35
}
36
?>