Completed
Push — master ( 9a3a3c...24148b )
by Michael
14s
created

UpdateCommand::runCommand()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 9
cp 0
rs 9.584
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12

1 Method

Rating   Name   Duplication   Size   Complexity  
A UpdateCommand::configure() 0 4 1
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer\Commands;
10
11
use Joomla\Console\Command\AbstractCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Process\Exception\ProcessFailedException;
15
use Symfony\Component\Process\Process;
16
17
/**
18
 * Update command
19
 */
20
class UpdateCommand extends AbstractCommand
21
{
22
	/**
23
	 * The default command name
24
	 *
25
	 * @var  string|null
26
	 */
27
	protected static $defaultName = 'update:server';
28
29
	/**
30
	 * Internal function to execute the command.
31
	 *
32
	 * @param   InputInterface   $input   The input to inject into the command.
33
	 * @param   OutputInterface  $output  The output to inject into the command.
34
	 *
35
	 * @return  integer  The command exit code
36
	 */
37
	protected function doExecute(InputInterface $input, OutputInterface $output): int
38
	{
39
		$symfonyStyle = new SymfonyStyle($input, $output);
40
41
		$symfonyStyle->title('Update Server');
42
		$symfonyStyle->comment('Updating server to git HEAD');
43
44
		// Pull from remote repo
45
		try
46
		{
47
			(new Process('git pull', APPROOT))->mustRun();
0 ignored issues
show
Documentation introduced by
'git pull' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
		}
49
		catch (ProcessFailedException $e)
50
		{
51
			$this->getApplication()->getLogger()->error('Could not execute `git pull`', ['exception' => $e]);
52
53
			$symfonyStyle->error('Error running `git pull`: ' . $e->getMessage());
54
55
			return 1;
56
		}
57
58
		$symfonyStyle->comment('Updating Composer resources');
59
60
		// Run Composer install
61
		try
62
		{
63
			(new Process('composer install --no-dev -o -a', APPROOT))->mustRun();
0 ignored issues
show
Documentation introduced by
'composer install --no-dev -o -a' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
		}
65
		catch (ProcessFailedException $e)
66
		{
67
			$this->getApplication()->getLogger()->error('Could not update Composer resources', ['exception' => $e]);
68
69
			$symfonyStyle->error('Error updating Composer resources: ' . $e->getMessage());
70
71
			return 1;
72
		}
73
74
		$symfonyStyle->success('Update complete');
75
76
		return 0;
77
	}
78
79
	/**
80
	 * Configures the current command.
81
	 *
82
	 * @return  void
83
	 */
84
	protected function configure(): void
85
	{
86
		$this->setDescription('Update the server to the current git HEAD');
87
	}
88
}
89