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

Same::modify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\qa;
4
5
/**
6
 * A lifetime class.
7
 *
8
 * Properties are: Start, Access, Modify, End
9
 *
10
 *
11
 * Note: SAME is an old (ca 2005) OSInet PHP_lib class, which other modules may
12
 * have imported in a non-namespaced form.
13
 */
14
class Same {
15
  /**
16
   * Start time.
17
   *
18
   * @var int
19
   */
20
  public $s;
21
22
  /**
23
   * Access time.
24
   *
25
   * @var int
26
   */
27
  public $a;
28
29
  /**
30
   * Modification time.
31
   *
32
   * @var int
33
   */
34
  public $m;
35
36
  /**
37
   * End time.
38
   *
39
   * @var int
40
   */
41
  public $e;
42
43
  /**
44
   * Constructor
45
   *
46
   * S.A.M. default to current time, but E defaults to NULL.
47
   *
48
   * @param int $s
49
   * @param int $a
50
   * @param int $m
51
   * @param int $e
52
   */
53
  function __construct($s = NULL, $a = NULL, $m = NULL, $e = NULL) {
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...
54
    $now = time();
55
    foreach (array('s', 'a', 'm') as $ts) {
56
      $this->$ts = isset($$ts) ? $$ts : $now;
57
    }
58
  }
59
60
  /**
61
   * Update the access time.
62
   *
63
   * @param int $now
64
   */
65
  public function access($now = NULL) {
66
    $this->a = isset($now) ? $now : time();
67
  }
68
69
  /**
70
   * Update the modification time.
71
   *
72
   * @param int $now
73
   */
74
  public function modify($now = NULL) {
75
    if (!isset($now)) {
76
      $now = time();
77
    }
78
    $this->access($now);
79
    $this->m = $now;
80
  }
81
82
  /**
83
   * Update the end time.
84
   *
85
   * @param int $now
86
   */
87
  public function end($now = NULL) {
88
    if (!isset($now)) {
89
      $now = time();
90
    }
91
    $this->modify($now);
92
    $this->e = $now;
93
  }
94
}
95