Failed Conditions
Push — develop ( 6c29e1...37d097 )
by Reüel
03:10
created

src/DirectLink/ConfigFactory.php (7 issues)

1
<?php
2
namespace Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
3
4
use Pronamic\WordPress\Pay\Core\Gateway;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Pronamic\WordPress\Pay\G...nico\DirectLink\Gateway. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use Pronamic\WordPress\Pay\Core\GatewayConfigFactory;
6
use Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
7
8
/**
9
 * Title: Ingenico DirectLink config factory
10
 * Description:
11
 * Copyright: 2005-2019 Pronamic
12
 * Company: Pronamic
13
 *
14
 * @author  Remco Tolsma
15
 * @version 2.0.0
16
 */
17
class ConfigFactory extends GatewayConfigFactory {
18
	public function get_config( $post_id ) {
19
		$config = new Config();
20
21
		$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...
22
		$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...
23
		$config->hash_algorithm      = get_post_meta( $post_id, '_pronamic_gateway_ogone_hash_algorithm', true );
0 ignored issues
show
The property hash_algorithm does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
24
		$config->sha_out_pass_phrase = get_post_meta( $post_id, '_pronamic_gateway_ogone_sha_out_pass_phrase', true );
0 ignored issues
show
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...
25
		$config->user_id             = get_post_meta( $post_id, '_pronamic_gateway_ogone_user_id', true );
26
		$config->password            = get_post_meta( $post_id, '_pronamic_gateway_ogone_password', true );
27
		$config->sha_in_pass_phrase  = get_post_meta( $post_id, '_pronamic_gateway_ogone_directlink_sha_in_pass_phrase', true );
28
		$config->enabled_3d_secure   = get_post_meta( $post_id, '_pronamic_gateway_ogone_3d_secure_enabled', true );
0 ignored issues
show
The property enabled_3d_secure does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
29
		$config->order_id            = get_post_meta( $post_id, '_pronamic_gateway_ogone_order_id', true );
0 ignored issues
show
The property order_id does not seem to exist on Pronamic\WordPress\Pay\G...enico\DirectLink\Config.
Loading history...
30
31
		// API URL
32
		$is_utf8 = strcasecmp( get_bloginfo( 'charset' ), 'UTF-8' ) === 0;
33
34
		switch ( $config->mode ) {
35
			case Gateway::MODE_TEST:
36
				if ( $is_utf8 ) {
37
					$config->api_url = DirectLink::API_TEST_UTF8_URL;
38
				} else {
39
					$config->api_url = DirectLink::API_TEST_URL;
40
				}
41
42
				break;
43
			default:
44
				if ( $is_utf8 ) {
45
					$config->api_url = DirectLink::API_PRODUCTION_UTF8_URL;
46
				} else {
47
					$config->api_url = DirectLink::API_PRODUCTION_URL;
48
				}
49
		}
50
51
		return $config;
52
	}
53
}
54