22
33namespace frictionlessdata \datapackage \Datapackages ;
44
5+ use Exception ;
56use frictionlessdata \datapackage \Factory ;
67use frictionlessdata \datapackage \Package ;
78use frictionlessdata \datapackage \Registry ;
89use frictionlessdata \datapackage \Utils ;
910use frictionlessdata \datapackage \Validators \DatapackageValidator ;
1011use frictionlessdata \datapackage \Exceptions \DatapackageValidationFailedException ;
1112use frictionlessdata \datapackage \Exceptions \DatapackageInvalidSourceException ;
13+ use Iterator ;
1214use ZipArchive ;
1315
14- abstract class BaseDatapackage implements \ Iterator
16+ abstract class BaseDatapackage implements Iterator
1517{
1618
1719 /**
@@ -34,6 +36,9 @@ public function __construct($descriptor, $basePath = null, $skipValidations = fa
3436 }
3537 }
3638
39+ /**
40+ * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
41+ */
3742 public static function create ($ name , $ resources , $ basePath = null )
3843 {
3944 $ datapackage = new static ((object ) [
@@ -47,6 +52,9 @@ public static function create($name, $resources, $basePath = null)
4752 return $ datapackage ;
4853 }
4954
55+ /**
56+ * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
57+ */
5058 public function revalidate ()
5159 {
5260 $ this ->rewind ();
@@ -81,16 +89,23 @@ public function resources()
8189 return $ resources ;
8290 }
8391
92+ /**
93+ * @throws \frictionlessdata\datapackage\Exceptions\ResourceValidationFailedException
94+ * @throws \Exception
95+ */
8496 public function getResource ($ name )
8597 {
8698 foreach ($ this ->descriptor ->resources as $ resourceDescriptor ) {
8799 if ($ resourceDescriptor ->name == $ name ) {
88100 return $ this ->initResource ($ resourceDescriptor );
89101 }
90102 }
91- throw new \ Exception ("couldn't find matching resource with name = ' {$ name }' " );
103+ throw new Exception ("couldn't find matching resource with name = ' {$ name }' " );
92104 }
93105
106+ /**
107+ * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
108+ */
94109 public function addResource ($ name , $ resource )
95110 {
96111 if (is_a ($ resource , 'frictionlessdata \\datapackage \\Resources \\BaseResource ' )) {
@@ -119,6 +134,10 @@ public function addResource($name, $resource)
119134 }
120135
121136 // TODO: remove this function and use the getResource / addResource directly (will need to modify a lot of tests code)
137+
138+ /**
139+ * @throws \Exception
140+ */
122141 public function resource ($ name , $ resource = null )
123142 {
124143 if ($ resource ) {
@@ -128,6 +147,9 @@ public function resource($name, $resource = null)
128147 }
129148 }
130149
150+ /**
151+ * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
152+ */
131153 public function removeResource ($ name )
132154 {
133155 $ resourceDescriptors = [];
@@ -148,27 +170,30 @@ public function saveDescriptor($filename)
148170 }
149171
150172 // standard iterator functions - to iterate over the resources
151- public function rewind ()
173+ public function rewind (): void
152174 {
153175 $ this ->currentResourcePosition = 0 ;
154176 }
155177
156- public function current ()
178+ /**
179+ * @throws \frictionlessdata\datapackage\Exceptions\ResourceValidationFailedException
180+ */
181+ public function current ():mixed
157182 {
158183 return $ this ->initResource ($ this ->descriptor ()->resources [$ this ->currentResourcePosition ]);
159184 }
160185
161- public function key ()
186+ public function key (): mixed
162187 {
163188 return $ this ->currentResourcePosition ;
164189 }
165190
166- public function next ()
191+ public function next (): void
167192 {
168193 ++$ this ->currentResourcePosition ;
169194 }
170195
171- public function valid ()
196+ public function valid (): bool
172197 {
173198 return isset ($ this ->descriptor ()->resources [$ this ->currentResourcePosition ]);
174199 }
@@ -242,7 +267,6 @@ protected function copy()
242267 * @param object $descriptor
243268 *
244269 * @return \frictionlessdata\datapackage\Resources\BaseResource
245- * @throws \frictionlessdata\datapackage\Exceptions\ResourceValidationFailedException
246270 */
247271 protected function initResource ($ descriptor )
248272 {
0 commit comments