Completed
Pull Request — master (#48)
by
unknown
02:50
created
src/Datapackages/BaseDatapackage.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -224,6 +224,9 @@
 block discarded – undo
224 224
         return DatapackageValidator::validate($this->descriptor(), $this->basePath);
225 225
     }
226 226
 
227
+    /**
228
+     * @param string $profile
229
+     */
227 230
     protected static function handlesProfile($profile)
228 231
     {
229 232
         return false;
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -13,16 +13,16 @@  discard block
 block discarded – undo
13 13
 abstract class BaseDatapackage implements \Iterator
14 14
 {
15 15
 
16
-  /**
17
-   * BaseDatapackage constructor.
18
-   *
19
-   * @param object $descriptor
20
-   * @param null|string $basePath
21
-   *
22
-   * @param bool $skipValidations
23
-   *
24
-   * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
25
-   */
16
+    /**
17
+     * BaseDatapackage constructor.
18
+     *
19
+     * @param object $descriptor
20
+     * @param null|string $basePath
21
+     *
22
+     * @param bool $skipValidations
23
+     *
24
+     * @throws \frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException
25
+     */
26 26
     public function __construct($descriptor, $basePath = null, $skipValidations = false)
27 27
     {
28 28
         $this->descriptor = $descriptor;
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
         $this->saveDescriptor($files['datapackage.json']);
192 192
         register_shutdown_function(function () use ($base) {Utils::removeDir($base); });
193 193
         if ($zip->open($zip_filename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
194
-          foreach ($files as $filename => $resource) {
194
+            foreach ($files as $filename => $resource) {
195 195
             $zip->addFile($resource, $filename);
196
-          }
197
-          $zip->close();
196
+            }
197
+            $zip->close();
198 198
         }
199 199
         else {
200
-          throw new DatapackageInvalidSourceException('zip file could not be saved.');
200
+            throw new DatapackageInvalidSourceException('zip file could not be saved.');
201 201
         }
202 202
     }
203 203
 
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
     protected $basePath;
207 207
     protected $skipValidations = false;
208 208
 
209
-  /**
210
-   * called by the resources iterator for each iteration.
211
-   *
212
-   * @param object $descriptor
213
-   *
214
-   * @return \frictionlessdata\datapackage\Resources\BaseResource
215
-   * @throws \frictionlessdata\datapackage\Exceptions\ResourceValidationFailedException
216
-   */
209
+    /**
210
+     * called by the resources iterator for each iteration.
211
+     *
212
+     * @param object $descriptor
213
+     *
214
+     * @return \frictionlessdata\datapackage\Resources\BaseResource
215
+     * @throws \frictionlessdata\datapackage\Exceptions\ResourceValidationFailedException
216
+     */
217 217
     protected function initResource($descriptor)
218 218
     {
219 219
         return Factory::resource($descriptor, $this->basePath, $this->skipValidations);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@
 block discarded – undo
189 189
             ++$ri;
190 190
         }
191 191
         $this->saveDescriptor($files['datapackage.json']);
192
-        register_shutdown_function(function () use ($base) {Utils::removeDir($base); });
192
+        register_shutdown_function(function() use ($base) {Utils::removeDir($base); });
193 193
         if ($zip->open($zip_filename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
194 194
           foreach ($files as $filename => $resource) {
195 195
             $zip->addFile($resource, $filename);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -195,8 +195,7 @@
 block discarded – undo
195 195
             $zip->addFile($resource, $filename);
196 196
           }
197 197
           $zip->close();
198
-        }
199
-        else {
198
+        } else {
200 199
           throw new DatapackageInvalidSourceException('zip file could not be saved.');
201 200
         }
202 201
     }
Please login to merge, or discard this patch.
src/Factory.php 3 patches
Doc Comments   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
      * allows extending classes to add custom sources
229 229
      * used by unit tests to add a mock http source.
230 230
      *
231
-     * @param $source
231
+     * @param string $source
232 232
      *
233
-     * @return mixed
233
+     * @return string
234 234
      */
235 235
     protected static function normalizeHttpSource($source)
236 236
     {
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * allows extending classes to add custom sources
242 242
      * used by unit tests to add a mock http source.
243
-     * @param $source
243
+     * @param string $source
244 244
      * @return bool
245 245
      */
246 246
     protected static function isHttpSource($source)
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      *   - normalized basePath.
256 256
      *
257 257
      * @param $source
258
-     * @param $basePath
258
+     * @param null|string $basePath
259 259
      *
260 260
      * @return object
261 261
      *
@@ -330,16 +330,25 @@  discard block
 block discarded – undo
330 330
         return (object) ['descriptor' => $descriptor, 'basePath' => $basePath];
331 331
     }
332 332
 
333
+    /**
334
+     * @param string $source
335
+     */
333 336
     protected static function isHttpZipSource($source)
334 337
     {
335 338
         return strtolower(substr($source, -4)) == '.zip';
336 339
     }
337 340
 
341
+    /**
342
+     * @param string $source
343
+     */
338 344
     protected static function isFileZipSource($source)
339 345
     {
340 346
         return strtolower(substr($source, -4)) == '.zip';
341 347
     }
342 348
 
349
+    /**
350
+     * @param string $source
351
+     */
343 352
     protected static function loadHttpZipSource($source)
344 353
     {
345 354
         print_r('calling loadHttpZipSource');
@@ -352,6 +361,9 @@  discard block
 block discarded – undo
352 361
         return self::loadFileZipSource($tempfile);
353 362
     }
354 363
 
364
+    /**
365
+     * @param string $source
366
+     */
355 367
     protected static function loadFileZipSource($source)
356 368
     {
357 369
         $zip = new ZipArchive();
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
         unlink($tempfile);
348 348
         $tempfile .= '.zip';
349 349
         stream_copy_to_stream(fopen($source, 'r'), fopen($tempfile, 'w'));
350
-        register_shutdown_function(function () use ($tempfile) {unlink($tempfile); });
350
+        register_shutdown_function(function() use ($tempfile) {unlink($tempfile); });
351 351
 
352 352
         return self::loadFileZipSource($tempfile);
353 353
     }
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         $tempdir = tempnam(sys_get_temp_dir(), 'datapackage-php');
359 359
         unlink($tempdir);
360 360
         mkdir($tempdir);
361
-        register_shutdown_function(function () use ($tempdir) {Utils::removeDir($tempdir); });
361
+        register_shutdown_function(function() use ($tempdir) {Utils::removeDir($tempdir); });
362 362
         /* @noinspection PhpUnhandledExceptionInspection File existence is checked afterwards anyway */
363 363
         if (($zip->open($source) === TRUE) && ($zip->extractTo($tempdir) === TRUE)) {
364 364
             $zip->close();
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -362,8 +362,7 @@
 block discarded – undo
362 362
         /* @noinspection PhpUnhandledExceptionInspection File existence is checked afterwards anyway */
363 363
         if (($zip->open($source) === TRUE) && ($zip->extractTo($tempdir) === TRUE)) {
364 364
             $zip->close();
365
-        }
366
-        else {
365
+        } else {
367 366
             throw new Exceptions\DatapackageInvalidSourceException('zip file could not be opened from source.');
368 367
         }
369 368
 
Please login to merge, or discard this patch.
src/Resources/BaseResource.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -251,6 +251,9 @@
 block discarded – undo
251 251
 
252 252
     abstract protected function getInlineDataStream($data);
253 253
 
254
+    /**
255
+     * @param string $profile
256
+     */
254 257
     protected static function handlesProfile($profile)
255 258
     {
256 259
         return false;
Please login to merge, or discard this patch.
src/Validators/BaseValidator.php 1 patch
Doc Comments   +7 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,6 +44,9 @@  discard block
 block discarded – undo
44 44
         return $this->descriptor->profile;
45 45
     }
46 46
 
47
+    /**
48
+     * @param boolean|string $filename
49
+     */
47 50
     protected function convertValidationSchemaFilenameToUrl($filename)
48 51
     {
49 52
         $filename = realpath($filename);
@@ -124,6 +127,9 @@  discard block
 block discarded – undo
124 127
         $this->validateSchemaUrl($this->getValidationSchemaUrl());
125 128
     }
126 129
 
130
+    /**
131
+     * @param string $url
132
+     */
127 133
     protected function validateSchemaUrl($url)
128 134
     {
129 135
         $validator = new \JsonSchema\Validator();
@@ -143,7 +149,7 @@  discard block
 block discarded – undo
143 149
      * Add an error to the validator object - errors are aggregated and returned by validate function.
144 150
      *
145 151
      * @param int        $code
146
-     * @param null|mixed $extraDetails
152
+     * @param string $extraDetails
147 153
      */
148 154
     protected function addError($code, $extraDetails = null)
149 155
     {
Please login to merge, or discard this patch.
src/Package.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -8,41 +8,41 @@  discard block
 block discarded – undo
8 8
 class Package
9 9
 {
10 10
 
11
-  /**
12
-   * @param $source
13
-   * @param null $basePath
14
-   *
15
-   * @return \frictionlessdata\datapackage\Datapackages\BaseDatapackage
16
-   * @throws \Exception
17
-   * @throws \frictionlessdata\datapackage\Exceptions\DatapackageInvalidSourceException
18
-   */
19
-  public static function load($source, $basePath = null)
11
+    /**
12
+     * @param $source
13
+     * @param null $basePath
14
+     *
15
+     * @return \frictionlessdata\datapackage\Datapackages\BaseDatapackage
16
+     * @throws \Exception
17
+     * @throws \frictionlessdata\datapackage\Exceptions\DatapackageInvalidSourceException
18
+     */
19
+    public static function load($source, $basePath = null)
20 20
     {
21 21
         static::isZipPresent();
22 22
         return Factory::datapackage($source, $basePath);
23 23
     }
24 24
 
25
-  /**
26
-   * @param $source
27
-   * @param null $basePath
28
-   *
29
-   * @return \frictionlessdata\datapackage\Validators\DatapackageValidationError[]
30
-   * @throws \Exception
31
-   */
32
-  public static function validate($source, $basePath = null)
25
+    /**
26
+     * @param $source
27
+     * @param null $basePath
28
+     *
29
+     * @return \frictionlessdata\datapackage\Validators\DatapackageValidationError[]
30
+     * @throws \Exception
31
+     */
32
+    public static function validate($source, $basePath = null)
33 33
     {
34 34
         static::isZipPresent();
35 35
         return Factory::validate($source, $basePath);
36 36
     }
37 37
 
38
-  /**
39
-   * @param null $descriptor
40
-   * @param null $basePath
41
-   *
42
-   * @return mixed
43
-   * @throws \Exception
44
-   */
45
-  public static function create($descriptor = null, $basePath = null)
38
+    /**
39
+     * @param null $descriptor
40
+     * @param null $basePath
41
+     *
42
+     * @return mixed
43
+     * @throws \Exception
44
+     */
45
+    public static function create($descriptor = null, $basePath = null)
46 46
     {
47 47
         static::isZipPresent();
48 48
         $descriptor = Utils::objectify($descriptor);
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
         return new $packageClass($descriptor, $basePath, true);
55 55
     }
56 56
 
57
-  /**
58
-   * @throws \Exception
59
-   */
60
-  private static function isZipPresent() {
57
+    /**
58
+     * @throws \Exception
59
+     */
60
+    private static function isZipPresent() {
61 61
         //If ZipArchive is not available throw Exception.
62 62
         if (!class_exists('ZipArchive')) {
63
-          throw new Exception('Error: Your PHP version is not compiled with zip support');
63
+            throw new Exception('Error: Your PHP version is not compiled with zip support');
64 64
         }
65 65
     }
66 66
 }
Please login to merge, or discard this patch.