Skip to content

Commit

Permalink
Merge pull request #258 from lemberg/chore/257-maintenance
Browse files Browse the repository at this point in the history
Mid 2022 maintenance
  • Loading branch information
T2L committed Jul 6, 2022
2 parents 62ffada + 1e2601b commit 0ece34d
Show file tree
Hide file tree
Showing 29 changed files with 198 additions and 104 deletions.
46 changes: 27 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "lemberg/draft-environment",
"type": "composer-plugin",
"description": "Development environment for Draft Drupal.",
"license": "GPL-2.0-or-later",
"type": "composer-plugin",
"require": {
"php": ">=7.3",
"composer-plugin-api": "^1.1 || ^2.0",
"nette/finder": "^2.5.2",
"nette/robot-loader": "^3.4.1",
"symfony/filesystem": "^3.4.47 || ^4.4.27 || ^5.3.4",
"symfony/yaml": "^3.4.41 || ^4.4.9 || ^5.3",
"symfony/filesystem": "^3.4.47 || ^4.4.27 || ^5.3.4 || ^6.0.9",
"symfony/yaml": "^3.4.41 || ^4.4.9 || ^5.3 || ^6.0.10",
"t2l/comments": "^1.1.0"
},
"require-dev": {
Expand All @@ -18,27 +18,22 @@
"dg/bypass-finals": "^1.3.1",
"drupal/coder": "^8.3.13",
"ergebnis/composer-normalize": "^2.15.0",
"ergebnis/phpstan-rules": "^0.15.3",
"ergebnis/phpstan-rules": "^1.0.0",
"mikey179/vfsstream": "^1.6.10",
"php-mock/php-mock-phpunit": "^2.5",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpro/grumphp": "^1.5.0",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^0.12.99",
"phpstan/phpstan-deprecation-rules": "^0.12.6",
"phpstan/phpstan-phpunit": "^0.12.22",
"phpstan/phpstan-strict-rules": "^0.12.11",
"phpstan/phpstan": "^1.8.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpunit/phpunit": "^9.5.10",
"slam/phpstan-extensions": "^5.0.2",
"symfony/process": "^3.4.47 || ^4.4.30 || ^5.3.7",
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
},
"config": {
"sort-packages": true
},
"extra": {
"class": "Lemberg\\Draft\\Environment\\Composer\\Plugin"
"symfony/process": "^3.4.47 || ^4.4.30 || ^5.3.7 || ^6.0.8",
"thecodingmachine/phpstan-strict-rules": "^1.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Lemberg\\Draft\\Environment\\": "src/"
Expand All @@ -52,6 +47,19 @@
"Lemberg\\Tests\\Unit\\Draft\\Environment\\": "tests/Unit"
}
},
"minimum-stability": "dev",
"prefer-stable": true
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"phpro/grumphp": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "7.3"
},
"sort-packages": true
},
"extra": {
"class": "Lemberg\\Draft\\Environment\\Composer\\Plugin"
}
}
5 changes: 1 addition & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ parameters:
- Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step\Cleanup30400Test
ignoreErrors:
-
message: '#Constructor in Lemberg\\Draft\\Environment\\Config\\Manager\\AbstractConfigManager has parameter \$classLoader with default value.#'
path: src/Config/Manager/AbstractConfigManager.php
-
message: '#Method Lemberg\\Draft\\Environment\\Config\\Manager\\AbstractConfigManager::__construct\(\) has parameter \$classLoader with null as default value.#'
message: '#Method Lemberg\\Draft\\Environment\\Config\\Manager\\AbstractConfigManager::__construct\(\) has parameter \$classLoader with a nullable type declaration.#'
path: src/Config/Manager/AbstractConfigManager.php
18 changes: 1 addition & 17 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

namespace Lemberg\Draft\Environment;

use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\EventDispatcher\Event;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Lemberg\Draft\Environment\Config\Manager\InstallManagerInterface;
use Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface;

