Completed
Push — master ( 0646cc...408e0c )
by Propa
05:16
created

Date   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 7.79 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 6
loc 77
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __call() 3 8 2
A _setLocale() 0 6 1
A _setFallbackLocale() 0 6 1
A __callStatic() 3 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Propaganistas\LaravelIntl;
2
3
use Illuminate\Support\Facades\App;
4
use Illuminate\Support\Facades\Config;
5
6
class Date
7
{
8
    /**
9
     * @var \Jenssegers\Date\Date
10
     */
11
    protected $date;
12
13
    /**
14
     * Date constructor.
15
     */
16 12
    public function __construct()
17
    {
18 12
        $this->date = \Jenssegers\Date\Date::make();
19 12
        $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...
20 12
        $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...
21 12
    }
22
23
    /**
24
     * Handle dynamic calls to the object.
25
     *
26
     * @param  string  $method
27
     * @param  array   $args
28
     * @return mixed
29
     */
30 12
    public function __call($method, $args)
31
    {
32 12 View Code Duplication
        if (method_exists($this, '_' . $method)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33 12
            return call_user_func_array([$this, '_' . $method], $args);
34
        }
35
36 12
        return call_user_func_array([$this->date, $method], $args);
37
    }
38
39
    /**
40
     * Handle dynamic, static calls to the object.
41
     *
42
     * @param  string  $method
43
     * @param  array   $args
44
     * @return mixed
45
     */
46
    public static function __callStatic($method, $args)
47
    {
48
        $instance = new static;
49
50 View Code Duplication
        if (method_exists($instance, '_' . $method)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            return call_user_func_array([$instance, '_' . $method], $args);
52
        }
53
54
        return call_user_func_array([$instance, $method], $args);
55
    }
56
57
    /**
58
     * Spoofed setLocale method.
59
     *
60
     * @param string $locale
61
     * @return $this
62
     */
63 12
    public function _setLocale($locale)
64
    {
65 12
        $this->date->setLocale($locale);
66
67 12
        return $this;
68
    }
69
70
    /**
71
     * Spoofed setFallbackLocale method.
72
     *
73
     * @param string $locale
74
     * @return $this
75
     */
76 12
    public function _setFallbackLocale($locale)
77
    {
78 12
        $this->date->setFallbackLocale($locale);
79
80 12
        return $this;
81
    }
82
}