Completed
Push — master ( ed845b...38c1c8 )
by Luke
04:37
created

PackageCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 7
crap 2
1
<?php
2
3
/**
4
 * Moodle component manager.
5
 *
6
 * @author Luke Carrier <[email protected]>
7
 * @copyright 2016 Luke Carrier
8
 * @license GPL-3.0+
9
 */
10
11
namespace ComponentManager\Command;
12
13
use ComponentManager\Console\Argument;
14
use ComponentManager\Moodle;
15
use ComponentManager\MoodleApi;
16
use ComponentManager\PackageFormat\PackageFormatFactory;
17
use ComponentManager\PackageRepository\PackageRepositoryFactory;
18
use ComponentManager\PackageSource\PackageSourceFactory;
19
use ComponentManager\Platform\Platform;
20
use ComponentManager\Task\PackageTask;
21
use Psr\Log\LoggerInterface;
22
use Symfony\Component\Console\Input\InputDefinition;
23
use Symfony\Component\Console\Input\InputInterface;
24
use Symfony\Component\Console\Input\InputOption;
25
use Symfony\Component\Console\Output\OutputInterface;
26
use Symfony\Component\Filesystem\Filesystem;
27
28
/**
29
 * Package command.
30
 *
31
 * Assembles an entire Moodle instance from the specified project file, then
32
 * packages it in the specified format.
33
 */
34
class PackageCommand extends ProjectAwareCommand {
35
    /**
36
     * Help.
37
     *
38
     * @var string
39
     */
40
    const HELP = <<<HELP
41
Packages a Moodle site from a project file.
42
HELP;
43
44
    /**
45
     * Moodle.org plugin and update API.
46
     *
47
     * @var MoodleApi
48
     */
49
    protected $moodleApi;
50
51
    /**
52
     * Initialiser.
53
     *
54
     * @param \ComponentManager\PackageRepository\PackageRepositoryFactory $packageRepositoryFactory
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 100 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
55
     * @param \ComponentManager\PackageSource\PackageSourceFactory         $packageSourceFactory
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 96 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
56
     * @param \ComponentManager\PackageFormat\PackageFormatFactory         $packageFormatFactory
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 96 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
57
     * @param \ComponentManager\MoodleApi                                  $moodleApi
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 85 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
     * @param \Symfony\Component\Filesystem\Filesystem                     $filesystem
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 86 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
     * @param \ComponentManager\Platform\Platform                          $platform
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 84 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
60
     * @param \Psr\Log\LoggerInterface                                     $logger
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 82 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
     */
62
    public function __construct(PackageRepositoryFactory $packageRepositoryFactory,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 83 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
63
                                PackageSourceFactory $packageSourceFactory,
64
                                PackageFormatFactory $packageFormatFactory,
65
                                MoodleApi $moodleApi, Filesystem $filesystem,
66
                                Platform $platform, LoggerInterface $logger) {
67
        $this->moodleApi = $moodleApi;
68
69
        parent::__construct(
70
                $packageRepositoryFactory, $packageSourceFactory,
71
                $packageFormatFactory, $platform, $filesystem, $logger);
72
    }
73
74
    /**
75
     * @override \ComponentManager\Command\AbstractCommand
76
     */
77
    protected function configure() {
78
        $this
79
            ->setName('package')
80
            ->setDescription('Packages a Moodle site from a project file')
81
            ->setHelp(static::HELP)
82
            ->setDefinition(new InputDefinition([
83
                new InputOption(Argument::OPTION_PACKAGE_FORMAT, null,
84
                                InputOption::VALUE_REQUIRED,
85
                                Argument::OPTION_PACKAGE_FORMAT_HELP),
86
                new InputOption(Argument::OPTION_PROJECT_FILE, null,
87
                                InputOption::VALUE_REQUIRED,
88
                                Argument::OPTION_PROJECT_FILE_HELP),
89
                new InputOption(Argument::OPTION_PACKAGE_DESTINATION, null,
90
                                InputOption::VALUE_REQUIRED,
91
                                Argument::OPTION_PACKAGE_DESTINATION_HELP),
92
            ]));
93
    }
94
95
    /**
96
     * @override \ComponentManager\Command\AbstractCommand
97
     */
98
    protected function execute(InputInterface $input, OutputInterface $output) {
99
        $projectFilename = $input->getOption(Argument::OPTION_PROJECT_FILE);
100
        $packageDestination = $this->platform->expandPath(
101
                $input->getOption(Argument::OPTION_PACKAGE_DESTINATION));
102
        $packageFormat   = $input->getOption(Argument::OPTION_PACKAGE_FORMAT);
103
104
        $tempDirectory       = $this->platform->createTempDirectory();
105
        $archive             = $tempDirectory
106
                             . $this->platform->getDirectorySeparator()
107
                             . 'moodle.zip';
108
        $destination         = $tempDirectory
109
                             . $this->platform->getDirectorySeparator() . 'moodle';
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 83 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
110
        $projectLockFilename = $destination . $this->platform->getDirectorySeparator()
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 86 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
111
                             . 'componentmgr.lock.json';
112
113
        $moodle  = new Moodle($destination, $this->platform);
114
        $project = $this->getProject($projectFilename, $projectLockFilename);
115
116
        $task = new PackageTask(
117
                $this->moodleApi, $project, $archive, $destination,
118
                $this->platform, $this->filesystem, $moodle, $packageFormat,
119
                $packageDestination);
120
        $task->execute($this->logger);
121
    }
122
}
123