Skip to content

Commit bf21de7

Browse files
committed
Add factory method for DocumentClient
1 parent 436adb5 commit bf21de7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/DocumentClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
namespace Swis\JsonApi\Client;
44

5+
use Psr\Http\Client\ClientInterface as HttpClientInterface;
56
use Psr\Http\Message\ResponseInterface;
67
use Swis\JsonApi\Client\Interfaces\ClientInterface;
78
use Swis\JsonApi\Client\Interfaces\DocumentClientInterface;
89
use Swis\JsonApi\Client\Interfaces\DocumentInterface;
910
use Swis\JsonApi\Client\Interfaces\ItemDocumentInterface;
1011
use Swis\JsonApi\Client\Interfaces\ResponseParserInterface;
12+
use Swis\JsonApi\Client\Interfaces\TypeMapperInterface;
13+
use Swis\JsonApi\Client\Parsers\ResponseParser;
1114

1215
class DocumentClient implements DocumentClientInterface
1316
{
@@ -31,6 +34,17 @@ public function __construct(ClientInterface $client, ResponseParserInterface $pa
3134
$this->parser = $parser;
3235
}
3336

37+
/**
38+
* @param \Swis\JsonApi\Client\Interfaces\TypeMapperInterface|null $typeMapper
39+
* @param \Psr\Http\Client\ClientInterface|null $client
40+
*
41+
* @return static
42+
*/
43+
public static function create(TypeMapperInterface $typeMapper = null, HttpClientInterface $client = null): self
44+
{
45+
return new static(new Client($client), ResponseParser::create($typeMapper));
46+
}
47+
3448
/**
3549
* @return string
3650
*/

tests/DocumentClientTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
class DocumentClientTest extends AbstractTest
1414
{
15+
/**
16+
* @test
17+
*/
18+
public function it_can_create_an_instance_using_a_factory_method()
19+
{
20+
$this->assertInstanceOf(DocumentClient::class, DocumentClient::create());
21+
}
22+
1523
/**
1624
* @test
1725
*/

0 commit comments

Comments
 (0)