Completed
Push — master ( 3ef192...31d2af )
by Propa
03:28
created

Date::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Propaganistas\LaravelIntl;
2
3
use Illuminate\Support\Facades\App;
4
use Illuminate\Support\Facades\Config;
5
use Propaganistas\LaravelIntl\Base\LocaleCallback;
6
7
class Date
8
{
9
    use LocaleCallback;
10
11
    /**
12
     * @var \Jenssegers\Date\Date
13
     */
14
    protected $date;
15
16
    /**
17
     * Date constructor.
18
     */
19 15
    public function __construct()
20
    {
21 15
        $this->date = \Jenssegers\Date\Date::make();
22 15
        $this->setLocale(App::getLocale());
0 ignored issues
show
Bug introduced by
The method setLocale() does not exist on Propaganistas\LaravelIntl\Date. Did you maybe mean _setLocale()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
23 15
        $this->setFallbackLocale(Config::get('app.fallback_locale'));
0 ignored issues
show
Bug introduced by
The method setFallbackLocale() does not exist on Propaganistas\LaravelIntl\Date. Did you maybe mean _setFallbackLocale()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
24 15
    }
25
26
    /**
27
     * Handle dynamic calls to the object.
28
     *
29
     * @param  string  $method
30
     * @param  array   $args
31
     * @return mixed
32
     */
33 15
    public function __call($method, $args)
34
    {
35 15
        if (method_exists($this, '_' . $method)) {
36 15
            return call_user_func_array([$this, '_' . $method], $args);
37
        }
38
39 15
        return call_user_func_array([$this->date, $method], $args);
40
    }
41
42
    /**
43
     * Spoofed setLocale method.
44
     *
45
     * @param string $locale
46
     * @return $this
47
     */
48 15
    public function _setLocale($locale)
49
    {
50 15
        $this->date->setLocale($locale);
51
52 15
        return $this;
53
    }
54
55
    /**
56
     * Spoofed setFallbackLocale method.
57
     *
58
     * @param string $locale
59
     * @return $this
60
     */
61 15
    public function _setFallbackLocale($locale)
62
    {
63 15
        $this->date->setFallbackLocale($locale);
64
65 15
        return $this;
66
    }
67
}