GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 40ad3b...fa031e )
by Felix
06:30
created

tx_t3deploy_dispatch::getClassInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
/***************************************************************
3
*  Copyright notice
4
*
5
*  (c) 2016 AOE GmbH <[email protected]>
6
*  All rights reserved
7
*
8
*  This copyright notice MUST APPEAR in all copies of the script!
9
***************************************************************/
10
11
use \TYPO3\CMS\Core\Utility\GeneralUtility;
12
13
/**
14
 * General CLI dispatcher for the t3deploy extension.
15
 *
16
 * @package t3deploy
17
 * @author Oliver Hader <[email protected]>
18
 */
19
class tx_t3deploy_dispatch extends \TYPO3\CMS\Core\Controller\CommandLineController {
20
	const ExtKey = 't3deploy';
0 ignored issues
show
Coding Style introduced by
Constant ExtKey should be defined in uppercase
Loading history...
21
	const Mask_ClassName = 'tx_t3deploy_%sController';
0 ignored issues
show
Coding Style introduced by
Constant Mask_ClassName should be defined in uppercase
Loading history...
22
	const Mask_ClassFile = 'Classes/class.tx_t3deploy_%sController.php';
0 ignored issues
show
Coding Style introduced by
Constant Mask_ClassFile should be defined in uppercase
Loading history...
23
	const Mask_Action = '%sAction';
0 ignored issues
show
Coding Style introduced by
Constant Mask_Action should be defined in uppercase
Loading history...
24
25
	/**
26
	 * @var array
27
	 */
28
	protected $classInstances = array();
29
30
	/**
31
	 * Creates this object.
32
	 */
33
	public function __construct() {
34
		parent::__construct();
35
36
		$this->setCliOptions();
37
38
		$this->cli_help = array_merge($this->cli_help, array(
39
			'name' => 'tx_t3deploy_dispatch',
40
			'synopsis' => self::ExtKey . ' controller action ###OPTIONS###',
41
			'description' => 'TYPO3 dispatcher for database related operations.',
42
			'examples' => 'typo3/cli_dispatch.phpsh ' . self::ExtKey . ' database updateStructure',
43
			'author' => '(c) 2012 - 2016 AOE GmbH <[email protected]>',
44
		));
45
	}
46
47
	/**
48
	 * Sets the CLI arguments.
49
	 *
50
	 * @param array $arguments
51
	 * @return void
52
	 */
53
	public function setCliArguments(array $arguments) {
54
		$this->cli_args = $arguments;
55
	}
56
57
	/**
58
	 * Gets or generates an instance of the given class name.
59
	 *
60
	 * @param string $className
61
	 * @return object
62
	 */
63
	public function getClassInstance($className) {
64
		if (!isset($this->classInstances[$className])) {
65
			$this->classInstances[$className] = GeneralUtility::makeInstance($className);
66
		}
67
		return $this->classInstances[$className];
68
	}
69
70
	/**
71
	 * Sets an instance for the given class name.
72
	 *
73
	 * @param string $className
74
	 * @param object $classInstance
75
	 * @return void
76
	 */
77
	public function setClassInstance($className, $classInstance) {
78
		$this->classInstances[$className] = $classInstance;
79
	}
80
81
	/**
82
	 * Dispatches the requested actions to the accordant controller.
83
	 *
84
	 * @return mixed
85
	 * @throws Exception
86
	 */
87
	public function dispatch() {
88
		$controller = (string)$this->cli_args['_DEFAULT'][1];
89
		$action = (string)$this->cli_args['_DEFAULT'][2];
90
91
		if (!$controller || !$action) {
92
			$this->cli_validateArgs();
93
			$this->cli_help();
94
			exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method dispatch() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
95
		}
96
97
		$className = sprintf(self::Mask_ClassName, $controller);
98
		$classFile = sprintf(self::Mask_ClassFile, $controller);
99
		$actionName = sprintf(self::Mask_Action, $action);
100
101
		if (!class_exists($className)) {
102
			GeneralUtility::requireOnce(PATH_tx_t3deploy . $classFile);
103
		}
104
105
		$instance = $this->getClassInstance($className);
106
107
		if (!is_callable(array($instance, $actionName))) {
108
			throw new Exception('The action ' . $action . ' is not implemented in controller ' . $controller);
109
		}
110
111
		$result = call_user_func_array(
112
			array($instance, $actionName),
113
			array($this->cli_args)
114
		);
115
116
		return $result;
117
	}
118
119
	/**
120
	 * Sets the CLI options for help.
121
	 *
122
	 * @return void
123
	 */
124
	protected function setCliOptions() {
125
		$this->cli_options = array(
126
			array('--verbose', 'Report changes'),
127
			array('-v', 'Same as --verbose'),
128
			array('--execute', 'Execute changes (updates, removals)'),
129
			array('-e', 'Same as --execute'),
130
			array('--remove', 'Include structure differences for removal'),
131
			array('-r', 'Same as --remove'),
132
			array('--drop-keys', 'Removes key modifications that will cause errors'),
133
			array('--dump-file', 'Dump changes to file'),
134
			array('--excludes', 'Exclude update types (add,change,create_table,change_table,drop,drop_table,clear_table)')
135
		);
136
	}
137
}
138