static.php ➔ tld_extract()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 14
rs 9.4285
1
<?php
2
/**
3
 * TLDExtract: Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List.
4
 *
5
 * @link      https://github.com/layershifter/TLDExtract
6
 *
7
 * @copyright Copyright (c) 2016, Alexander Fedyashov
8
 * @license   https://raw.githubusercontent.com/layershifter/TLDExtract/master/LICENSE Apache 2.0 License
9
 */
10
11
namespace {
12
13
    use LayerShifter\TLDExtract\Extract;
14
15
    /**
16
     * Extract the subdomain, host and gTLD/ccTLD components from a URL.
17
     *
18
     * @param string $url  URL that will be extracted
19
     * @param int    $mode Optional, option that will control extraction process
20
     *
21
     * @return \LayerShifter\TLDExtract\ResultInterface
22
     */
23
    function tld_extract($url, $mode = null)
24
    {
25
        static $extract = null;
26
27
        if (null === $extract) {
28
            $extract = new Extract();
29
        }
30
31
        if (null !== $mode) {
32
            $extract->setExtractionMode($mode);
33
        }
34
35
        return $extract->parse($url);
36
    }
37
}
38