Completed
Push — develop ( fc3971...71605d )
by David
03:09 queued 11s
created

Analysis_Response_Ops_Factory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * Create instances of {@link \Wordlift\Analysis\Response\Analysis_Response_Ops}.
4
 *
5
 * @author David Riccitelli <[email protected]>
6
 * @since 3.25.0
7
 * @package Wordlift\Analysis\Response
8
 */
9
10
namespace Wordlift\Analysis\Response;
11
12
use Wordlift\Entity\Entity_Helper;
13
14
class Analysis_Response_Ops_Factory {
15
	/**
16
	 * @var \Wordlift_Entity_Uri_Service
17
	 */
18
	private $entity_uri_service;
19
	/**
20
	 * @var \Wordlift_Entity_Service
21
	 */
22
	private $entity_service;
23
	/**
24
	 * @var \Wordlift_Entity_Type_Service
25
	 */
26
	private $entity_type_service;
27
	/**
28
	 * @var \Wordlift_Post_Image_Storage
29
	 */
30
	private $post_image_storage;
31
	/**
32
	 * @var Entity_Helper
33
	 */
34
	private $entity_helper;
35
36
	private static $instance;
37
38
	/**
39
	 * Analysis_Response_Ops constructor.
40
	 *
41
	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service}.
42
	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service}.
43
	 * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service}.
44
	 * @param \Wordlift_Post_Image_Storage $post_image_storage A {@link Wordlift_Post_Image_Storage} instance.
45
	 * @param Entity_Helper $entity_helper The {@link Entity_Helper}.
46
	 *
47
	 * @since 3.25.1
48
	 */
49 View Code Duplication
	public function __construct( $entity_uri_service, $entity_service, $entity_type_service, $post_image_storage, $entity_helper ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
51
		$this->entity_uri_service  = $entity_uri_service;
52
		$this->entity_service      = $entity_service;
53
		$this->entity_type_service = $entity_type_service;
54
		$this->post_image_storage  = $post_image_storage;
55
		$this->entity_helper       = $entity_helper;
56
57
		self::$instance = $this;
58
59
	}
60
61
	public static function get_instance() {
62
63
		return self::$instance;
64
	}
65
66
	public function create( $json ) {
67
68
		return new Analysis_Response_Ops(
69
			$this->entity_uri_service,
70
			$this->entity_service,
71
			$this->entity_type_service,
72
			$this->post_image_storage,
73
			$this->entity_helper,
74
			$json );
75
	}
76
77
	/**
78
	 * Create an Analysis_Response_Ops instance given the provided http response.
79
	 *
80
	 * @param array $response {
81
	 *
82
	 * @type string $body The response body.
83
	 * }
84
	 *
85
	 * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
86
	 * @throws \Exception if the provided response doesn't contain a `body` element.
87
	 */
88
	public function create_with_response( $response ) {
89
90
		if ( ! isset( $response['body'] ) ) {
91
			throw new \Exception( "`body` is required in response." );
92
		}
93
94
		return $this->create( json_decode( $response['body'] ) );
95
	}
96
97
}