Passed
Push — master ( 5fd967...610a73 )
by Jakub
02:01
created

NewChatMessageFormFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 1
final class NewChatMessageFormFactory {
15
  /** @var ITranslator */
16
  protected $translator;
17
  
18
  public function __construct(ITranslator $translator) {
19 1
    $this->translator = $translator;
20 1
  }
21
  
22
  public function create(ChatControl $chatControl): Form {
23 1
    $form = new Form();
24 1
    $form->setTranslator($this->translator);
25 1
    $form->addText("message", "")
26 1
      ->setRequired("chat.newMessageForm.messageField.empty");
27 1
    $form->addSubmit("send", "chat.newMessageForm.submitButton.label");
28 1
    $form->addComponent($chatControl, "chat");
29 1
    $form->onSuccess[] = function(Form $form, array $values) {
30
      /** @var ChatControl $chat */
31
      $chat = $form->getComponent("chat");
32
      $chat->newMessage($values["message"]);
33
    };
34 1
    return $form;
35
  }
36
}
37
?>