Passed
Push — main ( 66f102...e7c7b0 )
by Yevhenii
02:28
created

SteamParser::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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 1
    public function __construct(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
    public function run(int $page = 1): array
67
    {
68
        return $this->abstractProvider->start($page);
69
    }
70
}
71