Failed Conditions
Push — master ( 8068fc...341a20 )
by Alexander
02:05
created

RevisionUrlBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 74
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addStyle() 0 3 2
A getMask() 0 25 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;
12
13
14
use ConsoleHelpers\SVNBuddy\Exception\RepositoryCommandException;
15
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector;
16
17
class RevisionUrlBuilder
18
{
19
20
	/**
21
	 * Repository connector.
22
	 *
23
	 * @var Connector
24
	 */
25
	private $_repositoryConnector;
26
27
	/**
28
	 * Repository URL.
29
	 *
30
	 * @var string
31
	 */
32
	private $_repositoryUrl;
33
34
	/**
35
	 * Creates revision url builder instance.
36
	 *
37
	 * @param Connector $repository_connector Repository connector.
38
	 * @param string    $repository_url       Repository URL.
39
	 */
40 7
	public function __construct(Connector $repository_connector, $repository_url)
41
	{
42 7
		$this->_repositoryConnector = $repository_connector;
43 7
		$this->_repositoryUrl = $repository_url;
44
	}
45
46
	/**
47
	 * Returns mask.
48
	 *
49
	 * @param string $style Style.
50
	 *
51
	 * @return string
52
	 */
53 6
	public function getMask($style = '')
54
	{
55
		try {
56 6
			$arcanist_config = \json_decode(
57 6
				$this->_repositoryConnector->getFileContent($this->_repositoryUrl . '/.arcconfig', 'HEAD'),
0 ignored issues
show
Bug introduced by
'HEAD' of type string is incompatible with the type integer expected by parameter $revision of ConsoleHelpers\SVNBuddy\...ector::getFileContent(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
				$this->_repositoryConnector->getFileContent($this->_repositoryUrl . '/.arcconfig', /** @scrutinizer ignore-type */ 'HEAD'),
Loading history...
58 6
				true
59 6
			);
60
		}
61 2
		catch ( RepositoryCommandException $e ) {
62
			// Phabricator integration is not configured.
63 2
			return $this->addStyle($style, '{revision}');
64
		}
65
66
		// Phabricator integration is not configured correctly.
67 4
		if ( !\is_array($arcanist_config)
68 4
			|| !isset($arcanist_config['repository.callsign'], $arcanist_config['phabricator.uri'])
69
		) {
70 2
			return $this->addStyle($style, '{revision}');
71
		}
72
73
		// Phabricator integration is configured properly.
74 2
		$revision_title = $arcanist_config['phabricator.uri'];
75 2
		$revision_title .= 'r' . $arcanist_config['repository.callsign'] . '{revision}';
76
77 2
		return $this->addStyle($style, $revision_title);
78
	}
79
80
	/**
81
	 * Adds style around a text.
82
	 *
83
	 * @param string $style Style.
84
	 * @param string $text  Text.
85
	 *
86
	 * @return string
87
	 */
88 6
	protected function addStyle($style, $text)
89
	{
90 6
		return $style ? '<' . $style . '>' . $text . '</>' : $text;
91
92
	}
93
94
}
95