MergeSourceDetectorAggregator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 10 2
A detect() 0 11 3
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\MergeSourceDetector;
12
13
14
class MergeSourceDetectorAggregator extends AbstractMergeSourceDetector
15
{
16
17
	/**
18
	 * Merge sources.
19
	 *
20
	 * @var AbstractMergeSourceDetector[]
21
	 */
22
	private $_detectors = array();
23
24
	/**
25
	 * Adds merge source detector.
26
	 *
27
	 * @param AbstractMergeSourceDetector $merge_source_detector Merge source detector.
28
	 *
29
	 * @return void
30
	 * @throws \InvalidArgumentException When another detector with same weight was added.
31
	 */
32 5
	public function add(AbstractMergeSourceDetector $merge_source_detector)
33
	{
34 5
		$weight = $merge_source_detector->getWeight();
35
36 5
		if ( array_key_exists($weight, $this->_detectors) ) {
37 1
			throw new \InvalidArgumentException('Another detector with same weight is already added.');
38
		}
39
40 5
		$this->_detectors[$weight] = $merge_source_detector;
41 5
		krsort($this->_detectors, SORT_NUMERIC);
42
	}
43
44
	/**
45
	 * Detects merge source from repository url.
46
	 *
47
	 * @param string $repository_url Repository url.
48
	 *
49
	 * @return null|string
50
	 */
51 2
	public function detect($repository_url)
52
	{
53 2
		foreach ( $this->_detectors as $detector ) {
54 2
			$result = $detector->detect($repository_url);
55
56 2
			if ( isset($result) ) {
57 1
				return $result;
58
			}
59
		}
60
61 1
		return null;
62
	}
63
64
}
65