anonymous//tests/Parser/SteamParserTest.php$0   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 10
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SteamMarketProviders\ParserManager\Tests\Parser;
6
7
use Exception;
8
use PHPHtmlParser\Exceptions\ChildNotFoundException;
9
use PHPHtmlParser\Exceptions\CircularException;
10
use PHPHtmlParser\Exceptions\ContentLengthException;
11
use PHPHtmlParser\Exceptions\LogicalException;
12
use PHPHtmlParser\Exceptions\NotLoadedException;
13
use PHPHtmlParser\Exceptions\StrictException;
14
use PHPUnit\Framework\TestCase;
15
use SteamMarketProviders\Enums\SteamApp;
16
use SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder;
17
use SteamMarketProviders\ParserManager\Builder\SearchUrlBuilder;
18
use SteamMarketProviders\ParserManager\Contract\StrategyInterface;
19
use SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface;
20
use SteamMarketProviders\ParserManager\Exception\HttpException;
21
use SteamMarketProviders\ParserManager\Http\Options;
22
use SteamMarketProviders\ParserManager\Http\Response;
23
use SteamMarketProviders\ParserManager\Parser\AbstractProvider;
24
use SteamMarketProviders\ParserManager\SteamParserFactory;
25
26
class SteamParserTest extends TestCase
27
{
28
    public function testWhenProviderMethodCreateUrlNoneReturned(): void
29
    {
30
        $this->expectExceptionMessage('SteamMarketProviders\ParserManager\Parser\AbstractProvider@anonymous::createUrl(): Return value must be of type SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface, none returned');
31
32
        $provider = new class () extends AbstractProvider {
33
            protected function createUrl(int $page): UrlBuilderInterface
34
            {
35
            }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return SteamMarketProviders\Par...act\UrlBuilderInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
36
            protected function createParseRules(): ParseRulesBuilder
37
            {
38
            }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return SteamMarketProviders\Par...ilder\ParseRulesBuilder. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
        };
40
41
        SteamParserFactory::create($provider)->run();
42
    }
43
44
    public function testWhenProviderMethodCreateParseRulesNoneReturned(): void
45
    {
46
        $this->expectExceptionMessage('SteamMarketProviders\ParserManager\Parser\AbstractProvider@anonymous::createParseRules(): Return value must be of type SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder, none returned');
47
48
        $provider = new class () extends AbstractProvider {
49
            protected function createUrl(int $page): UrlBuilderInterface
50
            {
51
                return (new SearchUrlBuilder())
52
                    ->setAppId(SteamApp::CSGO)
53
                    ->setPage($page);
54
            }
55
            protected function createParseRules(): ParseRulesBuilder
56
            {
57
            }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return SteamMarketProviders\Par...ilder\ParseRulesBuilder. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
58
        };
59
60
        SteamParserFactory::create($provider)->run();
61
    }
62
}
63