@@ -24,10 +24,9 @@ class HostsFile
2424 /**
2525 * Returns the default path for the hosts file on this system
2626 *
27- * @return string
2827 * @codeCoverageIgnore
2928 */
30- public static function getDefaultPath ()
29+ public static function getDefaultPath (): string
3130 {
3231 // use static path for all Unix-based systems
3332 if (DIRECTORY_SEPARATOR !== '\\' ) {
@@ -59,7 +58,7 @@ public static function getDefaultPath()
5958 * @return self
6059 * @throws RuntimeException if the path can not be loaded (does not exist)
6160 */
62- public static function loadFromPathBlocking ($ path = null )
61+ public static function loadFromPathBlocking (? string $ path = null ): self
6362 {
6463 if ($ path === null ) {
6564 $ path = self ::getDefaultPath ();
@@ -73,16 +72,23 @@ public static function loadFromPathBlocking($path = null)
7372 return new self ($ contents );
7473 }
7574
75+ /**
76+ * @var string
77+ */
7678 private $ contents ;
7779
7880 /**
7981 * Instantiate new hosts file with the given hosts file contents
8082 *
8183 * @param string $contents
8284 */
83- public function __construct ($ contents )
85+ public function __construct (string $ contents )
8486 {
85- // remove all comments from the contents
87+ /**
88+ * remove all comments from the contents
89+ *
90+ * @var string $contents
91+ */
8692 $ contents = preg_replace ('/[ \t]*#.*/ ' , '' , strtolower ($ contents ));
8793
8894 $ this ->contents = $ contents ;
@@ -92,9 +98,9 @@ public function __construct($contents)
9298 * Returns all IPs for the given hostname
9399 *
94100 * @param string $name
95- * @return string[]
101+ * @return iterable< string>
96102 */
97- public function getIpsForHost ($ name )
103+ public function getIpsForHost (string $ name ): iterable
98104 {
99105 $ name = strtolower ($ name );
100106
@@ -113,17 +119,15 @@ public function getIpsForHost($name)
113119 }
114120 }
115121 }
116-
117- return $ ips ;
118122 }
119123
120124 /**
121125 * Returns all hostnames for the given IPv4 or IPv6 address
122126 *
123127 * @param string $ip
124- * @return string[]
128+ * @return iterable< string>
125129 */
126- public function getHostsForIp ($ ip )
130+ public function getHostsForIp (string $ ip ): iterable
127131 {
128132 // check binary representation of IP to avoid string case and short notation
129133 $ ip = @inet_pton ($ ip );
0 commit comments