Failed Conditions
Push — develop ( 8574fc...cc7867 )
by Remco
04:15
created

Integration::get_config()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 26
nc 4
nop 1
dl 0
loc 36
ccs 0
cts 30
cp 0
crap 20
rs 9.504
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
4
5
use Pronamic\WordPress\Pay\Gateways\Ingenico\AbstractIntegration;
6
use Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
7
use Pronamic\WordPress\Pay\Gateways\Ingenico\Settings;
8
9
class Integration extends AbstractIntegration {
10
	public function __construct( $args = array() ) {
11
		$args = wp_parse_args( $args, array(
12
			'id'   => 'ogone-directlink',
13
			'name' => 'Ingenico/Ogone - DirectLink',
14
		) );
15
16
		parent::__construct( $args );
17
	}
18
19
	public function get_settings_fields() {
20
		return Settings::get_settings_fields( 'directlink' );
21
	}
22
23
	public function get_config( $post_id ) {
24
		$config = new Config();
25
26
		$config->mode                = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...ic_gateway_mode', true) can also be of type false. However, the property $mode is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
27
		$config->psp_id              = get_post_meta( $post_id, '_pronamic_gateway_ogone_psp_id', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...ay_ogone_psp_id', true) can also be of type false. However, the property $psp_id is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
28
		$config->hash_algorithm      = get_post_meta( $post_id, '_pronamic_gateway_ogone_hash_algorithm', true );
0 ignored issues
show
Bug introduced by
The property hash_algorithm does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
29
		$config->sha_out_pass_phrase = get_post_meta( $post_id, '_pronamic_gateway_ogone_sha_out_pass_phrase', true );
0 ignored issues
show
Bug introduced by
The property sha_out_pass_phrase does not exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config. Did you mean sha_in_pass_phrase?
Loading history...
30
		$config->user_id             = get_post_meta( $post_id, '_pronamic_gateway_ogone_user_id', true );
31
		$config->password            = get_post_meta( $post_id, '_pronamic_gateway_ogone_password', true );
32
		$config->sha_in_pass_phrase  = get_post_meta( $post_id, '_pronamic_gateway_ogone_directlink_sha_in_pass_phrase', true );
33
		$config->enabled_3d_secure   = get_post_meta( $post_id, '_pronamic_gateway_ogone_3d_secure_enabled', true );
0 ignored issues
show
Bug introduced by
The property enabled_3d_secure does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
34
		$config->order_id            = get_post_meta( $post_id, '_pronamic_gateway_ogone_order_id', true );
0 ignored issues
show
Bug introduced by
The property order_id does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
35
		$config->alias_enabled       = get_post_meta( $post_id, '_pronamic_gateway_ogone_alias_enabled', true );
0 ignored issues
show
Bug introduced by
The property alias_enabled does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
36
		$config->alias_usage         = get_post_meta( $post_id, '_pronamic_gateway_ogone_alias_usage', true );
0 ignored issues
show
Bug introduced by
The property alias_usage does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
37
38
		// API URL
39
		$is_utf8 = strcasecmp( get_bloginfo( 'charset' ), 'UTF-8' ) === 0;
40
41
		switch ( $config->mode ) {
42
			case Gateway::MODE_TEST:
43
				if ( $is_utf8 ) {
44
					$config->api_url = DirectLink::API_TEST_UTF8_URL;
45
				} else {
46
					$config->api_url = DirectLink::API_TEST_URL;
47
				}
48
49
				break;
50
			default:
51
				if ( $is_utf8 ) {
52
					$config->api_url = DirectLink::API_PRODUCTION_UTF8_URL;
53
				} else {
54
					$config->api_url = DirectLink::API_PRODUCTION_URL;
55
				}
56
		}
57
58
		return $config;
59
	}
60
}
61