CLogExample.php ➔ calculateBigSum()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
//
4
// Set the error reporting.
5
//
6
error_reporting(-1);              // Report all type of errors
7
ini_set('output_buffering', 0);   // Do not buffer outputs, write directly
8
9
//
10
// Get required files
11
//
12
require "../src/Logger/CLog.php";
13
14
// Create new CLog object, set precision to 3 decimals (default is 3)
15
$log = new \ultimadark\Logger\CLog(3);
16
17
$log->timestamp("ExampleClass", "Beginning of file");
18
19
// Calculate some meaningless stuff
20
$log->timestamp("ExampleClass", "calculateBigSum", "Before summing");
21
calculateBigSum();
0 ignored issues
show
Unused Code introduced by
The call to the function calculateBigSum() seems unnecessary as the function has no side-effects.
Loading history...
22
$log->timestamp("ExampleClass", "calculateBigSum", "After summing");
23
24
$log->timestamp("ExampleClass", "End of file");
25
26
// Print log
27
echo $log->timestampAsTable();
28
29
30
function calculateBigSum()
31
{    
32
    $sum = 0;
33
    for ($i = 0; $i < 500000; $i++) {
34
        $sum += $i;
35
    }    
36
}