Completed
Push — 7.x-1.x ( 2f9e3c...1070be )
by Frédéric G.
01:36
created

Pass::record()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 1
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\qa;
4
5
/**
6
 * A control pass.
7
 */
8
class Pass {
9
  /**
10
   * The control of which this is a pass
11
   *
12
   * @var \Drupal\qa\Plugin\Qa\Control\BaseControl
13
   */
14
  public $control;
15
16
  /**
17
   * The user who ran the pass.
18
   *
19
   * This is normally a stdClass with a $uid public member.
20
   *
21
   * @var object
22
   */
23
  public $account;
24
25
  /**
26
   * The pass lifecycle
27
   *
28
   * @var \Drupal\qa\Same
29
   */
30
  public $life;
31
32
  /**
33
   * Success or failure
34
   *
35
   * @var int
36
   *   - NULL: undefined
37
   *   - 0: failure
38
   *   - 1: success
39
   */
40
  public $status;
41
42
  /**
43
   * Render array for the results
44
   *
45
   * @param array
46
   */
47
  public $result;
48
49
  /**
50
   * @param \Drupal\qa\Plugin\Qa\Control\BaseControl $control
51
   */
52
  function __construct($control) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
    $this->life = new Same();
54
    $this->status = NULL;
55
    $this->control = $control;
56
    $this->account = $GLOBALS['user'];
57
    $this->result = array();
58
  }
59
60
  /**
61
   * Record results from one of the checks in a control pass
62
   *
63
   * @param array $check
64
   *   - status: 0 or 1
65
   *   - result: render array
66
   *
67
   * @return void
68
   */
69
  function record($check) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
    if (!$check['status']) {
71
      $this->status = 0;
72
      if (isset($check['name'])) {
73
        $this->result[$check['name']] = $check['result'];
74
      }
75
      else {
76
        $this->result[] = $check['result'];
77
      }
78
    }
79
    elseif (!isset($this->status)) {
80
      $this->status = 1;
81
    }
82
    $this->life->modify();
83
  }
84
}
85