Expand All @@ -24,16 +22,6 @@ final class App {

public const LAST_AVAILABLE_UPDATE_WEIGHT = 12;

/**
* @var \Composer\Composer
*/
private $composer;

/**
* @var \Composer\IO\IOInterface
*/
private $io;

/**
* @var \Lemberg\Draft\Environment\Config\Manager\InstallManagerInterface
*/
Expand All @@ -47,14 +35,10 @@ final class App {
/**
* Draft Environment app constructor.
*
* @param \Composer\Composer $composer
* @param \Composer\IO\IOInterface $io
* @param \Lemberg\Draft\Environment\Config\Manager\InstallManagerInterface $configInstallManager
* @param \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface $configUpdateManager
*/
public function __construct(Composer $composer, IOInterface $io, InstallManagerInterface $configInstallManager, UpdateManagerInterface $configUpdateManager) {
$this->composer = $composer;
$this->io = $io;
public function __construct(InstallManagerInterface $configInstallManager, UpdateManagerInterface $configUpdateManager) {
$this->configInstallManager = $configInstallManager;
$this->configUpdateManager = $configUpdateManager;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function activate(Composer $composer, IOInterface $io): void {
$classLoader = new ClassLoader();
$configInstallManager = new InstallManager($composer, $io, $config, $classLoader);
$configUpdateManager = new UpdateManager($composer, $io, $config, $classLoader);
$this->setApp(new App($composer, $io, $configInstallManager, $configUpdateManager));
$this->setApp(new App($configInstallManager, $configUpdateManager));
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ public function readConfigFromTheFile(string $source): string {
*
* @param string $source
*
* @return array<int|string, array>
* @return array<int|string,mixed>
*/
public function readAndParseConfigFromTheFile(string $source): array {
$content = $this->readConfigFromTheFile($source);
$parser = new Parser();
return $parser->parse($content);
/** @var array<int|string,mixed> $parsed_content */
$parsed_content = $parser->parse($content);
return $parsed_content;
}

/**
Expand All @@ -164,7 +166,7 @@ public function readAndParseConfigFromTheFile(string $source): array {
*
* @param string $source
* @param string $target
* @param array<int|string,array> $config
* @param array<int|string,mixed> $config
*/
public function writeConfigToTheFile(string $source, string $target, array $config): void {
$yaml = new Dumper(2);
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Install/Step/ProjectName.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function install(array &$config): void {
> Project name <question>[$default]</question>:
HERE;

/**
* @var array{
* vagrant?: array{
* hostname?: string ,
* }
* } $config
*/
$config['vagrant']['hostname'] = $this->io->askAndValidate(
$question, [__CLASS__, 'validateProjectName'], NULL, $default
);
Expand Down
24 changes: 23 additions & 1 deletion src/Config/Manager/AbstractConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ abstract class AbstractConfigManager implements ManagerInterface {
/**
* {@inheritdoc}
*/
final public function __construct(Composer $composer, IOInterface $io, Config $config, ClassLoader $classLoader = NULL) {
final public function __construct(Composer $composer, IOInterface $io, Config $config, ?ClassLoader $classLoader) {
$this->composer = $composer;
$this->io = $io;
$this->setConfig($config);
Expand Down Expand Up @@ -105,8 +105,15 @@ final protected function writeConfig(array $config): void {

/**
* Looks for classes implementing a given interface.
*
* @throws \UnexpectedValueException
*/
final protected function discoverSteps(string $interface, string $directory): void {

if (!is_subclass_of($interface, AbstractStepInterface::class)) {
throw new \UnexpectedValueException(sprintf('Step discovery is expecting interface extending %s, but %s has been passed.', AbstractStepInterface::class, $interface));
}

$loader = new RobotLoader();
$loader->addDirectory($directory);
$loader->rebuild();
Expand All @@ -117,6 +124,7 @@ final protected function discoverSteps(string $interface, string $directory): vo
foreach ($classes as $class => $filepath) {
$reflection = new \ReflectionClass($class);
if ($reflection->isInstantiable() && $reflection->implementsInterface($interface)) {
/** @var \Lemberg\Draft\Environment\Config\AbstractStepInterface $class */
$this->steps[] = new $class($this->composer, $this->io, $this);
}
}
Expand All @@ -142,6 +150,13 @@ final protected function sortSteps(): void {
* @return int
*/
final protected function getLastAppliedUpdateWeight(array $config): int {
/**
* @var array{
* draft: array{
* last_applied_update?: int,
* },
* } $config
*/
return $config['draft']['last_applied_update'] ?? 0;
}

Expand All @@ -152,6 +167,13 @@ final protected function getLastAppliedUpdateWeight(array $config): int {
* @param int $weight
*/
final protected function setLastAppliedUpdateWeight(array &$config, int $weight): void {
/**
* @var array{
* draft: array{
* last_applied_update: int,
* },
* } $config
*/
$config['draft']['last_applied_update'] = $weight;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Config/Update/Step/AddIdToSyncedFoldersOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* vagrant?: array{
* synced_folder_options?: array<string, string>,
* }
* } $config
*/
$config['vagrant']['synced_folder_options']['id'] = 'default';
}

Expand Down
5 changes: 5 additions & 0 deletions src/Config/Update/Step/AllowAllHostsMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* mysql_users?: array<string, string[]>,
* } $config
*/
if (array_key_exists('mysql_users', $config)) {
foreach ($config['mysql_users'] as &$value) {
$value['host'] = $value['host'] ?? '%';
Expand Down
17 changes: 17 additions & 0 deletions src/Config/Update/Step/Cleanup30400.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public function getWeight(): int {
*/
public function update(array &$config): void {
// Update target Ansible version.

/**
* @var array{
* ansible?: array{
* version?: string,
* },
* mysql_sql_mode?: ?string,
* php_extensions_configuration?: array{
* xdebug?: array{
* 'xdebug.discover_client_host'?: bool|string,
* },
* },
* virtualbox?: array{
* disk_size?: string,
* },
* } $config
*/
if (array_key_exists('ansible', $config)) {
if (array_key_exists('version', $config['ansible'])) {
if ($config['ansible']['version'] === '2.9.*') {
Expand Down
8 changes: 7 additions & 1 deletion src/Config/Update/Step/ExportAllAvailableConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ private function configMerge($defaultConfig, array $config): array {
$result[$key] = $value;
}
elseif (is_array($value)) {
$result[$key] = $this->configMerge($defaultConfig[$key] ?? [], $config[$key]);

if (is_array($defaultConfig) && array_key_exists($key, $defaultConfig)) {
$result[$key] = $this->configMerge($defaultConfig[$key] ?? [], $value);
}
else {
$result[$key] = $value;
}
}
else {
throw new \UnexpectedValueException(sprintf("Unexpected value type '%s' in the configuration array", gettype($value)));
Expand Down
3 changes: 2 additions & 1 deletion src/Config/Update/Step/RemoveConfigurerComposerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public function update(array &$config): void {
}

// Parse composer.json contents into the object in order to preserve empty
// object that might be there. If converted to the associative array,
// values that might be there. If converted to the associative array,
// empty objects later will be exported as empty arrays producing invalid
// composer.json file.
/** @var \stdClass $decoded_contents */
$decoded_contents = json_decode($contents);

if (count($scripts) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* ssh_default_directory?: string,
* vagrant?: array<mixed>
* } $config
*/
$config['vagrant']['source_directory'] = '.';
$config['vagrant']['destination_directory'] = $config['vagrant']['base_directory'] ?? '/var/www/draft';
unset($config['vagrant']['base_directory']);
Expand Down
10 changes: 10 additions & 0 deletions src/Config/Update/Step/RevisePhpConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* php_configuration?: array{
* PHP?: string[]
* },
* php_cli_configuration?: array{
* PHP?: string[]
* },
* } $config
*/
if (array_key_exists('php_configuration', $config)) {
$updates = [
'max_execution_time' => 300,
Expand Down
5 changes: 5 additions & 0 deletions src/Config/Update/Step/SetAsAlreadyInstalledStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* draft: array<mixed>
* } $config
*/
$config['draft']['last_applied_update'] = $this->getWeight();
}

Expand Down
13 changes: 13 additions & 0 deletions src/Config/Update/Step/Xdebug2To3.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ public function getWeight(): int {
* {@inheritdoc}
*/
public function update(array &$config): void {
/**
* @var array{
* php_extensions_configuration?: array{
* xdebug?: string[],
* },
* } $config
*/
if (array_key_exists('php_extensions_configuration', $config)) {
if (array_key_exists('xdebug', $config['php_extensions_configuration'])) {
/**
* @var array{
* 'xdebug.remote_enable'?: string,
* 'xdebug.discover_client_host'?: string,
* } $xdebug_config
*/
$xdebug_config = &$config['php_extensions_configuration']['xdebug'];
if (array_key_exists('xdebug.remote_enable', $xdebug_config)) {
$this->replaceArrayKey($xdebug_config, 'xdebug.remote_enable', 'xdebug.mode');
Expand Down

0 comments on commit 0ece34d

Please sign in to comment.