Passed
Pull Request — 8.x-2.x (#26)
by Frédéric G.
02:49
created

EventTemplateForm::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\mongodb_watchdog\Form;
4
5
use Drupal\Core\Entity\ContentEntityForm;
6
use Drupal\Core\Form\FormStateInterface;
7
8
/**
9
 * Form controller for Event template edit forms.
10
 *
11
 * @ingroup mongodb_watchdog
12
 */
13
class EventTemplateForm extends ContentEntityForm {
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function buildForm(array $form, FormStateInterface $form_state) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
    /* @var $entity \Drupal\mongodb_watchdog\Entity\EventTemplate */
20
    $form = parent::buildForm($form, $form_state);
21
    $entity = $this->entity;
0 ignored issues
show
Unused Code introduced by
$entity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
22
23
    return $form;
24
  }
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  public function save(array $form, FormStateInterface $form_state) {
30
    $entity = $this->entity;
31
    $status = parent::save($form, $form_state);
32
33
    switch ($status) {
34
      case SAVED_NEW:
35
        drupal_set_message($this->t('Created the %label Event template.', [
36
          '%label' => $entity->label(),
37
        ]));
38
        break;
39
40
      default:
41
        drupal_set_message($this->t('Saved the %label Event template.', [
42
          '%label' => $entity->label(),
43
        ]));
44
    }
45
    $form_state->setRedirect('entity.mongodb_watchdog_event_template.canonical', ['mongodb_watchdog_event_template' => $entity->id()]);
46
  }
47
48
}
49