1212
1313namespace Geocoder \Model ;
1414
15+ use Geocoder \Exception \CollectionIsEmpty ;
1516use Geocoder \Exception \InvalidArgument ;
17+ use Geocoder \Exception \OutOfBoundsException ;
1618
1719/**
1820 * @author Giorgio Premi <giosh94mhz@gmail.com>
@@ -65,29 +67,34 @@ public function count()
6567 }
6668
6769 /**
68- * @return AdminLevel|null
70+ * @return AdminLevel
71+ *
72+ * @throws CollectionIsEmpty
6973 */
70- public function first ()
74+ public function first (): AdminLevel
7175 {
7276 if (empty ($ this ->adminLevels )) {
73- return null ;
77+ throw new CollectionIsEmpty () ;
7478 }
7579
7680 return reset ($ this ->adminLevels );
7781 }
7882
7983 /**
84+ * @param int $offset
85+ * @param int|null $length
86+ *
8087 * @return AdminLevel[]
8188 */
82- public function slice ($ offset , $ length = null )
89+ public function slice (int $ offset , int $ length = null ): array
8390 {
8491 return array_slice ($ this ->adminLevels , $ offset , $ length , true );
8592 }
8693
8794 /**
8895 * @return bool
8996 */
90- public function has ($ level ): bool
97+ public function has (int $ level ): bool
9198 {
9299 return isset ($ this ->adminLevels [$ level ]);
93100 }
@@ -98,7 +105,7 @@ public function has($level): bool
98105 * @throws \OutOfBoundsException
99106 * @throws InvalidArgument
100107 */
101- public function get ($ level ): AdminLevel
108+ public function get (int $ level ): AdminLevel
102109 {
103110 $ this ->checkLevel ($ level );
104111
@@ -122,14 +129,12 @@ public function all()
122129 *
123130 * @throws \OutOfBoundsException
124131 */
125- private function checkLevel ($ level )
132+ private function checkLevel (int $ level )
126133 {
127134 if ($ level <= 0 || $ level > self ::MAX_LEVEL_DEPTH ) {
128- throw new \OutOfBoundsException (sprintf (
129- 'Administrative level should be an integer in [1,%d], %d given ' ,
130- self ::MAX_LEVEL_DEPTH ,
131- $ level
132- ));
135+ throw new OutOfBoundsException (
136+ sprintf ('Administrative level should be an integer in [1,%d], %d given ' , self ::MAX_LEVEL_DEPTH , $ level )
137+ );
133138 }
134139 }
135140}
0 commit comments