• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

h4kuna / ares / 15408307146

30 May 2025 03:51PM UTC coverage: 83.105% (-1.8%) from 84.928%
15408307146

push

github

web-flow
Merge pull request #48 from h4kuna/update-phpstan

Update phpstan

15 of 42 new or added lines in 17 files covered. (35.71%)

364 of 438 relevant lines covered (83.11%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/AresFactory.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Ares;
4

5
use GuzzleHttp;
6
use h4kuna\Ares\Adis\StatusBusinessSubjects\StatusBusinessSubjectsTransformer;
7
use h4kuna\Ares\Exception\LogicException;
8
use h4kuna\Ares\Http\HttpFactory;
9
use h4kuna\Ares\Http\TransportProvider;
10
use h4kuna\Ares\Vies\Client;
11
use h4kuna\Ares\Vies\ContentProvider;
12
use Psr\Http\Client\ClientInterface;
13
use Psr\Http\Message\RequestFactoryInterface;
14
use Psr\Http\Message\StreamFactoryInterface;
15

16
/**
17
 * @phpstan-type multiFactory RequestFactoryInterface&StreamFactoryInterface
18
 */
19
class AresFactory
20
{
21
        /**
22
         * @var multiFactory|null
23
         */
24
        private null|RequestFactoryInterface|StreamFactoryInterface $multiFactory = null;
25

26

27
        public function __construct(
1✔
28
                private ?ClientInterface $client = null,
29
                private ?StreamFactoryInterface $streamFactory = null,
30
                private ?RequestFactoryInterface $requestFactory = null,
31
        )
32
        {
33
        }
1✔
34

35

36
        public function create(): Ares
37
        {
38
                $streamFactory = $this->getStreamFactory();
1✔
39
                $transportProvider = $this->createTransportProvider($streamFactory);
1✔
40
                $adisContentProvider = $this->createAdisContentProvider($transportProvider);
1✔
41
                $aresClient = new Ares\Client($transportProvider);
1✔
42

43
                $dataBoxClient = new DataBox\Client($transportProvider);
1✔
44
                $dataBoxContentProvider = new DataBox\ContentProvider($dataBoxClient, $streamFactory);
1✔
45

46
                $aresContentProvider = new Ares\Core\ContentProvider(new Ares\Core\JsonToDataTransformer(), $aresClient, $adisContentProvider);
1✔
47

48
                $viesContentProvider = new ContentProvider(new Client($transportProvider));
1✔
49

50
                return new Ares($aresContentProvider, $dataBoxContentProvider, $adisContentProvider, $viesContentProvider);
1✔
51
        }
52

53

54
        public function getRequestFactory(): RequestFactoryInterface
55
        {
56
                return $this->requestFactory ??= $this->getMultiFactory();
1✔
57
        }
58

59

60
        public function getClient(): ClientInterface
61
        {
62
                if ($this->client !== null) {
1✔
63
                        return $this->client;
×
64
                }
65
                self::checkGuzzle();
1✔
66

67
                return $this->client = new GuzzleHttp\Client();
1✔
68
        }
69

70

71
        public function getStreamFactory(): StreamFactoryInterface
72
        {
73
                return $this->streamFactory ??= $this->getMultiFactory();
1✔
74
        }
75

76

77
        protected function createAdisContentProvider(TransportProvider $transportProvider): Adis\ContentProvider
1✔
78
        {
79
                return new Adis\ContentProvider(new Adis\Client($transportProvider), new StatusBusinessSubjectsTransformer());
1✔
80
        }
81

82

83
        public function createTransportProvider(StreamFactoryInterface $streamFactory): TransportProvider
1✔
84
        {
85
                $client = $this->getClient();
1✔
86
                $requestFactory = $this->getRequestFactory();
1✔
87
                return new TransportProvider($requestFactory, $client, $streamFactory);
1✔
88
        }
89

90

91
        /**
92
         * @return multiFactory
93
         */
94
        protected function getMultiFactory(): RequestFactoryInterface|StreamFactoryInterface
95
        {
96
                self::checkGuzzle();
1✔
97

98
                return $this->multiFactory ??= class_exists(GuzzleHttp\Psr7\HttpFactory::class) ? new GuzzleHttp\Psr7\HttpFactory() : new HttpFactory();
1✔
99
        }
100

101

102
        private static function checkGuzzle(): void
103
        {
104
                if (!class_exists(GuzzleHttp\Client::class)) {
1✔
NEW
105
                        throw new LogicException('Guzzle not found, let implement own solution or install guzzle by: composer require guzzlehttp/guzzle');
×
106
                }
107
        }
1✔
108

109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc