TemplateInstaller::getInstallPath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * Plugins Management
4
 * @author Joe Huss <[email protected]>
5
 * @copyright 2019
6
 * @package MyAdmin
7
 * @category Plugins
8
 */
9
10
namespace MyAdmin\Plugins;
11
12
use Composer\Package\PackageInterface;
13
use Composer\Installer\LibraryInstaller;
14
15
/**
16
 * Class TemplateInstaller
17
 *
18
 * @package MyAdmin\Plugins
19
 */
20
class TemplateInstaller extends LibraryInstaller
21
{
22
	/**
23
	 * {@inheritDoc}
24
	 * @throws \InvalidArgumentException
25
	 */
26
	public function getInstallPath(PackageInterface $package)
27
	{
28
		$prefix = mb_substr($package->getPrettyName(), 0, 23);
29
		if ('myadmin/template-' !== $prefix) {
30
			throw new \InvalidArgumentException(
31
				'Unable to install template, myadmin templates '
32
				.'should always start their package name with '
33
				.'"myadmin/template-"'
34
			);
35
		}
36
		return 'data/templates/'.mb_substr($package->getPrettyName(), 23);
37
	}
38
39
	/**
40
	 * {@inheritDoc}
41
	 */
42
	public function supports($packageType)
43
	{
44
		return 'myadmin-template' === $packageType;
45
	}
46
}
47