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

AbstractCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareDependencies() 0 4 1
B getPath() 0 16 5
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