Completed
Push — master ( 01abf8...56bab1 )
by Andy
02:13
created

Parse::extractTwitterUsername()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
crap 3
1
<?php
2
3
namespace mySociety\EveryPoliticianPopolo;
4
5
class Parse
6
{
7 18
    public static function extractTwitterUsername($usernameOrUrl)
8
    {
9 18
        $splitUrl = parse_url($usernameOrUrl);
10 18
        if (array_key_exists('host', $splitUrl) && $splitUrl['host'] == 'twitter.com') {
11 9
            return preg_replace('!^/([^/]+).*!', '\1', $splitUrl['path']);
12
        }
13 9
        return ltrim(trim($usernameOrUrl), '@');
14
    }
15
}
16