Completed
Pull Request — master (#664)
by
unknown
05:50 queued 52s
created

SS_Datetimezone   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B Nice() 0 13 6
1
<?php
2
/**
3
 * Class SS_Datetimezone
4
 *
5
 * Adds customisable timezones to the nice method on {@link SS_Datetime}.
6
 */
7
class SS_Datetimezone extends SS_Datetime
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
    * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04”
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
11
    */
12
    public function Nice() {
13
        if($timestamp = $this){
14
            //instantiate new DateTime object based off received timestamp in the default timezone
15
            $timestamp = new DateTime($timestamp, new DateTimeZone(date_default_timezone_get()));
16
            //if a user is logged in, has set a timezone that is in the allowed list and 
17
            //that timezone is NOT the default one then convert the timestamp to use the selected timezone
18
            if(Member::currentUserID() && isset(Member::CurrentUser()->Timezone) && in_array(Member::CurrentUser()->Timezone, timezone_identifiers_list()) && Member::CurrentUser()->Timezone != date_default_timezone_get()){
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 222 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
19
                $timestamp->setTimezone(new DateTimeZone(Member::CurrentUser()->Timezone));    
20
            }
21
        }
22
        //return timestamp in "Nice" format + the user's timezone
23
        return $timestamp->Format('d/m/Y g:ia');
24
    }
25
}