EditBufferItem   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntity() 0 2 1
A __construct() 0 3 1
A save() 0 2 1
A overwrite() 0 2 1
1
<?php
2
3
namespace Drupal\paragraphs_editor\EditBuffer;
4
5
use Drupal\paragraphs\ParagraphInterface;
6
7
/**
8
 * Wraps paragraph edits with the buffer that will store those edits.
9
 */
10
class EditBufferItem implements EditBufferItemInterface {
11
12
  /**
13
   * The wrapped entity, containing any edits.
14
   *
15
   * @var \Drupal\paragraphs\ParagraphInterface
16
   */
17
  protected $entity;
18
19
  /**
20
   * The buffer that will be used to store the edits.
21
   *
22
   * @var \Drupal\paragraphs_editor\EditBuffer\EditBufferInterface
23
   */
24
  protected $buffer;
25
26
  /**
27
   * Creates an edit buffer item.
28
   *
29
   * @param \Drupal\paragraphs\ParagraphInterface $entity
30
   *   The entity to wrap.
31
   * @param \Drupal\paragraphs_editor\EditBuffer\EditBufferInterface $buffer
32
   *   The buffer that will store edits.
33
   */
34
  public function __construct(ParagraphInterface $entity, EditBufferInterface $buffer) {
35
    $this->entity = $entity;
36
    $this->buffer = $buffer;
37
  }
38
39
  /**
40
   * {@inheritdoc}
41
   */
42
  public function getEntity() {
43
    return $this->entity;
44
  }
45
46
  /**
47
   * {@inheritdoc}
48
   */
49
  public function overwrite(ParagraphInterface $entity) {
50
    $this->entity = $entity;
51
  }
52
53
  /**
54
   * {@inheritdoc}
55
   */
56
  public function save() {
57
    $this->buffer->setItem($this)->save();
58
  }
59
60
}
61