Fastspring   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
c 0
b 0
f 0
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 10 4
1
<?php
2
/**
3
 * This class helps to reach the Fastspring class with Laravel config and static
4
 * methods.
5
 *
6
 * @author    Bilal Gultekin <[email protected]>
7
 * @version   0.1:
8
 * @copyright 2019 22 Digital
9
 * @license   MIT
10
 * @see       https://docs.fastspring.com/integrating-with-fastspring/fastspring-api
11
 */
12
13
namespace TwentyTwoDigital\CashierFastspring\Fastspring;
14
15
/**
16
 * This class describes the Fastspring implementation.
17
 */
18
class Fastspring
19
{
20
    /**
21
     * Instance of Fastspring class.
22
     *
23
     * @var array
24
     */
25
    public static $instance;
26
27
    /**
28
     * Static method.
29
     *
30
     * It is not useful to construct this Fastspring class everytime. This helps
31
     * to construct this class with the current config. if there is not any
32
     * constructed instance then construct and save it to self::$instance
33
     *
34
     * @param string $method     The method
35
     * @param array  $parameters The parameters for username and password
36
     *
37
     * @return self
38
     */
39 21
    public static function __callStatic($method, $parameters)
40
    {
41 21
        if (!self::$instance) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::instance of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
42 1
            $username = (getenv('FASTSPRING_USERNAME') ?: config('services.fastspring.username'));
43 1
            $password = (getenv('FASTSPRING_PASSWORD') ?: config('services.fastspring.password'));
44
45 1
            self::$instance = new ApiClient($username, $password);
0 ignored issues
show
Documentation Bug introduced by
It seems like new TwentyTwoDigital\Cas...t($username, $password) of type TwentyTwoDigital\Cashier...ng\Fastspring\ApiClient is incompatible with the declared type array of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        }
47
48 21
        return call_user_func_array([self::$instance, $method], $parameters);
49
    }
50
}
51