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.

RemoveProjectCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
namespace Kunstmaan\Skylab\Command;
3
4
use Kunstmaan\Skylab\Skeleton\AbstractSkeleton;
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
/**
10
 * RemoveProjectCommand
11
 */
12
class RemoveProjectCommand extends AbstractCommand
13
{
14
15
    /**
16
     * Configures the current command.
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->addDefaults()
22
            ->setName('remove')
23
            ->setDescription('Removes a Skylab project')
24
            ->addArgument('name', InputArgument::OPTIONAL, 'The name of the project.')
25
            ->addOption("force", null, InputOption::VALUE_NONE, 'Does not ask before removing')
26
            ->setHelp(<<<EOT
27
The <info>remove</info> command will remove the project after creating a backup first.
28
29
<info>php skylab.phar remove testproject</info>                         # Will remove the testproject project
30
<info>php skylab.phar remove testproject --force</info>                 # Will do the same, but don't ask you if you are sure.
31
32
EOT
33
            );
34
    }
35
36
    protected function doExecute()
37
    {
38
        $projectname = $this->dialogProvider->askFor("Please enter the name of the project", 'name');
39
40
        // Check if the project exists, do use in creating a new one with the same name.
41
        if (!$this->fileSystemProvider->projectExists($projectname)) {
42
            $this->dialogProvider->logError("A project with name $projectname does not exists!", false);
43
        }
44
45
        if (!$this->input->getOption('force') && !$this->dialogProvider->askConfirmation('Are you sure you want to remove ' . $projectname . '?')) {
46
            return;
47
        }
48
49
        $this->dialogProvider->logStep("Removing project $projectname");
50
51
        $command = $this->getApplication()->find('backup');
52
        $arguments = array(
53
            'command' => 'backup',
54
            'project' => $projectname,
55
            '--hideLogo' => true
56
        );
57
        $input = new ArrayInput($arguments);
58
        $returnCode = $command->run($input, $this->output);
59
60
        if (!$returnCode) {
61
            $this->permissionsProvider->killProcesses($projectname);
62
        }
63
64
        $project = $this->projectConfigProvider->loadProjectConfig($projectname);
65
66
        $this->skeletonProvider->skeletonLoop(function (AbstractSkeleton $skeleton) use ($project) {
67
            $this->dialogProvider->logTask("Running preRemove for skeleton " . $skeleton->getName());
68
            $skeleton->preRemove($project);
69
        }, new \ArrayObject($project["skeletons"]));
70
71
        $this->dialogProvider->logTask("Deleting the project folder at " . $this->fileSystemProvider->getProjectDirectory($projectname));
72
        $this->fileSystemProvider->removeProjectDirectory($project);
73
74
        $this->skeletonProvider->skeletonLoop(function (AbstractSkeleton $skeleton) use ($project) {
75
            $this->dialogProvider->logTask("Running postRemove for skeleton " . $skeleton->getName());
76
            $skeleton->postRemove($project);
77
        }, new \ArrayObject($project["skeletons"]));
78
    }
79
}
80