Failed Conditions
Push — master ( 17cdc3...604e06 )
by Alexander
05:14
created

AbstractCommand::getPath()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.2
cc 4
eloc 6
nc 2
nop 1
crap 20
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
		$path = realpath($raw_path);
44
45
		if ( !$path || !file_exists($path) || !is_dir($path) ) {
46
			throw new \InvalidArgumentException('The "' . $raw_path . '" path is invalid.');
47
		}
48
49
		return $path;
50
	}
51
52
}
53