Skip to content

Commit

Permalink
Improvement factory
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Jun 3, 2024
1 parent e5bda16 commit b8fea56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
27 changes: 15 additions & 12 deletions src/FioFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use h4kuna\Dir\Dir;
use h4kuna\Dir\TempDir;
use h4kuna\Fio;
use h4kuna\Fio\Account;
use Psr\Http\Client\ClientInterface;

class FioFactory
Expand All @@ -15,20 +15,23 @@ class FioFactory

protected Utils\Queue $queue;

protected TempDir $tempDir;


/**
* @param array<array{token: string, account: string}> $accounts
*/
public function __construct(
array $accounts,
string $temp = 'fio',
)
{
$this->tempDir = new TempDir($temp);
string|Dir $temp = 'fio',
?ClientInterface $client = null,
?Utils\FioRequestFactory $fioRequestFactory = null,
) {

$this->accountCollection = $this->createAccountCollection($accounts);
$this->queue = $this->createQueue();
$this->queue = $this->createQueue(
is_string($temp) ? new TempDir($temp) : $temp,
$client ?? self::createClientInterface(),
$fioRequestFactory ?? self::createRequestFactory()
);
}


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


protected function createQueue(): Utils\Queue
protected function createQueue(Dir $tempDir, ClientInterface $client, Utils\FioRequestFactory $fioRequestFactory): Utils\Queue
{
return new Utils\Queue($this->tempDir, $this->createClientInterface(), $this->createRequestFactory());
return new Utils\Queue($tempDir, $client, $fioRequestFactory);
}


Expand Down Expand Up @@ -75,15 +78,15 @@ protected function createXmlFile(): Pay\XMLFile
}


private function createClientInterface(): ClientInterface
private static function createClientInterface(): ClientInterface
{
Fio\Exceptions\MissingDependency::checkGuzzlehttp();

return new Client();
}


private function createRequestFactory(): Utils\FioRequestFactory
private static function createRequestFactory(): Utils\FioRequestFactory
{
Fio\Exceptions\MissingDependency::checkGuzzlehttp();

Expand Down
7 changes: 3 additions & 4 deletions src/Utils/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace h4kuna\Fio\Utils;

use h4kuna\Dir\TempDir;
use h4kuna\Dir\Dir;
use h4kuna\Fio\Exceptions;
use h4kuna\Fio\Pay\Response;
use h4kuna\Fio\Pay\XMLResponse;
Expand All @@ -26,11 +26,10 @@ class Queue


public function __construct(
private TempDir $tempDir,
private Dir $tempDir,
private ClientInterface $client,
private FioRequestFactory $requestFactory,
)
{
) {
}


Expand Down
5 changes: 4 additions & 1 deletion tests/src/Fixtures/FioFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace h4kuna\Fio\Tests\Fixtures;

use h4kuna\Dir\Dir;
use h4kuna\Fio\Pay\XMLFile;
use h4kuna\Fio\Read\Json;
use h4kuna\Fio\Utils\FioRequestFactory;
use Psr\Http\Client\ClientInterface;

class FioFactory extends \h4kuna\Fio\FioFactory
{
Expand Down Expand Up @@ -36,7 +39,7 @@ public function getReader(): Json
}


protected function createQueue(): Queue
protected function createQueue(Dir $tempDir, ClientInterface $client, FioRequestFactory $fioRequestFactory): Queue
{
return new Queue();
}
Expand Down

0 comments on commit b8fea56

Please sign in to comment.