Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
Total | |
91.30% |
21 / 23 |
|
92.00% |
23 / 25 |
|
35.29% |
6 / 17 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
Location | |
91.30% |
21 / 23 |
|
92.00% |
23 / 25 |
|
35.29% |
6 / 17 |
|
83.33% |
5 / 6 |
75.96 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
__destruct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
asHashtag | |
87.50% |
14 / 16 |
|
88.89% |
16 / 18 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
9.16 | |||
equals | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Fdsn\Webservices\Event\Structs; |
3 | |
4 | /** |
5 | * Data structure to handle Location |
6 | * |
7 | * @param string $name Name of location |
8 | * |
9 | * @return true, if every check is passed, false otherwise |
10 | */ |
11 | |
12 | class Location { |
13 | private string $name; |
14 | |
15 | function __construct(string $name) { |
16 | |
17 | if( empty($name) ) |
18 | throw new \InvalidArgumentException("Location name invalid"); |
19 | |
20 | $this->name = $name; |
21 | } |
22 | |
23 | function __destruct(){ } |
24 | |
25 | /** |
26 | * Returns location |
27 | * |
28 | * @return string Location name |
29 | */ |
30 | function __toString(){ return sprintf("%s", $this->name); } |
31 | |
32 | /** |
33 | * fetch location name |
34 | * @return string location name |
35 | */ |
36 | public function name():string{ return $this->name; } |
37 | |
38 | /** |
39 | * Hashtag Location name |
40 | * @return string Location name with hashtag for Tweeter/X, Telegram, etc... |
41 | */ |
42 | public function asHashtag():string{ |
43 | $tokens = array(); |
44 | |
45 | $elems = preg_split('/ /', $this->name); |
46 | foreach($elems as $elem){ |
47 | if(is_numeric($elem)) |
48 | $tokens[] = $elem; |
49 | elseif(preg_match('/^(E|Se|S|Sw|W|Nw|N|Ne|Km|di)$/i', $elem)) |
50 | $tokens[] = $elem; |
51 | elseif(preg_match('/\(\w+/i', $elem)) |
52 | $tokens[] = preg_replace('/^\((\w+)/i', '(#$1', $elem); |
53 | elseif(preg_match('/\[.*/', $elem)) |
54 | $tokens[] = preg_replace('/^\[(\w+)/i', '[#$1', $elem); |
55 | elseif(preg_match('/.*]/', $elem)) |
56 | $tokens[] = "#" . $elem; |
57 | elseif(is_string($elem) && 2 < strlen($elem)) |
58 | $tokens[] = '#' . $elem; |
59 | |
60 | } |
61 | return implode(' ', $tokens); |
62 | } |
63 | |
64 | /** |
65 | * Compare two objects |
66 | * @return bool true are equals, false otherwise |
67 | */ |
68 | public function equals(self $other):bool{ return $this->name == $other->name; } |
69 | |
70 | |
71 | } |