UrlResolver::resolve()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 4
nc 3
nop 2
crap 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