Skip to content
Extraits de code Groupes Projets
Valider 222903d8 rédigé par JamesRezo's avatar JamesRezo :tada:
Parcourir les fichiers

chore: passe phpstan

parent 0ae89c71
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -13,14 +13,14 @@ class Classic
/**
* To move spip/classic after download to the root of the project.
*
* @param $event
* @param $event
*
* @return void
*/
public static function postInstall(Event $event)
{
$filesystem = new Filesystem();
$rootDir = realpath($event->getComposer()->getConfig()->get('vendor-dir') . '/..');
$rootDir = realpath($event->getComposer()->getConfig()->get('vendor-dir') . '/..') ?: '';
$filesystem->remove($rootDir . '/tmp/__spip_classic__/.git');
$filesystem->remove($rootDir . '/tmp/__spip_classic__/composer.json');
......@@ -36,6 +36,9 @@ class Classic
$filesystem->remove($rootDir . '/tmp/__spip_classic__');
}
/**
* @return void
*/
public static function postUpdate(Event $event)
{
static::postInstall($event);
......
......@@ -8,8 +8,14 @@ abstract class AbstractSpipCommand extends BaseCommand
{
protected function getRootDir(): string
{
$vendorDir = $this->tryComposer()->getConfig()->get('vendor-dir');
$composer = $this->tryComposer();
if (\is_null($composer)) {
throw new \RuntimeException('An error occured with the composer file.');
return realpath($vendorDir.'/..');
}
$vendorDir = $composer->getConfig()->get('vendor-dir');
return realpath($vendorDir.'/..') ?: '';
}
}
......@@ -27,12 +27,19 @@ class ModeDevCommand extends AbstractSpipCommand
{
$composerFile = Factory::getComposerFile();
$composer = $this->tryComposer();
if (\is_null($composer)) {
return AbstractSpipCommand::FAILURE;
}
$output->writeln('Looking into ' . $composerFile);
if (SpipPaths::LOCAL_COMPOSER == $composerFile) {
$tmp = $composer->getConfig()->get('preferred-install');
if (is_string($tmp)) {
$tmp = [$tmp];
}
if (!\is_array($tmp)) {
$tmp = [];
}
if(empty(\array_intersect(['spip/*' => 'source'], $tmp))) {
$output->writeln('<warning>Missing preferred-install in '.$composerFile.'</warning>');
if (!$this->getIO()->askConfirmation('<info>Adding default preferred-install ?</info> [<comment>Y,n</comment>]?')) {
......@@ -45,6 +52,9 @@ class ModeDevCommand extends AbstractSpipCommand
$json->addConfigSetting('preferred-install', ['spip/*' => 'source']);
$this->resetComposer();
$composer = $this->tryComposer();
if (\is_null($composer)) {
return AbstractSpipCommand::FAILURE;
}
}
}
......
......@@ -14,10 +14,14 @@ class PreferredInstall
/**
* Provides the directories where to check source preferred-install
*
* @return List
* @return string[]
*/
public function getFromConfig(): array
{
if (!\is_array($this->composer->getConfig()->get('preferred-install'))) {
return [];
}
$toCheck = array_keys(array_filter(
$this->composer->getConfig()->get('preferred-install'), function ($install) {
return $install === 'source';
......@@ -26,6 +30,7 @@ class PreferredInstall
// packages to change by mode-dev
$rootPackage = $this->composer->getPackage();
/** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */
$extra = $rootPackage->getExtra();
$extensions = $extra['spip']['extensions'] ?? []; // -> SpipPaths::EXTENSIONS/
$template = $extra['spip']['template'] ?? ''; // -> SpipPaths::TEMPLATE/
......
......@@ -11,6 +11,7 @@ use Composer\Util\ProcessExecutor;
*/
class RemoteUrls
{
/** @var string[] */
private array $matching = [
'github.com',
'gitlab.com',
......@@ -19,7 +20,7 @@ class RemoteUrls
private ProcessExecutor $processor;
public function __construct(private IOInterface $io)
public function __construct(IOInterface $io)
{
$this->processor = new ProcessExecutor($io);
}
......@@ -34,7 +35,7 @@ class RemoteUrls
*/
public function toSsh(string $url): string
{
return \preg_replace(',https://'.$this->regexp().'/,', 'git@$1:', $url);
return \preg_replace(',https://'.$this->regexp().'/,', 'git@$1:', $url) ?? $url;
}
/**
......@@ -42,7 +43,7 @@ class RemoteUrls
*/
public function toHttps(string $url): string
{
return \preg_replace(',git@'.$this->regexp().':,', 'https://$1/', $url);
return \preg_replace(',git@'.$this->regexp().':,', 'https://$1/', $url) ?? $url;
}
public function getRemote(string $path): string
......
......@@ -12,7 +12,7 @@ use Spip\Composer\Git\RemoteUrls;
*/
class ModeDev
{
public static function activate(Event $event)
public static function activate(Event $event): void
{
$io = $event->getIO();
$changer = new RemoteUrls($io);
......
......@@ -12,6 +12,8 @@ class Security
{
/**
* @deprecated 0.6.0
*
* @return void
*/
public static function postInstall(Event $event)
{
......@@ -20,6 +22,8 @@ class Security
/**
* @deprecated 0.6.0
*
* @return void
*/
public static function postUpdate(Event $event)
{
......
......@@ -26,6 +26,7 @@ class SpipInstaller extends LibraryInstaller
}
if ('spip-plugin' === $package->getType()) {
/** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */
$extra = $this->composer->getPackage()->getExtra();
$template = $extra['spip']['template'] ?? '';
$extensions = $extra['spip']['extensions'] ?? [];
......@@ -39,7 +40,7 @@ class SpipInstaller extends LibraryInstaller
return './' . SpipPaths::EXTENSIONS . '/' . $name;
}
return './plugins/' . $name;
return './'. SpipPaths::PLUGINS .'/' . $name;
}
if (in_array($package->getType(), array(
......@@ -51,12 +52,14 @@ class SpipInstaller extends LibraryInstaller
' Wait for a future SPIP version for using it.'
);
}
return parent::getInstallPath($package);
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
public function supports(string $packageType)
{
return in_array($packageType, array(
'spip-classic', //SPIP Classic a.k.a. v4.2
......
......@@ -33,7 +33,7 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
];
}
public function updateSafetyScreen(Event $event)
public function updateSafetyScreen(Event $event): void
{
Security::copySafetyScreen($event);
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter