Completed
Push — master ( cbb650...b6a2ec )
by Alexander
02:04
created

AbstractCommand::getPath()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 8.8571
c 1
b 0
f 0
cc 5
eloc 8
nc 3
nop 1
crap 30
1
<?php
2
/**
3
 * This file is part of the Code-Insight 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/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\Command;
12
13
14
use ConsoleHelpers\ConsoleKit\Command\AbstractCommand as BaseCommand;
15
16
/**
17
 * Base command class.
18
 */
19
abstract class AbstractCommand extends BaseCommand
20
{
21
22
	/**
23
	 * Prepare dependencies.
24
	 *
25
	 * @return void
26
	 */
27
	protected function prepareDependencies()
28
	{
29
		$container = $this->getContainer();
0 ignored issues
show
Unused Code introduced by
$container is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
	}
31
32
	/**
33
	 * Returns and validates path.
34
	 *
35
	 * @param string $argument_name Argument name, that contains path.
36
	 *
37
	 * @return string
38
	 * @throws \InvalidArgumentException When path isn't valid.
39
	 */
40
	protected function getPath($argument_name)
41
	{
42
		$raw_path = $this->io->getArgument($argument_name);
43
44
		if ( !$raw_path ) {
45
			return '';
46
		}
47
48
		$path = realpath($raw_path);
49
50
		if ( !$path || !file_exists($path) || !is_dir($path) ) {
51
			throw new \InvalidArgumentException('The "' . $raw_path . '" path is invalid.');
52
		}
53
54
		return $path;
55
	}
56
57
}
58