Failed Conditions
Push — develop ( e0cc10...0ab1e9 )
by Reüel
05:24
created

src/WebhookListener.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Webhook listener
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 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\GatewayPostType;
14
use Pronamic\WordPress\Pay\Plugin;
15
16
/**
17
 * Webhook listener
18
 *
19
 * @author  Remco Tolsma
20
 * @version 2.1.8
21
 * @since   2.0.2
22
 */
23
class WebhookListener {
24
	/**
25
	 * Listen to OmniKassa 2.0 webhook requests.
26
	 *
27
	 * @return void
28
	 */
29
	public static function listen() {
30
		if ( ! \filter_has_var( \INPUT_GET, 'omnikassa2_webhook' ) ) {
31
			return;
32
		}
33
34
		$json = \file_get_contents( 'php://input' );
35
36
		if ( empty( $json ) ) {
37
			return;
38
		}
39
40
		$notification = Notification::from_json( $json );
41
42
		$query = new \WP_Query(
43
			array(
44
				'post_type'   => GatewayPostType::POST_TYPE,
45
				'post_status' => 'publish',
46
				'nopaging'    => true,
47
				'meta_query'  => array(
48
					array(
49
						'key'   => '_pronamic_gateway_id',
50
						'value' => 'rabobank-omnikassa-2',
51
					),
52
				),
53
			)
54
		);
55
56
		foreach ( $query->posts as $post ) {
57
			$gateway = Plugin::get_gateway( $post->ID );
0 ignored issues
show
Are you sure the assignment to $gateway is correct as Pronamic\WordPress\Pay\P...:get_gateway($post->ID) targeting Pronamic\WordPress\Pay\Plugin::get_gateway() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
58
59
			if ( $gateway instanceof Gateway ) {
60
				try {
61
					$gateway->handle_notification( $notification );
62
				} catch ( \Exception $e ) {
63
					continue;
64
				}
65
			}
66
		}
67
	}
68
}
69