Completed
Push — master ( f2828f...7fcd15 )
by Alexander
02:39
created

MergeTemplateFactory::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Repository\CommitMessage;
12
13
14
class MergeTemplateFactory
15
{
16
17
	/**
18
	 * Merge templates.
19
	 *
20
	 * @var AbstractMergeTemplate[]
21
	 */
22
	protected $mergeTemplates = array();
23
24
	/**
25
	 * Adds merge template.
26
	 *
27
	 * @param AbstractMergeTemplate $merge_template Merge template.
28
	 *
29
	 * @return void
30
	 * @throws \LogicException When merge template is already added.
31
	 */
32 4
	public function add(AbstractMergeTemplate $merge_template)
33
	{
34 4
		$name = $merge_template->getName();
35
36 4
		if ( array_key_exists($name, $this->mergeTemplates) ) {
37 1
			throw new \LogicException('The merge template with "' . $name . '" name is already added.');
38
		}
39
40 4
		$this->mergeTemplates[$name] = $merge_template;
41 4
	}
42
43
	/**
44
	 * Gets merge template by name.
45
	 *
46
	 * @param string $name Merge template name.
47
	 *
48
	 * @return AbstractMergeTemplate
49
	 * @throws \LogicException When merge template wasn't found.
50
	 */
51 2
	public function get($name)
52
	{
53 2
		if ( !array_key_exists($name, $this->mergeTemplates) ) {
54 1
			throw new \LogicException('The merge template with "' . $name . '" name is not found.');
55
		}
56
57 1
		return $this->mergeTemplates[$name];
58
	}
59
60
	/**
61
	 * Returns merge template names.
62
	 *
63
	 * @return array
64
	 */
65 1
	public function getNames()
66
	{
67 1
		return array_keys($this->mergeTemplates);
68
	}
69
70
}
71