Completed
Push — master ( 5d29b3...11effe )
by Nazar
04:11
created

Controller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index_help() 0 16 1
A index_update() 0 13 1
A index_clean() 0 6 2
1
<?php
2
/**
3
 * @package   Composer
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\Composer\cli;
10
use
11
	cs\modules\Composer\Composer,
12
	cs\Event,
13
	cs\ExitException;
14
15
class Controller {
16
	static function index_help () {
17
		return <<<HELP
18
%yComposer module%n
19
20
%yMethods:%n
21
  %gupdate%n  Update Composer using system configuration
22
  %gclean%n   Clean Composer's files (composer.json/lock as well as vendor directory, useful if %gupdate%n fails)
23
24
%yExamples:%n
25
  Update Composer:
26
    %g./cli update:Composer%n
27
  Clean Composer's files:
28
    %g./cli clean:Composer%n
29
30
HELP;
31
	}
32
	/**
33
	 * @param \cs\Request  $Request
34
	 * @param \cs\Response $Response
35
	 */
36
	static function index_update (
37
		/** @noinspection PhpUnusedParameterInspection */
38
		$Request,
1 ignored issue
show
Unused Code introduced by
The parameter $Request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
		$Response
40
	) {
41
		$callback = function ($data) {
42
			echo $data['message'];
43
		};
44
		$Event    = Event::instance();
45
		$Event->on('Composer/update_progress', $callback);
46
		$Response->code = Composer::instance()->force_update();
0 ignored issues
show
Documentation Bug introduced by
It seems like \cs\modules\Composer\Com...tance()->force_update() of type array is incompatible with the declared type integer of property $code.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
		$Event->off('Composer/update_progress', $callback);
48
	}
49
	/**
50
	 * @return string
51
	 *
52
	 * @throws ExitException
53
	 */
54
	static function index_clean () {
55
		if (!rmdir_recursive(STORAGE.'/Composer')) {
56
			throw new ExitException(500);
57
		}
58
		return "%gOK%n\n";
59
	}
60
}
61