Factory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 71
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInstance() 0 15 2
A __callStatic() 0 14 4
A __clone() 0 3 1
1
<?php
2
/**
3
 * VersionControl_HG
4
 * Simple OO implementation for Mercurial.
5
 *
6
 * PHP Version 5.4
7
 *
8
 * @copyright 2014 Siad Ardroumli
9
 * @license http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link http://siad007.github.io/versioncontrol_hg
11
 */
12
13
namespace Siad007\VersionControl\HG;
14
15
/**
16
 * Factory class.
17
 *
18
 * @method static Command\AddCommand createAdd(array $options = [])
19
 * @method static Command\AddremoveCommand createAddremove(array $options = [])
20
 * @method static Command\AnnotateCommand createAnnotate(array $options = [])
21
 * @method static Command\ArchiveCommand createArchive(array $options = [])
22
 * @method static Command\BackoutCommand createBackout(array $options = [])
23
 * @method static Command\BisecCommand createBisec(array $options = [])
24
 * @method static Command\BlameCommand createBlame(array $options = [])
25
 * @method static Command\BookmarksCommand createBookmarks(array $options = [])
26
 * @method static Command\BranchCommand createBranch(array $options = [])
27
 * @method static Command\BranchesCommand createBranches(array $options = [])
28
 * @method static Command\BundleCommand createBundle(array $options = [])
29
 * @method static Command\CatCommand createCat(array $options = [])
30
 * @method static Command\CloneCommand createClone(array $options = [])
31
 * @method static Command\CommitCommand createCommit(array $options = [])
32
 * @method static Command\ConfigCommand createConfig(array $options = [])
33
 * @method static Command\CopyCommand createCopy(array $options = [])
34
 * @method static Command\ForgetCommand createForget(array $options = [])
35
 * @method static Command\HeadsCommand createHeads(array $options = [])
36
 * @method static Command\IdentifyCommand createIdentify(array $options = [])
37
 * @method static Command\ImportCommand createImport(array $options = [])
38
 * @method static Command\InitCommand createInit(array $options = [])
39
 * @method static Command\LocateCommand createLocate(array $options = [])
40
 * @method static Command\LogCommand createLog(array $options = [])
41
 * @method static Command\ManifestCommand createManifest(array $options = [])
42
 * @method static Command\MergeCommand createMerge(array $options = [])
43
 * @method static Command\PathsCommand createPaths(array $options = [])
44
 * @method static Command\ParentsCommand createParents(array $options = [])
45
 * @method static Command\PhaseCommand createPhase(array $options = [])
46
 * @method static Command\PullCommand createPull(array $options = [])
47
 * @method static Command\PushCommand createPush(array $options = [])
48
 * @method static Command\RecoverCommand createRecover(array $options = [])
49
 * @method static Command\RemoveCommand createRemove(array $options = [])
50
 * @method static Command\RenameCommand createRename(array $options = [])
51
 * @method static Command\ResolveCommand createResolve(array $options = [])
52
 * @method static Command\RevertCommand createRevert(array $options = [])
53
 * @method static Command\RootCommand createRoot(array $options = [])
54
 * @method static Command\StatusCommand createStatus(array $options = [])
55
 * @method static Command\SummaryCommand createSummary(array $options = [])
56
 * @method static Command\TagCommand createTag(array $options = [])
57
 * @method static Command\TagsCommand createTags(array $options = [])
58
 * @method static Command\UnbundleCommand createUnbundle(array $options = [])
59
 * @method static Command\UpdateCommand createUpdate(array $options = [])
60
 * @method static Command\VerifyCommand createVerify(array $options = [])
61
 * @method static Command\VersionCommand createVersion(array $options = [])
62
 */
63
class Factory
64
{
65
    /**
66
     * Disabled constructor.
67
     *
68
     * @codeCoverageIgnore
69
     */
70
    final private function __construct()
71
    {
72
    }
73
74
    /**
75
     * Factory method.
76
     *
77
     * @param string $command
78
     * @param array  $options
79
     *
80
     * @return Command\AbstractCommand
81
     *
82
     * @throws \InvalidArgumentException
83
     */
84 48
    public static function getInstance($command, $options = [])
85
    {
86 48
        $commandClassName = sprintf(
87 48
            '\\Siad007\\VersionControl\\HG\\Command\\%sCommand',
88
            ucfirst($command)
89
        );
90
91 48
        if (!class_exists($commandClassName)) {
92 1
            throw new \InvalidArgumentException(
93 1
                "Command $commandClassName not supported."
94
            );
95
        }
96
97 47
        return new $commandClassName($options);
98
    }
99
100
    /**
101
     * Magic method to reduce the number of methods.
102
     *
103
     * @param string $name
104
     * @param array  $arguments
105
     *
106
     * @return Command\AbstractCommand
107
     *
108
     * @throws \InvalidArgumentException
109
     */
110 42
    public static function __callStatic($name, $arguments)
111
    {
112 42
        if (strpos($name, 'create') !== 0) {
113 1
            throw new \InvalidArgumentException(
114 1
                "Create command $name not supported."
115
            );
116
        } else {
117 41
            $command = strtolower(str_replace('create', '', $name));
118
        }
119
120 41
        $options = isset($arguments[0]) && is_array($arguments[0]) ? $arguments[0] : [];
121
122 41
        return self::getInstance($command, $options);
123
    }
124
125
    /**
126
     * Disabled clone behavior.
127
     *
128
     * @codeCoverageIgnore
129
     */
130
    private function __clone()
131
    {
132
    }
133
}
134