Failed Conditions
Push — master ( 7ec057...73baf0 )
by Reüel
16:01 queued 08:21
created

Integration::admin_notice_tld_test()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 60
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 36
nc 8
nop 0
dl 0
loc 60
ccs 0
cts 47
cp 0
crap 72
rs 8.0995
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Integration
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...mon\AbstractIntegration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Integration
17
 *
18
 * @author  Remco Tolsma
19
 * @version 2.1.0
20
 * @since   1.0.0
21
 */
22
class Integration extends AbstractIntegration {
23
	/**
24
	 * Construct and initialize integration.
25
	 */
26
	public function __construct() {
27
		$this->id            = 'rabobank-omnikassa-2';
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
		$this->name          = 'Rabobank - OmniKassa 2.0';
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
		$this->product_url   = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/';
0 ignored issues
show
Bug Best Practice introduced by
The property product_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
		$this->dashboard_url = 'https://bankieren.rabobank.nl/omnikassa-dashboard/';
0 ignored issues
show
Bug Best Practice introduced by
The property dashboard_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
		$this->provider      = 'rabobank';
0 ignored issues
show
Bug Best Practice introduced by
The property provider does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
33
		/**
34
		 * Webhook listener function.
35
		 *
36
		 * @var callable $webhook_listener_function
37
		 */
38
		$webhook_listener_function = array( __NAMESPACE__ . '\WebhookListener', 'listen' );
39
40
		if ( ! has_action( 'wp_loaded', $webhook_listener_function ) ) {
41
			add_action( 'wp_loaded', $webhook_listener_function );
42
		}
43
44
		/**
45
		 * Save post.
46
		 *
47
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736
48
		 *
49
		 * @var callable $delete_access_token_meta_function
50
		 */
51
		$delete_access_token_meta_function = array( __NAMESPACE__ . '\ConfigFactory', 'delete_access_token_meta' );
52
53
		if ( ! has_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ) ) {
54
			add_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function );
55
		}
56
57
		/**
58
		 * Admin notices.
59
		 *
60
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
61
		 *
62
		 * @var callable $admin_notices_function
63
		 */
64
		$admin_notices_function = array( $this, 'admin_notice_tld_test' );
65
66
		if ( ! has_action( 'admin_notices', $admin_notices_function ) ) {
67
			add_action( 'admin_notices', $admin_notices_function );
68
		}
69
	}
70
71
	/**
72
	 * Admin notice TLD .test.
73
	 *
74
	 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
75
	 * @link https://developer.wordpress.org/reference/hooks/admin_notices/
76
	 * @link https://developer.wordpress.org/reference/functions/get_current_screen/
77
	 */
78
	public function admin_notice_tld_test() {
79
		if ( has_filter( 'pronamic_pay_omnikassa_2_merchant_return_url' ) ) {
80
			return;
81
		}
82
83
		$screen = get_current_screen();
84
85
		if ( null === $screen ) {
86
			return;
87
		}
88
89
		if ( 'pronamic_gateway' !== $screen->id ) {
90
			return;
91
		}
92
93
		$host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
94
95
		if ( is_array( $host ) ) {
96
			return;
97
		}
98
99
		if ( '.test' !== substr( $host, -5 ) ) {
100
			return;
101
		}
102
103
		$post_id = get_the_ID();
104
105
		if ( empty( $post_id ) ) {
106
			return;
107
		}
108
109
		$gateway_id = get_post_meta( $post_id, '_pronamic_gateway_id', true );
110
111
		if ( 'rabobank-omnikassa-2' !== $gateway_id ) {
112
			return;
113
		}
114
115
		$class   = 'notice notice-error';
116
		$message = sprintf(
117
			/* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */
118
			__( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ),
119
			sprintf(
120
				'<strong>%s</strong>',
121
				__( 'Pronamic Pay', 'pronamic_ideal' )
122
			),
123
			'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address',
124
			'<code>.test</code>'
125
		);
126
127
		printf(
128
			'<div class="%1$s"><p>%2$s</p></div>',
129
			esc_attr( $class ),
130
			wp_kses(
131
				$message,
132
				array(
133
					'a'      => array(
134
						'href' => true,
135
					),
136
					'code'   => array(),
137
					'strong' => array(),
138
				)
139
			)
140
		);
141
	}
142
143
	/**
144
	 * Get config factory class.
145
	 *
146
	 * @return string
147
	 */
148
	public function get_config_factory_class() {
149
		return __NAMESPACE__ . '\ConfigFactory';
150
	}
151
152
	/**
153
	 * Get settings class.
154
	 *
155
	 * @return string
156
	 */
157
	public function get_settings_class() {
158
		return __NAMESPACE__ . '\Settings';
159
	}
160
161
	/**
162
	 * Get required settings for this integration.
163
	 *
164
	 * @link https://github.com/wp-premium/gravityforms/blob/1.9.16/includes/fields/class-gf-field-multiselect.php#L21-L42
165
	 * @since 1.1.6
166
	 * @return array
167
	 */
168
	public function get_settings() {
169
		$settings = parent::get_settings();
170
171
		$settings[] = 'omnikassa-2';
172
173
		return $settings;
174
	}
175
}
176