Skip to content

Commit b8fea56

Browse files
committed
Improvement factory
1 parent e5bda16 commit b8fea56

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/FioFactory.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use GuzzleHttp\Client;
66
use GuzzleHttp\Psr7\HttpFactory;
7+
use h4kuna\Dir\Dir;
78
use h4kuna\Dir\TempDir;
89
use h4kuna\Fio;
9-
use h4kuna\Fio\Account;
1010
use Psr\Http\Client\ClientInterface;
1111

1212
class FioFactory
@@ -15,20 +15,23 @@ class FioFactory
1515

1616
protected Utils\Queue $queue;
1717

18-
protected TempDir $tempDir;
19-
2018

2119
/**
2220
* @param array<array{token: string, account: string}> $accounts
2321
*/
2422
public function __construct(
2523
array $accounts,
26-
string $temp = 'fio',
27-
)
28-
{
29-
$this->tempDir = new TempDir($temp);
24+
string|Dir $temp = 'fio',
25+
?ClientInterface $client = null,
26+
?Utils\FioRequestFactory $fioRequestFactory = null,
27+
) {
28+
3029
$this->accountCollection = $this->createAccountCollection($accounts);
31-
$this->queue = $this->createQueue();
30+
$this->queue = $this->createQueue(
31+
is_string($temp) ? new TempDir($temp) : $temp,
32+
$client ?? self::createClientInterface(),
33+
$fioRequestFactory ?? self::createRequestFactory()
34+
);
3235
}
3336

3437

@@ -44,9 +47,9 @@ public function createFioPay(string $name = ''): Fio\FioPay
4447
}
4548

4649

47-
protected function createQueue(): Utils\Queue
50+
protected function createQueue(Dir $tempDir, ClientInterface $client, Utils\FioRequestFactory $fioRequestFactory): Utils\Queue
4851
{
49-
return new Utils\Queue($this->tempDir, $this->createClientInterface(), $this->createRequestFactory());
52+
return new Utils\Queue($tempDir, $client, $fioRequestFactory);
5053
}
5154

5255

@@ -75,15 +78,15 @@ protected function createXmlFile(): Pay\XMLFile
7578
}
7679

7780

78-
private function createClientInterface(): ClientInterface
81+
private static function createClientInterface(): ClientInterface
7982
{
8083
Fio\Exceptions\MissingDependency::checkGuzzlehttp();
8184

8285
return new Client();
8386
}
8487

8588

86-
private function createRequestFactory(): Utils\FioRequestFactory
89+
private static function createRequestFactory(): Utils\FioRequestFactory
8790
{
8891
Fio\Exceptions\MissingDependency::checkGuzzlehttp();
8992

src/Utils/Queue.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace h4kuna\Fio\Utils;
44

5-
use h4kuna\Dir\TempDir;
5+
use h4kuna\Dir\Dir;
66
use h4kuna\Fio\Exceptions;
77
use h4kuna\Fio\Pay\Response;
88
use h4kuna\Fio\Pay\XMLResponse;
@@ -26,11 +26,10 @@ class Queue
2626

2727

2828
public function __construct(
29-
private TempDir $tempDir,
29+
private Dir $tempDir,
3030
private ClientInterface $client,
3131
private FioRequestFactory $requestFactory,
32-
)
33-
{
32+
) {
3433
}
3534

3635

tests/src/Fixtures/FioFactory.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace h4kuna\Fio\Tests\Fixtures;
44

5+
use h4kuna\Dir\Dir;
56
use h4kuna\Fio\Pay\XMLFile;
67
use h4kuna\Fio\Read\Json;
8+
use h4kuna\Fio\Utils\FioRequestFactory;
9+
use Psr\Http\Client\ClientInterface;
710

811
class FioFactory extends \h4kuna\Fio\FioFactory
912
{
@@ -36,7 +39,7 @@ public function getReader(): Json
3639
}
3740

3841

39-
protected function createQueue(): Queue
42+
protected function createQueue(Dir $tempDir, ClientInterface $client, FioRequestFactory $fioRequestFactory): Queue
4043
{
4144
return new Queue();
4245
}

0 commit comments

Comments
 (0)