Completed
Push — master ( 1e07c5...65a849 )
by CodexShaper
02:21
created

WooCommerce   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 13
loc 91
ccs 0
cts 47
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A __set() 0 4 1
A __call() 13 13 3
A __callStatic() 0 4 1
A instance() 0 24 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
2
3
namespace Codexshaper\WooCommerce\PHP;
4
5
use Automattic\WooCommerce\Client;
6
use Codexshaper\WooCommerce\PHP\Helpers\Config;
7
use Codexshaper\WooCommerce\PHP\Traits\WooCommerceTrait;
8
9
class WooCommerce
10
{
11
    use WooCommerceTrait;
12
13
    /**
14
     *@var \Automattic\WooCommerce\Client
15
     */
16
    protected static $client;
17
18
    /**
19
     *@var array
20
     */
21
    protected static $headers = [];
22
23
    /**
24
     * Build Woocommerce connection.
25
     *
26
     * @return void
27
     */
28
29
    protected $properties = [];
30
31
    /**
32
     * Get  Inaccessible Property.
33
     *
34
     * @param string $name
35
     *
36
     * @return int|string|array|object|null
37
     */
38
    public function __get($name)
39
    {
40
        return $this->$name;
41
    }
42
43
    /**
44
     * Set Option.
45
     *
46
     * @param string $name
47
     * @param string $value
48
     *
49
     * @return void
50
     */
51
    public function __set($name, $value)
52
    {
53
        $this->properties[$name] = $value;
54
    }
55
56 View Code Duplication
    public function __call($method, $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
57
    {
58
        if (!method_exists($this, $method)) {
59
            preg_match_all('/((?:^|[A-Z])[a-z]+)/', $method, $partials);
60
            $method = array_shift($partials[0]);
61
            if (!method_exists($this, $method)) {
62
                throw new \Exception('Sorry! you are calling wrong method');
63
            }
64
            array_unshift($parameters, strtolower(implode('_', $partials[0])));
65
        }
66
67
        return $this->$method(...$parameters);
68
    }
69
70
    public static function __callStatic($method, $parameters)
71
    {
72
        return (new static() )->$method(...$parameters);
73
    }
74
    
75
    private function instance()
76
    {
77
        try {
78
            static::$headers = [
79
                'header_total'       => Config::get('woocommerce.header_total'),
80
                'header_total_pages' => Config::get('woocommerce.header_total_pages'),
81
            ];
82
83
            static::$client = new Client(
84
                Config::get('woocommerce.store_url'),
85
                Config::get('woocommerce.consumer_key'),
86
                Config::get('woocommerce.consumer_secret'),
87
                [
88
                    'version'           => 'wc/'.Config::get('woocommerce.api_version'),
89
                    'wp_api'            => Config::get('woocommerce.wp_api'),
90
                    'verify_ssl'        => Config::get('woocommerce.verify_ssl'),
91
                    'query_string_auth' => Config::get('woocommerce.query_string_auth'),
92
                    'timeout'           => Config::get('woocommerce.timeout'),
93
                ]
94
            );
95
        } catch (\Exception $e) {
96
            throw new \Exception($e->getMessage(), 1);
97
        }
98
    }
99
}
100