TemplateInstaller   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 25
ccs 0
cts 14
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstallPath() 0 11 2
A supports() 0 3 1
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