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 |
||
15 | class Consumer |
||
16 | { |
||
17 | private $client; |
||
18 | |||
19 | /** |
||
20 | * When enabled, crawler will read content of title and meta description if no |
||
21 | * Open Graph data is provided by target page. |
||
22 | * |
||
23 | * @var bool |
||
24 | */ |
||
25 | public $useFallbackMode = false; |
||
26 | |||
27 | /** |
||
28 | * When enabled, crawler will throw exceptions for some crawling errors like unexpected |
||
29 | * Open Graph elements. |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | public $debug = false; |
||
34 | |||
35 | /** |
||
36 | * @param AdapterInterface $adapter Guzzle adapter to use for making HTTP requests. |
||
37 | * @param array $config Optional Guzzle config overrides. |
||
38 | */ |
||
39 | 16 | public function __construct(AdapterInterface $adapter = null, array $config = []) |
|
45 | |||
46 | /** |
||
47 | * Fetches HTML content from the given URL and then crawls it for Open Graph data. |
||
48 | * |
||
49 | * @param string $url URL to be crawled. |
||
50 | * |
||
51 | * @return Website |
||
52 | */ |
||
53 | public function loadUrl($url) |
||
60 | |||
61 | /** |
||
62 | * Crawls the given HTML string for OpenGraph data. |
||
63 | * |
||
64 | * @param string $html HTML string, usually whole content of crawled web resource. |
||
65 | * @param string $fallbackUrl URL to use when fallback mode is enabled. |
||
66 | * |
||
67 | * @return ObjectBase |
||
68 | */ |
||
69 | 16 | public function loadHtml($html, $fallbackUrl = null) |
|
82 | |||
83 | 16 | private function extractOpenGraphData($content) |
|
148 | } |
||
149 |