Passed
Push — main ( 0a94ad...30f64e )
by smiley
09:47
created

HTTPClientAbstract::setStreamFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * Class HTTPClientAbstract
4
 *
5
 * @created      22.02.2019
6
 * @author       smiley <[email protected]>
7
 * @copyright    2019 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\HTTP\Psr18;
12
13
use chillerlan\HTTP\HTTPOptions;
14
use Psr\Http\Message\StreamFactoryInterface;
15
use chillerlan\HTTP\Psr17\{ResponseFactory};
16
use chillerlan\Settings\SettingsContainerInterface;
17
use Fig\Http\Message\RequestMethodInterface;
18
use Psr\Http\Client\ClientInterface;
19
use Psr\Http\Message\ResponseFactoryInterface;
20
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
21
22
abstract class HTTPClientAbstract implements ClientInterface, LoggerAwareInterface, RequestMethodInterface{
23
	use LoggerAwareTrait;
24
25
	/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\HTTP\HTTPOptions */
26
	protected SettingsContainerInterface $options;
27
28
	protected ResponseFactoryInterface $responseFactory;
29
	protected ?StreamFactoryInterface $streamFactory = null;
30
31
	/**
32
	 * HTTPClientAbstract constructor.
33
	 */
34
	public function __construct(
35
		SettingsContainerInterface $options = null,
36
		ResponseFactoryInterface $responseFactory = null,
37
		LoggerInterface $logger = null
38
	){
39
		$this->options = $options ?? new HTTPOptions;
40
41
		$this->setResponseFactory($responseFactory ?? new ResponseFactory);
42
		$this->setLogger($logger ?? new NullLogger);
43
	}
44
45
	/**
46
	 * @codeCoverageIgnore
47
	 */
48
	public function setResponseFactory(ResponseFactoryInterface $responseFactory):self{
49
		$this->responseFactory = $responseFactory;
50
51
		return $this;
52
	}
53
54
	/**
55
	 * @codeCoverageIgnore
56
	 */
57
	public function setStreamFactory(StreamFactoryInterface $streamFactory):self{
58
		$this->streamFactory = $streamFactory;
59
60
		return $this;
61
	}
62
63
}
64