Passed
Push — main ( 255c0f...66f102 )
by Yevhenii
02:14
created

SteamParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

5 Methods

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