@@ -24,10 +24,9 @@ class HostsFile
24
24
/**
25
25
* Returns the default path for the hosts file on this system
26
26
*
27
- * @return string
28
27
* @codeCoverageIgnore
29
28
*/
30
- public static function getDefaultPath ()
29
+ public static function getDefaultPath (): string
31
30
{
32
31
// use static path for all Unix-based systems
33
32
if (DIRECTORY_SEPARATOR !== '\\' ) {
@@ -59,7 +58,7 @@ public static function getDefaultPath()
59
58
* @return self
60
59
* @throws RuntimeException if the path can not be loaded (does not exist)
61
60
*/
62
- public static function loadFromPathBlocking ($ path = null )
61
+ public static function loadFromPathBlocking (? string $ path = null ): self
63
62
{
64
63
if ($ path === null ) {
65
64
$ path = self ::getDefaultPath ();
@@ -73,16 +72,23 @@ public static function loadFromPathBlocking($path = null)
73
72
return new self ($ contents );
74
73
}
75
74
75
+ /**
76
+ * @var string
77
+ */
76
78
private $ contents ;
77
79
78
80
/**
79
81
* Instantiate new hosts file with the given hosts file contents
80
82
*
81
83
* @param string $contents
82
84
*/
83
- public function __construct ($ contents )
85
+ public function __construct (string $ contents )
84
86
{
85
- // remove all comments from the contents
87
+ /**
88
+ * remove all comments from the contents
89
+ *
90
+ * @var string $contents
91
+ */
86
92
$ contents = preg_replace ('/[ \t]*#.*/ ' , '' , strtolower ($ contents ));
87
93
88
94
$ this ->contents = $ contents ;
@@ -92,9 +98,9 @@ public function __construct($contents)
92
98
* Returns all IPs for the given hostname
93
99
*
94
100
* @param string $name
95
- * @return string[]
101
+ * @return iterable< string>
96
102
*/
97
- public function getIpsForHost ($ name )
103
+ public function getIpsForHost (string $ name ): iterable
98
104
{
99
105
$ name = strtolower ($ name );
100
106
@@ -121,9 +127,9 @@ public function getIpsForHost($name)
121
127
* Returns all hostnames for the given IPv4 or IPv6 address
122
128
*
123
129
* @param string $ip
124
- * @return string[]
130
+ * @return iterable< string>
125
131
*/
126
- public function getHostsForIp ($ ip )
132
+ public function getHostsForIp (string $ ip ): iterable
127
133
{
128
134
// check binary representation of IP to avoid string case and short notation
129
135
$ ip = @inet_pton ($ ip );
0 commit comments