Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Dec 12, 2024
1 parent 0d36c26 commit 3ec1355
Show file tree
Hide file tree
Showing 21 changed files with 135 additions and 298 deletions.
20 changes: 9 additions & 11 deletions src/N98/Magento/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ class Application extends BaseApplication
*/
protected $autoloader;

protected ?Config $config;
protected ?Config $config = null;

/**
* @see Application::setConfigurationLoader
*/
private ?ConfigurationLoader $configurationLoader;
private ?ConfigurationLoader $configurationLoader = null;

protected ?string $_magentoRootFolder;
protected string $_magentoRootFolder = '';

protected bool $_magentoEnterprise = false;

Expand All @@ -89,7 +89,7 @@ class Application extends BaseApplication

protected bool $_magerunStopFileFound = false;

protected string $_magerunStopFileFolder;
protected string $_magerunStopFileFolder = '';

protected bool $_magerunUseDeveloperMode;

Expand Down Expand Up @@ -327,9 +327,7 @@ public function checkVarDir(OutputInterface $output): ?bool

$this->detectMagento(null, $output);
/* If magento is not installed yet, don't check */
if ($this->_magentoRootFolder === null
|| !file_exists($this->_magentoRootFolder . '/app/etc/local.xml')
) {
if (!file_exists($this->_magentoRootFolder . '/app/etc/local.xml')) {
return null;
}

Expand Down Expand Up @@ -571,10 +569,10 @@ public function init(array $initConfig = [], ?InputInterface $input = null, ?Out

public function reinit(array $initConfig = [], ?InputInterface $input = null, ?OutputInterface $output = null): void
{
$this->_isInitialized = false;
$this->_magentoDetected = false;
$this->_magentoRootFolder = null;
$this->config = null;
$this->_isInitialized = false;
$this->_magentoDetected = false;
$this->_magentoRootFolder = '';
$this->config = null;
$this->init($initConfig, $input, $output);
}

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Application/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config

private array $partialConfig = [];

private ?ConfigurationLoader $configurationLoader;
private ?ConfigurationLoader $configurationLoader = null;

private array $initConfig;

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Application/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigLocator
{
private string $customConfigFilename;

private string $magentoRootFolder;
private ?string $magentoRootFolder;

public function __construct(string $configFilename, string $magentoRootFolder)
{
Expand Down
14 changes: 7 additions & 7 deletions src/N98/Magento/Application/ConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ class ConfigurationLoader
*/
protected array $_initialConfig;

protected ?array $_configArray;
protected ?array $_configArray = null;

/**
* Cache
*/
protected ?array $_distConfig;
protected ?array $_distConfig = null;

/**
* Cache
*/
protected ?array $_pluginConfig;
protected ?array $_pluginConfig = null;

/**
* Cache
*/
protected ?array $_systemConfig;
protected ?array $_systemConfig = null;

/**
* Cache
*/
protected ?array $_userConfig;
protected ?array $_userConfig = null;

/**
* Cache
*/
protected ?array $_projectConfig;
protected ?array $_projectConfig = null;

protected string $_customConfigFilename = 'n98-magerun.yaml';

Expand Down Expand Up @@ -209,7 +209,7 @@ private function traversePluginFoldersForConfigFile(string $magentoRootFolder, $
/**
* Check if there is a user config file. ~/.n98-magerun.yaml
*/
public function loadUserConfig(array $config, ?string $magentoRootFolder = null): array
public function loadUserConfig(array $config, string $magentoRootFolder = ''): array
{
if (is_null($this->_userConfig)) {
$this->_userConfig = [];
Expand Down
8 changes: 4 additions & 4 deletions src/N98/Magento/Command/AbstractMagentoStoreConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/
abstract class AbstractMagentoStoreConfigCommand extends AbstractMagentoCommand
{
public string $commandName;
public string $commandDescription;
public string $commandName = '';
public string $commandDescription = '';

public const COMMAND_ARGUMENT_STORE = 'store';

Expand Down Expand Up @@ -76,13 +76,13 @@ protected function configure(): void
{
// for backwards compatibility before v3.0
// @phpstan-ignore function.alreadyNarrowedType
if (property_exists($this, 'commandName')) {
if (property_exists($this, 'commandName') && $this->commandName) {
$this->setName($this->commandName);
}

// for backwards compatibility before v3.0
// @phpstan-ignore function.alreadyNarrowedType
if (property_exists($this, 'commandDescription')) {
if (property_exists($this, 'commandDescription') && $this->commandDescription) {
$this->setDescription($this->commandDescription);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Question\Question;

use function chdir;
use function getcwd;

/**
* Class ChooseInstallationFolder
Expand All @@ -17,16 +18,13 @@
*/
class ChooseInstallationFolder extends AbstractSubCommand
{
/**
* @return bool
*/
public function execute()
public function execute(): void
{
$input = $this->input;
$validateInstallationFolder = function ($folderName) {
$folderName = rtrim(trim($folderName, ' '), '/');
if ($folderName[0] === '.') {
$cwd = \getcwd();
$cwd = getcwd();
if (($cwd === '' || $cwd === '0' || $cwd === false) && isset($_SERVER['PWD'])) {
$cwd = $_SERVER['PWD'];
}
Expand Down Expand Up @@ -74,7 +72,5 @@ public function execute()
$this->config->setString('initialFolder', (string) getcwd());
$this->config->setString('installationFolder', (string) realpath($installationFolder));
chdir($this->config->getString('installationFolder'));

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class CreateDatabase extends AbstractSubCommand
protected Closure $notEmptyCallback;

/**
* @return void
* @throws Exception
*/
public function execute()
public function execute(): void
{
$this->notEmptyCallback = function ($input) {
if (empty($input)) {
Expand Down
29 changes: 11 additions & 18 deletions src/N98/Magento/Command/Installer/SubCommand/InstallComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace N98\Magento\Command\Installer\SubCommand;

use Exception;
use N98\Magento\Command\SubCommand\AbstractSubCommand;
use N98\Util\Exec;
use N98\Util\OperatingSystem;
use RuntimeException;
use WpOrg\Requests\Requests;

/**
Expand All @@ -16,17 +18,12 @@
*/
class InstallComposer extends AbstractSubCommand
{
/**
* @var int
*/
public const EXEC_STATUS_OK = 0;

/**
* @return void
*
* @throws \Exception
* @throws Exception
*/
public function execute()
public function execute(): void
{
if (OperatingSystem::isProgramInstalled('composer.phar')) {
$composerBin = 'composer.phar';
Expand All @@ -39,7 +36,7 @@ public function execute()
}

if (empty($composerBin)) {
throw new \Exception('Cannot find or install composer. Please try it manually. https://getcomposer.org/');
throw new Exception('Cannot find or install composer. Please try it manually. https://getcomposer.org/');
}

$this->output->writeln('<info>Found executable <comment>' . $composerBin . '</comment></info>');
Expand All @@ -57,17 +54,15 @@ public function execute()
}

/**
* @return string
* @throws \Exception
* @throws Exception
*/
protected function downloadComposer()
protected function downloadComposer(): string
{
$this->output->writeln('<info>Could not find composer. Try to download it.</info>');

$response = Requests::get('https://getcomposer.org/installer');

if (!$response->success) {
throw new \RuntimeException('Cannot download Composer installer: ' . $response->status_code);
throw new RuntimeException('Cannot download Composer installer: ' . $response->status_code);
}

$composerInstaller = $response->body;
Expand All @@ -88,7 +83,7 @@ protected function downloadComposer()
unlink($tempComposerInstaller);
$installationOutput = implode(PHP_EOL, $installationOutput);
if ($returnStatus !== self::EXEC_STATUS_OK) {
throw new \Exception('Installation failed.' . $installationOutput);
throw new Exception('Installation failed.' . $installationOutput);
}

$this->output->writeln('<info>Successfully installed composer to Magento root</info>');
Expand All @@ -99,15 +94,13 @@ protected function downloadComposer()
/**
* Composer 1 or Composer 2
*
* @param $output
* @param $matches
* @throws \Exception
* @throws Exception
*/
protected function getMajorComposerVersion(): int
{
Exec::run(implode(' ', array_merge($this->config['composer_bin'], [' --version'])), $output);
if (in_array(preg_match('#(\d+)\.(\d+)\.(\d+)#', $output, $matches), [0, false], true)) {
throw new \Exception('Could not detect a valid Composer version');
throw new Exception('Could not detect a valid Composer version');
}

return (int) $matches[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace N98\Magento\Command\Installer\SubCommand;

use Exception;
use N98\Magento\Command\SubCommand\AbstractSubCommand;
use Symfony\Component\Process\Process;

Expand All @@ -15,13 +16,11 @@
class InstallComposerPackages extends AbstractSubCommand
{
/**
* Check PHP environment agains minimal required settings modules
* Check PHP environment against minimal required settings modules
*
* @return void
*
* @throws \Exception
* @throws Exception
*/
public function execute()
public function execute(): void
{
$this->output->writeln('<comment>Install composer packages</comment>');
$process = new Process(array_merge($this->config['composer_bin'], ['install']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace N98\Magento\Command\Installer\SubCommand;

use Exception;
use N98\Magento\Command\SubCommand\AbstractSubCommand;
use Symfony\Component\Console\Input\ArrayInput;

use function chdir;

/**
* Class PostInstallation
*
Expand All @@ -15,14 +18,13 @@
class PostInstallation extends AbstractSubCommand
{
/**
* @return void
* @throws \Exception
* @throws Exception
*/
public function execute()
public function execute(): void
{
$this->getCommand()->getApplication()->setAutoExit(false);

\chdir($this->config->getString('installationFolder'));
chdir($this->config->getString('installationFolder'));
$this->getCommand()->getApplication()->reinit();

$this->output->writeln('<info>Reindex all after installation</info>');
Expand Down
Loading

0 comments on commit 3ec1355

Please sign in to comment.