LocScraper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 16
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A recognizes() 4 4 1
A scrape() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Colligator\Scrapers;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7 View Code Duplication
class LocScraper extends Scraper implements ScraperInterface
8
{
9
    public function recognizes($url)
10
    {
11
        return strpos($url, 'loc.gov');
12
    }
13
14
    public function scrape(Crawler $crawler)
15
    {
16
        $text = $crawler->filter('body')->first()->text();
17
        $texts = preg_split("/\r\n|\n\n/", $text);
18
        $text = $this->getLongestText($texts);
19
20
        return $this->returnResult($text, 'Library of Congress');
21
    }
22
}
23