Failed Conditions
Push — develop ( a342cf...def963 )
by Remco
03:20 queued 12s
created

NotificationRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Notification request
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
/**
14
 * Notification request
15
 *
16
 * @link    https://docs.adyen.com/developers/api-reference/notifications-api#notificationrequest
17
 * @author  Remco Tolsma
18
 * @version 1.0.0
19
 * @since   1.0.0
20
 */
21
class NotificationRequest {
22
	/**
23
	 * Informs about the origin of the notification:
24
	 *
25
	 * - `true`: the notification originated from the live environment.
26
	 * - `false`: the notification originated from the test environment.
27
	 *
28
	 * @var boolean
29
	 */
30
	private $live;
31
32
	/**
33
	 * A container object for the details included in the notification.
34
	 *
35
	 * @var array
36
	 */
37
	private $items;
38
39
	/**
40
	 * Construct notification request.
41
	 *
42
	 * @param boolean $live  Informs about the origin of the notification.
43
	 * @param array   $items A container object for the details included in the notification.
44
	 */
45
	public function __construct( $live, $items ) {
46
		$this->live  = $live;
47
		$this->items = $items;
48
	}
49
50
	/**
51
	 * Create notification request from object.
52
	 *
53
	 * @param object $object Object.
54
	 * @return OrderAnnounceResponse
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...n\OrderAnnounceResponse 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...
55
	 * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties.
56
	 */
57
	public static function from_object( $object ) {
58
		if ( ! isset( $object->live ) ) {
59
			throw new InvalidArgumentException( 'Object must contain `live` property.' );
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...nvalidArgumentException was not found. Did you mean InvalidArgumentException? If so, make sure to prefix the type with \.
Loading history...
60
		}
61
62
		if ( ! isset( $object->notificationItems ) ) {
63
			throw new InvalidArgumentException( 'Object must contain `notificationItems` property.' );
64
		}
65
66
		if ( ! is_array( $object->notificationItems ) ) {
67
			throw new InvalidArgumentException( 'Object property `notificationItems` must be an array.' );			
68
		}
69
70
		$items = array();
71
72
		foreach ( $object->notificationItems as $o ) {
73
			$items[] = NotificationRequestItem::from_object( $o );
0 ignored issues
show
Bug introduced by
The method from_object() does not exist on Pronamic\WordPress\Pay\G...NotificationRequestItem. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
			/** @scrutinizer ignore-call */ 
74
   $items[] = NotificationRequestItem::from_object( $o );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
		}
75
76
		return new self(
0 ignored issues
show
Bug Best Practice introduced by
The expression return new self(filter_v...IDATE_BOOLEAN), $items) returns the type Pronamic\WordPress\Pay\G...yen\NotificationRequest which is incompatible with the documented return type Pronamic\WordPress\Pay\G...n\OrderAnnounceResponse.
Loading history...
77
			filter_var( $object->redirectUrl, FILTER_VALIDATE_BOOLEAN ),
78
			$items
79
		);
80
	}
81
}
82