AlreadyExtractFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
1
<?php
2
3
namespace AlreadyExtract\Factory;
4
5
use AlreadyExtract\Checker\AlreadyExtractCheckerInterface;
6
use AlreadyExtract\Checker\RarAlreadyExtractChecker;
7
use AlreadyExtract\Checker\ZipAlreadyExtractChecker;
8
9
class AlreadyExtractFactory
10
{
11
    const ZIP = 'zip';
12
    const RAR = 'rar';
13
14
    /**
15
     * @param $path
16
     * @param $type
17
     * @return AlreadyExtractCheckerInterface
18
     * @throws \Exception
19
     */
20
    public static function create($path, $type)
21
    {
22
        switch ($type) {
23
            case self::ZIP:
24
                return new ZipAlreadyExtractChecker($path);
25
            case self::RAR:
26
                return new RarAlreadyExtractChecker($path);
27
            default:
28
                throw new \Exception('Unknown archive type');
29
        }
30
    }
31
}