StackOverflowWebPageSource::getResults()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Coco\SourceWatcher\Vendors\StackOverflow;
4
5
use Coco\SourceWatcher\Core\SourceWatcherException;
6
use Coco\SourceWatcher\Watcher\Source\WebPageSource;
7
8
/**
9
 * Class StackOverflowWebPageSource
10
 *
11
 * @package Coco\SourceWatcher\Vendors\StackOverflow
12
 */
13
class StackOverflowWebPageSource extends WebPageSource
14
{
15
    public function __construct ( string $url )
16
    {
17
        parent::__construct( $url );
18
19
        $this->handler = new StackOverflowWebPageHandler( $url );
20
    }
21
22
    /**
23
     * Function that returns the results from the given StackOverflow URL.
24
     *
25
     * @return array
26
     * @throws SourceWatcherException
27
     */
28
    public function getResults () : array
29
    {
30
        if ( $this->url != $this->handler->getUrl() ) {
31
            $this->handler = new StackOverflowWebPageHandler( $this->url );
32
        }
33
34
        try {
35
            $this->handler->read();
36
        } catch ( SourceWatcherException $e ) {
37
            throw new SourceWatcherException( "Something went wrong trying to read the results", $e->getCode(), $e );
38
        }
39
40
        return $this->handler->getResults();
0 ignored issues
show
introduced by
The method getResults() does not exist on Coco\SourceWatcher\Watcher\Handler\WebPageHandler. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        return $this->handler->/** @scrutinizer ignore-call */ getResults();
Loading history...
41
    }
42
}
43