HolidayHelper::callMethod()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 3
nop 3
1
<?php
2
namespace Holiday\Helper;
3
4
class HolidayHelper
5
{
6
    public static function callMethod($country, $method, $params)
7
    {
8
        $classNamePattern = 'Holiday\Country\%sHoliday';
9
        if (class_exists(sprintf($classNamePattern, $country))) {
10
            if (method_exists(sprintf($classNamePattern, $country), $method) && is_callable(sprintf($classNamePattern, $country), $method)) {
11
                return call_user_func_array(sprintf($classNamePattern.'::%s', $country, $method), $params);
12
            } else {
13
                throw new \BadMethodCallException(sprintf('The required method "%s" does not exist for %s', $method, sprintf($classNamePattern, $country)));
14
            }
15
        } else {
16
            throw new \InvalidArgumentException(sprintf('%s country does not exist.', $country));
17
        }
18
    }
19
}
20