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

NewChatMessageFormFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 21
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

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 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
?>