Completed
Push — master ( 304766...d9e007 )
by Ori
11:07
created

Package::isZipPresent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace frictionlessdata\datapackage;
4
5
use Exception;
6
use ZipArchive;
7
8
class Package
9
{
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)
20
    {
21
        return Factory::datapackage($source, $basePath);
22
    }
23
24
    /**
25
     * @param $source
26
     * @param null $basePath
27
     *
28
     * @return \frictionlessdata\datapackage\Validators\DatapackageValidationError[]
29
     * @throws \Exception
30
     */
31
    public static function validate($source, $basePath = null)
32
    {
33
        return Factory::validate($source, $basePath);
34
    }
35
36
    /**
37
     * @param null $descriptor
38
     * @param null $basePath
39
     *
40
     * @return mixed
41
     * @throws \Exception
42
     */
43
    public static function create($descriptor = null, $basePath = null)
44
    {
45
        $descriptor = Utils::objectify($descriptor);
46
        if ($descriptor && !isset($descriptor->resources)) {
47
            $descriptor->resources = [];
48
        }
49
        $packageClass = Factory::getDatapackageClass($descriptor);
50
51
        return new $packageClass($descriptor, $basePath, true);
52
    }
53
54
    /**
55
     * @throws \Exception
56
     */
57
    public static function isZipPresent()
58
    {
59
        //If ZipArchive is not available throw Exception.
60
        if (!class_exists('ZipArchive')) {
61
            throw new Exception('Error: Your PHP version is not compiled with zip support');
62
        }
63
    }
64
}
65