CLog   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 53.56%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 78
ccs 15
cts 28
cp 0.5356
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A Timestamp() 0 15 2
A getTimestamp() 0 3 1
A getPageLoadTime() 0 6 1
A getMemoryPeak() 0 4 1
A saySomething() 0 3 1
1
<?php
2
namespace Mcknubb\Log;
3
/**
4
 * 
5
 * CLog
6
 *
7
 */
8
class CLog
9
{
10
  /**
11
   * Properties
12
   *
13
   */
14
  private $timestamp = array();
15
  private $pos = 0;
16
17
  /**
18
   * Constructor
19
   *
20
   */
21 1
  public function __construct() {
22 1
  }
23
24
  /**
25
   * Timestamp, log a event with a time.
26
   *
27
   * @param string $domain is the module or class.
28
   * @param string $where a more specific place in the domain.
29
   * @param string $comment on the timestamp.
30
   *
31
   */
32 1
  public function Timestamp($domain, $where, $comment=null) {
33 1
    $now = microtime(true);
34 1
    $this->timestamp[] = array(
35 1
      'domain'  => $domain,
36 1
      'where'   => $where,
37 1
      'comment' => $comment,
38 1
      'when'    => $now,
39 1
      'memory'  => memory_get_usage(true),
40
    );
41 1
    if($this->pos) {
42
      $this->timestamp[$this->pos - 1]['memory-peak'] = memory_get_peak_usage(true);
43
      $this->timestamp[$this->pos - 1]['duration']    = $now - $this->timestamp[$this->pos - 1]['when'];
44
    } 
45 1
    $this->pos++;
46 1
  }
47
48
  /**
49
   *
50
   */
51 1
  public function getTimestamp() {
52 1
  	return $this->timestamp;
53
  }
54
55
  /**
56
   * Print page load time.
57
   *
58
   * @return string with the page load time.
59
   *
60
   */
61
  public function getPageLoadTime() {
62
    $first = $this->timestamp[0]['when'];
63
    $last = $this->timestamp[count($this->timestamp) - 1]['when'];
64
    $loadtime = round($last - $first, 3);
65
    return $loadtime;
66
  }
67
68
  /**
69
   * Print memory peak.
70
   *
71
   * @return string with the memory peak.
72
   *
73
   */
74
  public function getMemoryPeak() {
75
    $peek = round(memory_get_peak_usage(true) / 1024 / 1024, 2);
76
    return $peek;
77
  }
78
79
  /*
80
    * Test if class is loaded
81
    */
82
    public function saySomething($word) {
83
        echo $word;
84
    }
85
}
86