azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.04k stars 152 forks source link

Consider the use of "instanceof" instead of "get_class" #49

Closed samag closed 7 years ago

samag commented 7 years ago

Looking at

// If given date is a DateTime object; check if it falls in the weekend
if (get_class($date) === 'DateTime') {
    if (in_array($date->format('w'), $this->weekend_days)) {
        return false;
    }
}

the condition fails for any subclasses of DateTime (like the very popular Carbon class) which needlessly limits your APIs scope. Please consider the instanceof operator to allow for classes that derive from DateTime.

stelgenhof commented 7 years ago

It does seem indeed a better way to verify the class with the instanceof operator. Thanks for the suggestion!

stelgenhof commented 7 years ago

Resolved.