UrlResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 11 4
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\Connector;
12
13
14
class UrlResolver
15
{
16
17
	/**
18
	 * Repository connector.
19
	 *
20
	 * @var Connector
21
	 */
22
	protected $repositoryConnector;
23
24
	/**
25
	 * Creates instance of url resolver.
26
	 *
27
	 * @param Connector $repository_connector Repository connector.
28
	 */
29 19
	public function __construct(Connector $repository_connector)
30
	{
31 19
		$this->repositoryConnector = $repository_connector;
32
	}
33
34
	/**
35
	 * Resolves any url into absolute one using given url for missing parts.
36
	 *
37
	 * @param string $wc_url         Working copy url.
38
	 * @param string $url_to_resolve Url to resolve.
39
	 *
40
	 * @return string
41
	 */
42 18
	public function resolve($wc_url, $url_to_resolve)
43
	{
44 18
		if ( strpos($url_to_resolve, '/') === false && $url_to_resolve !== 'trunk' ) {
45 2
			return dirname($wc_url) . '/' . $url_to_resolve;
46
		}
47
48 16
		if ( preg_match('#^(/|\^/)(.*)$#', $url_to_resolve, $regs) ) {
49 2
			return str_replace(parse_url($wc_url, PHP_URL_PATH), '/' . $regs[2], $wc_url);
50
		}
51
52 14
		return $this->repositoryConnector->getProjectUrl($wc_url) . '/' . $url_to_resolve;
53
	}
54
55
}
56