Skip to content

Commit 11c59d8

Browse files
authored
Fix code-style and docs (drupal-composer#74)
1 parent 877ae16 commit 11c59d8

8 files changed

+83
-67
lines changed

src/CommandProvider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
66

7+
/**
8+
* List of all commands provided by this package.
9+
*/
710
class CommandProvider implements CommandProviderCapability {
811

912
/**
1013
* {@inheritdoc}
1114
*/
1215
public function getCommands() {
1316
return [
14-
new DrupalScaffoldCommand()
17+
new DrupalScaffoldCommand(),
1518
];
1619
}
1720

src/DrupalScaffoldCommand.php

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88

9+
/**
10+
* The "drupal:scaffold" command class.
11+
*
12+
* Downloads scaffold files and generates the autoload.php file.
13+
*/
914
class DrupalScaffoldCommand extends BaseCommand {
1015

1116
/**

src/FileFetcher.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Contains \DrupalComposer\DrupalScaffold\FileFetcher.
6-
*/
7-
83
namespace DrupalComposer\DrupalScaffold;
94

105
use Composer\IO\IOInterface;
116
use Composer\Util\Filesystem;
127
use Composer\Util\RemoteFilesystem;
138

9+
/**
10+
* Downloads all required files and writes it to the file system.
11+
*/
1412
class FileFetcher {
1513

1614
/**
@@ -34,6 +32,9 @@ class FileFetcher {
3432
protected $filenames;
3533
protected $fs;
3634

35+
/**
36+
* Constructs this FileFetcher object.
37+
*/
3738
public function __construct(RemoteFilesystem $remoteFilesystem, $source, IOInterface $io, $progress = TRUE) {
3839
$this->remoteFilesystem = $remoteFilesystem;
3940
$this->io = $io;
@@ -42,6 +43,9 @@ public function __construct(RemoteFilesystem $remoteFilesystem, $source, IOInter
4243
$this->progress = $progress;
4344
}
4445

46+
/**
47+
* Downloads all required files and writes it to the file system.
48+
*/
4549
public function fetch($version, $destination, $override) {
4650
foreach ($this->filenames as $sourceFilename => $filename) {
4751
$target = "$destination/$filename";
@@ -62,14 +66,20 @@ public function fetch($version, $destination, $override) {
6266
}
6367
}
6468

69+
/**
70+
* Set filenames.
71+
*/
6572
public function setFilenames(array $filenames) {
6673
$this->filenames = $filenames;
6774
}
6875

76+
/**
77+
* Replace filename and version in the source pattern with their values.
78+
*/
6979
protected function getUri($filename, $version) {
7080
$map = [
7181
'{path}' => $filename,
72-
'{version}' => $version
82+
'{version}' => $version,
7383
];
7484
return str_replace(array_keys($map), array_values($map), $this->source);
7585
}

src/Handler.php

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Contains \DrupalComposer\DrupalScaffold\Handler.
6-
*/
7-
83
namespace DrupalComposer\DrupalScaffold;
94

5+
use Composer\Script\Event;
6+
use Composer\Installer\PackageEvent;
7+
use Composer\Plugin\CommandEvent;
108
use Composer\Composer;
119
use Composer\DependencyResolver\Operation\InstallOperation;
1210
use Composer\DependencyResolver\Operation\UpdateOperation;
@@ -18,6 +16,9 @@
1816
use Composer\Util\RemoteFilesystem;
1917
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
2018

19+
/**
20+
* Core class of the plugin, contains all logic which files should be fetched.
21+
*/
2122
class Handler {
2223

2324
const PRE_DRUPAL_SCAFFOLD_CMD = 'pre-drupal-scaffold-cmd';
@@ -48,8 +49,8 @@ class Handler {
4849
/**
4950
* Handler constructor.
5051
*
51-
* @param Composer $composer
52-
* @param IOInterface $io
52+
* @param \Composer\Composer $composer
53+
* @param \Composer\IO\IOInterface $io
5354
*/
5455
public function __construct(Composer $composer, IOInterface $io) {
5556
$this->composer = $composer;
@@ -79,7 +80,7 @@ protected function getCorePackage($operation) {
7980
*
8081
* @param \Composer\Plugin\CommandEvent $event
8182
*/
82-
public function onCmdBeginsEvent(\Composer\Plugin\CommandEvent $event) {
83+
public function onCmdBeginsEvent(CommandEvent $event) {
8384
if ($event->getInput()->hasOption('no-progress')) {
8485
$this->progress = !($event->getInput()->getOption('no-progress'));
8586
}
@@ -93,7 +94,7 @@ public function onCmdBeginsEvent(\Composer\Plugin\CommandEvent $event) {
9394
*
9495
* @param \Composer\Installer\PackageEvent $event
9596
*/
96-
public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){
97+
public function onPostPackageEvent(PackageEvent $event) {
9798
$package = $this->getCorePackage($event->getOperation());
9899
if ($package) {
99100
// By explicitly setting the core package, the onPostCmdEvent() will
@@ -107,7 +108,7 @@ public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){
107108
*
108109
* @param \Composer\Script\Event $event
109110
*/
110-
public function onPostCmdEvent(\Composer\Script\Event $event) {
111+
public function onPostCmdEvent(Event $event) {
111112
// Only install the scaffolding if drupal/core was installed,
112113
// AND there are no scaffolding files present.
113114
if (isset($this->drupalCorePackage)) {
@@ -138,10 +139,10 @@ public function downloadScaffold() {
138139

139140
$fetcher = new PrestissimoFileFetcher($remoteFs, $options['source'], $this->io, $this->progress, $this->composer->getConfig());
140141
$fetcher->setFilenames(array_combine($files, $files));
141-
$fetcher->fetch($version, $webroot, true);
142+
$fetcher->fetch($version, $webroot, TRUE);
142143

143144
$fetcher->setFilenames($this->getInitial());
144-
$fetcher->fetch($version, $webroot, false);
145+
$fetcher->fetch($version, $webroot, FALSE);
145146

146147
// Call post-scaffold scripts.
147148
$dispatcher->dispatch(self::POST_DRUPAL_SCAFFOLD_CMD);
@@ -212,7 +213,7 @@ public function getVendorPath() {
212213
* Look up the Drupal core package object, or return it from where we cached
213214
* it in the $drupalCorePackage field.
214215
*
215-
* @return PackageInterface
216+
* @return \Composer\Package\PackageInterface
216217
*/
217218
public function getDrupalCorePackage() {
218219
if (!isset($this->drupalCorePackage)) {
@@ -240,7 +241,7 @@ protected function getDrupalCoreVersion(PackageInterface $drupalCorePackage) {
240241
/**
241242
* Retrieve the path to the web root.
242243
*
243-
* @return string
244+
* @return string
244245
*/
245246
public function getWebRoot() {
246247
$drupalCorePackage = $this->getDrupalCorePackage();
@@ -258,7 +259,7 @@ public function getWebRoot() {
258259
* @param string $name
259260
* Name of the package to get from the current composer installation.
260261
*
261-
* @return PackageInterface
262+
* @return \Composer\Package\PackageInterface
262263
*/
263264
protected function getPackage($name) {
264265
return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
@@ -361,7 +362,7 @@ protected function getIncludesDefault() {
361362
'sites/example.settings.local.php',
362363
'sites/example.sites.php',
363364
'update.php',
364-
'web.config'
365+
'web.config',
365366
];
366367

367368
// Version specific variations.

src/Plugin.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
<?php
2-
/**
3-
* @file
4-
* Contains DrupalComposer\DrupalScaffold\Plugin.
5-
*/
62

73
namespace DrupalComposer\DrupalScaffold;
84

5+
use Composer\Script\Event;
6+
use Composer\Plugin\CommandEvent;
97
use Composer\Composer;
108
use Composer\EventDispatcher\EventSubscriberInterface;
119
use Composer\Installer\PackageEvent;
1210
use Composer\Installer\PackageEvents;
1311
use Composer\IO\IOInterface;
1412
use Composer\Plugin\Capable;
15-
use Composer\Plugin\CommandEvent;
1613
use Composer\Plugin\PluginEvents;
1714
use Composer\Plugin\PluginInterface;
1815
use Composer\Script\ScriptEvents;
@@ -64,7 +61,7 @@ public static function getSubscribedEvents() {
6461
*
6562
* @param \Composer\Plugin\CommandEvent $event
6663
*/
67-
public function cmdBegins(\Composer\Plugin\CommandEvent $event) {
64+
public function cmdBegins(CommandEvent $event) {
6865
$this->handler->onCmdBeginsEvent($event);
6966
}
7067

@@ -82,7 +79,7 @@ public function postPackage(PackageEvent $event) {
8279
*
8380
* @param \Composer\Script\Event $event
8481
*/
85-
public function postCmd(\Composer\Script\Event $event) {
82+
public function postCmd(Event $event) {
8683
$this->handler->onPostCmdEvent($event);
8784
}
8885

@@ -95,7 +92,7 @@ public function postCmd(\Composer\Script\Event $event) {
9592
* @deprecated since version 2.5.0, to be removed in 3.0. Use the command
9693
* "composer drupal:scaffold" instead.
9794
*/
98-
public static function scaffold(\Composer\Script\Event $event) {
95+
public static function scaffold(Event $event) {
9996
@trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED);
10097
$handler = new Handler($event->getComposer(), $event->getIO());
10198
$handler->downloadScaffold();

src/PrestissimoFileFetcher.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Contains \DrupalComposer\DrupalScaffold\FileFetcher.
6-
*/
7-
83
namespace DrupalComposer\DrupalScaffold;
94

5+
use Composer\Util\RemoteFilesystem;
106
use Composer\Config;
117
use Composer\IO\IOInterface;
128
use Hirak\Prestissimo\CopyRequest;
139
use Hirak\Prestissimo\CurlMulti;
1410

11+
/**
12+
* Extends the default FileFetcher and uses hirak/prestissimo for parallel
13+
* downloads.
14+
*/
1515
class PrestissimoFileFetcher extends FileFetcher {
1616

1717
/**
1818
* @var \Composer\Config
1919
*/
2020
protected $config;
2121

22-
public function __construct(\Composer\Util\RemoteFilesystem $remoteFilesystem, $source, IOInterface $io, $progress = TRUE, Config $config) {
22+
/**
23+
* Constructs this PrestissimoFileFetcher object.
24+
*/
25+
public function __construct(RemoteFilesystem $remoteFilesystem, $source, IOInterface $io, $progress = TRUE, Config $config) {
2326
parent::__construct($remoteFilesystem, $source, $io, $progress);
2427
$this->config = $config;
2528
}
2629

30+
/**
31+
* {@inheritdoc}
32+
*/
2733
public function fetch($version, $destination, $override) {
2834
if (class_exists(CurlMulti::class)) {
2935
$this->fetchWithPrestissimo($version, $destination, $override);
@@ -32,6 +38,9 @@ public function fetch($version, $destination, $override) {
3238
parent::fetch($version, $destination, $override);
3339
}
3440

41+
/**
42+
* Fetch files in parallel.
43+
*/
3544
protected function fetchWithPrestissimo($version, $destination, $override) {
3645
$requests = [];
3746

@@ -40,14 +49,14 @@ protected function fetchWithPrestissimo($version, $destination, $override) {
4049
if ($override || !file_exists($target)) {
4150
$url = $this->getUri($sourceFilename, $version);
4251
$this->fs->ensureDirectoryExists($destination . '/' . dirname($filename));
43-
$requests[] = new CopyRequest($url, $target, false, $this->io, $this->config);
52+
$requests[] = new CopyRequest($url, $target, FALSE, $this->io, $this->config);
4453
}
4554
}
4655

4756
$successCnt = $failureCnt = 0;
4857
$totalCnt = count($requests);
4958

50-
$multi = new CurlMulti;
59+
$multi = new CurlMulti();
5160
$multi->setRequests($requests);
5261
do {
5362
$multi->setupEventLoop();
@@ -57,7 +66,7 @@ protected function fetchWithPrestissimo($version, $destination, $override) {
5766
$failureCnt += $result['failureCnt'];
5867
if ($this->progress) {
5968
foreach ($result['urls'] as $url) {
60-
$this->io->writeError(" - Downloading <comment>$successCnt</comment>/<comment>$totalCnt</comment>: <info>$url</info>", true);
69+
$this->io->writeError(" - Downloading <comment>$successCnt</comment>/<comment>$totalCnt</comment>: <info>$url</info>", TRUE);
6170
}
6271
}
6372
} while ($multi->remain());

tests/FetcherTest.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Contains \DrupalComposer\DrupalScaffold\Tests\FetcherTest.
6-
*/
7-
83
namespace DrupalComposer\DrupalScaffold\Tests;
94

10-
use Composer\Downloader\TransportException;
115
use Composer\IO\NullIO;
126
use Composer\Util\Filesystem;
137
use Composer\Util\RemoteFilesystem;
148
use DrupalComposer\DrupalScaffold\FileFetcher;
15-
use DrupalComposer\DrupalScaffold\InitialFileFetcher;
169

1710
class FetcherTest extends \PHPUnit_Framework_TestCase {
1811

@@ -37,7 +30,7 @@ class FetcherTest extends \PHPUnit_Framework_TestCase {
3730
protected $tmpReleaseTag;
3831

3932
/**
40-
* SetUp test
33+
* SetUp test.
4134
*/
4235
public function setUp() {
4336
$this->rootDir = realpath(realpath(__DIR__ . '/..'));
@@ -59,7 +52,7 @@ protected function ensureDirectoryExistsAndClear($directory) {
5952
if (is_dir($directory)) {
6053
$this->fs->removeDirectory($directory);
6154
}
62-
mkdir($directory, 0777, true);
55+
mkdir($directory, 0777, TRUE);
6356
}
6457

6558
public function testFetch() {
@@ -68,17 +61,18 @@ public function testFetch() {
6861
'.htaccess' => '.htaccess',
6962
'sites/default/default.settings.php' => 'sites/default/default.settings.php',
7063
]);
71-
$fetcher->fetch('8.1.1', $this->tmpDir, true);
64+
$fetcher->fetch('8.1.1', $this->tmpDir, TRUE);
7265
$this->assertFileExists($this->tmpDir . '/.htaccess');
7366
$this->assertFileExists($this->tmpDir . '/sites/default/default.settings.php');
7467
}
75-
68+
7669
public function testInitialFetch() {
7770
$fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', new NullIO());
7871
$fetcher->setFilenames([
7972
'sites/default/default.settings.php' => 'sites/default/settings.php',
8073
]);
81-
$fetcher->fetch('8.1.1', $this->tmpDir, false);
74+
$fetcher->fetch('8.1.1', $this->tmpDir, FALSE);
8275
$this->assertFileExists($this->tmpDir . '/sites/default/settings.php');
8376
}
77+
8478
}

0 commit comments

Comments
 (0)