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

src/DirectLink/ConfigFactory.php (1 issue)

Labels
Severity
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.2
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 );
22
		$config->psp_id              = get_post_meta( $post_id, '_pronamic_gateway_ogone_psp_id', true );
23
		$config->hash_algorithm      = get_post_meta( $post_id, '_pronamic_gateway_ogone_hash_algorithm', true );
24
		$config->sha_out_pass_phrase = get_post_meta( $post_id, '_pronamic_gateway_ogone_sha_out_pass_phrase', true );
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 );
29
		$config->order_id            = get_post_meta( $post_id, '_pronamic_gateway_ogone_order_id', true );
30
		$config->alias_enabled       = get_post_meta( $post_id, '_pronamic_gateway_ogone_alias_enabled', true );
31
		$config->alias_usage         = get_post_meta( $post_id, '_pronamic_gateway_ogone_alias_usage', true );
32
33
		// API URL
34
		$is_utf8 = strcasecmp( get_bloginfo( 'charset' ), 'UTF-8' ) === 0;
35
36
		switch ( $config->mode ) {
37
			case Gateway::MODE_TEST:
38
				if ( $is_utf8 ) {
39
					$config->api_url = DirectLink::API_TEST_UTF8_URL;
40
				} else {
41
					$config->api_url = DirectLink::API_TEST_URL;
42
				}
43
44
				break;
45
			default:
46
				if ( $is_utf8 ) {
47
					$config->api_url = DirectLink::API_PRODUCTION_UTF8_URL;
48
				} else {
49
					$config->api_url = DirectLink::API_PRODUCTION_URL;
50
				}
51
		}
52
53
		return $config;
54
	}
55
}
56