Passed
Pull Request — master (#5629)
by Angel Fernando Quiroz
10:06 queued 01:32
created

PackageImporter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\PluginBundle\XApi\Importer;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Exception;
11
12
/**
13
 * Class AbstractImporter.
14
 */
15
abstract class PackageImporter
16
{
17
    /**
18
     * @var Course
19
     */
20
    protected $course;
21
22
    /**
23
     * @var string
24
     */
25
    protected $courseDirectoryPath;
26
27
    /**
28
     * @var array
29
     */
30
    protected $packageFileInfo;
31
32
    /**
33
     * @var string
34
     */
35
    protected $packageType;
36
37
    protected function __construct(array $fileInfo, Course $course)
38
    {
39
        $this->packageFileInfo = $fileInfo;
40
        $this->course = $course;
41
42
        $this->courseDirectoryPath = api_get_path(SYS_COURSE_PATH).$this->course->getDirectory();
0 ignored issues
show
Bug introduced by
The constant Chamilo\PluginBundle\XApi\Importer\SYS_COURSE_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43
    }
44
45
    /**
46
     * @return \Chamilo\PluginBundle\XApi\Importer\XmlPackageImporter|\Chamilo\PluginBundle\XApi\Importer\ZipPackageImporter
47
     */
48
    public static function create(array $fileInfo, Course $course)
49
    {
50
        if ('text/xml' === $fileInfo['type']) {
51
            return new XmlPackageImporter($fileInfo, $course);
52
        }
53
54
        return new ZipPackageImporter($fileInfo, $course);
55
    }
56
57
    /**
58
     * @return mixed
59
     *
60
     * @throws Exception
61
     */
62
    abstract public function import(): string;
63
64
    public function getPackageType(): string
65
    {
66
        return $this->packageType;
67
    }
68
}
69