TorProjectParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 15

Duplication

Lines 11
Ratio 52.38 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 0
Metric Value
dl 11
loc 21
ccs 17
cts 17
cp 1
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 1
crap 3
1
<?php
2
3
namespace BramR\TorExits\Parser;
4
5
use BramR\TorExits\IpList;
6
use GuzzleHttp\Psr7\StreamWrapper;
7
use Psr\Http\Message\StreamInterface;
8
9
/**
10
 * Class TorProjectParser
11
 */
12
class TorProjectParser extends BaseParser
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 4
    public function parse(StreamInterface $data = null)
18
    {
19 4
        stream_filter_register('torporject', 'BramR\TorExits\Parser\TorProjectIpFilter');
20 4
        $resource = StreamWrapper::getResource($this->getStreamData($data));
21 2
        stream_filter_prepend($resource, 'torporject');
22 2
        $contents = stream_get_contents($resource);
23
24 2
        $ips = $contents ? explode(',', $contents) : [];
25 2 View Code Duplication
        if (count($ips) < $this->getParseWarningThreshold()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26 1
            $this->logger->warning(
27 1
                'Number of Tor exit nodes found when parsing is low.',
28 1
                ['exit-node-count' => count($ips)]
29 1
            );
30 1
        } else {
31 1
            $this->logger->info(
32 1
                'Tor exit-nodes parsed from Tor project.',
33 1
                ['exit-node-count' => count($ips)]
34 1
            );
35
        }
36 2
        return new IpList($ips);
37
    }
38
}
39