Passed
Pull Request — master (#5629)
by Angel Fernando Quiroz
08:49
created

PackageParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 47
c 1
b 0
f 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\PluginBundle\XApi\Parser;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\Session;
11
use Chamilo\CoreBundle\Entity\XApiToolLaunch;
12
use Exception;
13
14
/**
15
 * Class PackageParser.
16
 */
17
abstract class PackageParser
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $filePath;
23
24
    /**
25
     * @var Course
26
     */
27
    protected $course;
28
29
    /**
30
     * @var Session|null
31
     */
32
    protected $session;
33
34
    /**
35
     * AbstractParser constructor.
36
     */
37
    protected function __construct($filePath, Course $course, ?Session $session = null)
38
    {
39
        $this->filePath = $filePath;
40
        $this->course = $course;
41
        $this->session = $session;
42
    }
43
44
    /**
45
     * @return mixed
46
     *
47
     * @throws Exception
48
     */
49
    public static function create(string $packageType, string $filePath, Course $course, ?Session $session = null)
50
    {
51
        switch ($packageType) {
52
            case 'tincan':
53
                return new TinCanParser($filePath, $course, $session);
54
55
            case 'cmi5':
56
                return new Cmi5Parser($filePath, $course, $session);
57
58
            default:
59
                throw new Exception('Invalid package.');
60
        }
61
    }
62
63
    abstract public function parse(): XApiToolLaunch;
64
}
65