UrlResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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