Completed
Push — 8.x-3.x ( 32ff4d...d01c55 )
by Sebastian
05:23 queued 02:25
created

EntityCrudOutputWrapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getEntity() 0 3 1
A getViolations() 0 3 1
A getErrors() 0 3 1
1
<?php
2
3
namespace Drupal\graphql_core\GraphQL;
4
5
use Drupal\Core\Entity\EntityInterface;
6
use Symfony\Component\Validator\ConstraintViolationListInterface;
7
8
class EntityCrudOutputWrapper {
9
  /**
10
   * The create entity.
11
   *
12
   * @var \Drupal\Core\Entity\EntityInterface|NULL
13
   */
14
  protected $entity;
15
16
  /**
17
   * The constraint validation list.
18
   *
19
   * @var \Symfony\Component\Validator\ConstraintViolationListInterface|NULL
20
   */
21
  protected $violations;
22
23
  /**
24
   * An array of error messages.
25
   *
26
   * @var array|NULL
27
   */
28
  protected $errors;
29
30
  /**
31
   * Creates a CreateEntityOutputWrapper object.
32
   *
33
   * @param \Drupal\Core\Entity\EntityInterface|NULL $entity
34
   *   The entity object that has been created or NULL if creation failed.
35
   * @param \Symfony\Component\Validator\ConstraintViolationListInterface|NULL $violations
36
   *   The validation errors that occurred during creation or NULL if validation
37
   *   succeeded.
38
   * @param array|NULL $errors
39
   *   An array of non validation error messages. Can be used to provide
40
   *   additional error messages e.g. for access restrictions.
41
   */
42
  public function __construct(
43
    EntityInterface $entity = NULL,
44
    ConstraintViolationListInterface $violations = NULL,
45
    array $errors = NULL
46
  ) {
47
    $this->entity = $entity;
48
    $this->violations = $violations;
49
    $this->errors = $errors;
50
  }
51
52
  /**
53
   * Returns the entity that was created.
54
   *
55
   * @return \Drupal\Core\Entity\EntityInterface|NULL
56
   *   The created entity object or NULL if creation failed.
57
   */
58
  public function getEntity() {
59
    return $this->entity;
60
  }
61
62
  /**
63
   * Returns the constraint violations.
64
   *
65
   * @return \Symfony\Component\Validator\ConstraintViolationListInterface|NULL
66
   *   The constraint validations or NULL if validation passed.
67
   */
68
  public function getViolations() {
69
    return $this->violations;
70
  }
71
72
  /**
73
   * Returns a list of error messages that occurred during entity creation.
74
   *
75
   * @return array|NULL
76
   *   An array of error messages as plain strings.
77
   */
78
  public function getErrors() {
79
    return $this->errors;
80
  }
81
82
}
83