Passed
Push — main ( e7c7b0...8ad6bb )
by Yevhenii
02:45
created

SteamParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 51
rs 10
ccs 3
cts 12
cp 0.25
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A setUrl() 0 5 1
A setHttpStrategy() 0 4 1
A setParseRules() 0 5 1
A run() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SteamMarketProviders\ParserManager\Parser;
6
7
use PHPHtmlParser\Exceptions\ChildNotFoundException;
8
use PHPHtmlParser\Exceptions\CircularException;
9
use PHPHtmlParser\Exceptions\ContentLengthException;
10
use PHPHtmlParser\Exceptions\LogicalException;
11
use PHPHtmlParser\Exceptions\NotLoadedException;
12
use PHPHtmlParser\Exceptions\StrictException;
13
use SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder;
14
use SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface;
15
use SteamMarketProviders\ParserManager\Exception\HttpException;
16
use SteamMarketProviders\ParserManager\Contract\StrategyInterface;
17
18
final class SteamParser
19
{
20
    /**
21
     * @param AbstractProvider $abstractProvider
22
     */
23 3
    public function __construct(readonly private AbstractProvider $abstractProvider)
24
    {
25
    }
26
27
    /**
28
     * @param StrategyInterface $strategy
29
     * @return $this
30
     */
31
    public function setHttpStrategy(StrategyInterface $strategy): SteamParser
32
    {
33
        $this->abstractProvider->setHttpStrategy($strategy);
34
        return $this;
35
    }
36
37
    /**
38
     * @param ParseRulesBuilder $parseRulesBuilder
39
     * @return $this
40
     */
41
    public function setParseRules(ParseRulesBuilder $parseRulesBuilder): SteamParser
42
    {
43
        $this->abstractProvider->setParseRules($parseRulesBuilder);
44
45
        return $this;
46
    }
47
48
    public function setUrl(UrlBuilderInterface $urlBuilder): SteamParser
49
    {
50
        $this->abstractProvider->setUrl($urlBuilder);
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param int $page
57
     * @return array
58
     * @throws ChildNotFoundException
59
     * @throws CircularException
60
     * @throws ContentLengthException
61
     * @throws LogicalException
62
     * @throws NotLoadedException
63
     * @throws StrictException
64
     * @throws HttpException
65
     */
66 2
    public function run(int $page = 1): array
67
    {
68 2
        return $this->abstractProvider->start($page);
69
    }
70
}
71