Completed
Push — develop ( b91125...52c290 )
by Seth
03:00
created

Schedule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSyncTimestamp() 0 14 3
1
<?php
2
3
namespace smtech\CanvasICSSync\SyncIntoCanvas;
4
5
class Schedule
6
{
7
    protected $syncTimestamp;
8
9
    /**
10
     * Generate a unique identifier for this synchronization pass
11
     **/
12
    public function getSyncTimestamp()
0 ignored issues
show
Coding Style introduced by
getSyncTimestamp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
13
    {
14
        if (empty($this->syncTimestamp)) {
15
            $timestamp = new DateTime();
16
            $this->syncTimestamp =
17
                $timestamp->format(Constants::SYNC_TIMESTAMP_FORMAT) .
18
                Constants::SEPARATOR . md5(
19
                    (php_sapi_name() == 'cli' ?
20
                        'cli' : $_SERVER['REMOTE_ADDR']
21
                    ) . time()
22
                );
23
        }
24
        return $this->syncTimestamp;
25
    }
26
}
27