Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • spip-league/composer-installer
1 résultat
Afficher les modifications
Affichage de
avec 126 ajouts et 101 suppressions
......@@ -18,27 +18,30 @@ class Security
public static function copySafetyScreen(Event $event): void
{
$search = array_filter(
$event->getComposer()->getPackage()->getRequires(),
function (Link $link) {
return $link->getTarget() === 'spip/security';
},
$event->getComposer()
->getPackage()
->getRequires(),
fn(Link $link) => $link->getTarget() === 'spip/security',
);
if (empty($search)) {
$event->getIO()->warning('spip/security is not installed.');
$event->getIO()
->warning('spip/security is not installed.');
return;
}
$event->getIO()->write('Updating the safety screen ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
$event->getIO()
->write('Updating the safety screen ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir');
try {
\copy(
$vendorDir . '/spip/security/ecran_securite.php',
$vendorDir . '/../config/ecran_securite.php',
);
$event->getIO()->write('Done.');
\copy($vendorDir . '/spip/security/ecran_securite.php', $vendorDir . '/../config/ecran_securite.php');
$event->getIO()
->write('Done.');
} catch (\Throwable $th) {
$event->getIO()->error($th->getMessage());
$event->getIO()
->error($th->getMessage());
}
}
}
......@@ -7,22 +7,20 @@ use Composer\Package\PackageInterface;
class SpipInstaller extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
if ('spip-ecrire' === $package->getType()) {
if ($package->getType() === 'spip-ecrire') {
return './' . SpipPaths::BACK_OFFICE;
}
if ('spip-prive' === $package->getType()) {
if ($package->getType() === 'spip-prive') {
return './' . SpipPaths::PRIVATE_TEMPLATE;
}
if ('spip-plugin' === $package->getType()) {
if ($package->getType() === 'spip-plugin') {
/** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */
$extra = $this->composer->getPackage()->getExtra();
$extra = $this->composer->getPackage()
->getExtra();
$template = $extra['spip']['template'] ?? '';
$extensions = $extra['spip']['extensions'] ?? [];
$name = $package->getName();
......@@ -38,10 +36,7 @@ class SpipInstaller extends LibraryInstaller
return './' . SpipPaths::PLUGINS . '/' . $name;
}
if (in_array($package->getType(), [
'spip-lang',
'spip-theme',
])) {
if (in_array($package->getType(), ['spip-lang', 'spip-theme'])) {
throw new \InvalidArgumentException(
'Unable to install this package as its type is not supported for now.' .
' Wait for a future SPIP version for using it.',
......@@ -51,9 +46,6 @@ class SpipInstaller extends LibraryInstaller
return parent::getInstallPath($package);
}
/**
* {@inheritDoc}
*/
public function supports(string $packageType)
{
return in_array($packageType, [
......
......@@ -17,16 +17,13 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function activate(Composer $composer, IOInterface $io)
{
$installer = new SpipInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
$composer->getInstallationManager()
->addInstaller($installer);
}
public function deactivate(Composer $composer, IOInterface $io)
{
}
public function deactivate(Composer $composer, IOInterface $io) {}
public function uninstall(Composer $composer, IOInterface $io)
{
}
public function uninstall(Composer $composer, IOInterface $io) {}
public static function getSubscribedEvents()
{
......@@ -82,7 +79,7 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function getCapabilities()
{
return [
'Composer\Plugin\Capability\CommandProvider' => 'SpipLeague\Composer\CommandProvider',
\Composer\Plugin\Capability\CommandProvider::class => \SpipLeague\Composer\CommandProvider::class,
];
}
}
......@@ -5,24 +5,37 @@ namespace SpipLeague\Composer;
class SpipPaths
{
public const CHMOD = 0777;
public const UMASK = 0000;
public const PLUGINS = 'plugins';
public const EXTENSIONS = 'plugins-dist';
public const TEMPLATE = 'squelettes-dist';
public const PRIVATE_TEMPLATE = 'prive';
public const BACK_OFFICE = 'ecrire';
public const TMP = 'tmp';
public const ETC = 'config';
public const VAR = 'local';
public const DOC = 'IMG';
public const LOCAL_COMPOSER = 'composer.local.json';
public const LOCAL_PLUGINS_DIST = 'plugins-dist.json';
public const DIR_CACHE = '%spip.dirs.tmp%/cache';
public const DIR_LOG = '%spip.dirs.tmp%/log';
public const DIR_ASSETS_CSS = '%spip.dirs.var%/cache-css';
public const DIR_ASSETS_JS = '%spip.dirs.var%/cache-js';
public const WHEELS_CACHE = '%spip.dirs.cache%/wheels';
......
......@@ -17,18 +17,18 @@ use SpipLeague\Composer\Switch\Operation\RemoveSpecification;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Analyzer
{
private Filesystem $filesystem;
private CollectionInterface $distribution;
private Composer $composer;
public function __construct(
CollectionInterface $distribution,
Composer $composer
Composer $composer,
) {
$this->distribution = $distribution;
$this->composer = $composer;
......@@ -42,7 +42,8 @@ class Analyzer
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $this->composer->getPackage()->getExtra();
$extra = $this->composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -75,7 +76,8 @@ class Analyzer
public function back(): \Generator
{
$extensions = $this->getExtensions();
$requires = $this->composer->getPackage()->getRequires();
$requires = $this->composer->getPackage()
->getRequires();
$vendorNames = \array_keys($requires);
$vendorDirs = [];
......
......@@ -8,6 +8,7 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
class AddToRequire implements OperationInterface
{
private string $vendorName;
private string $constraint;
public function __construct(string $vendorName, string $constraint)
......@@ -33,8 +34,6 @@ class AddToRequire implements OperationInterface
}
/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*/
public function mark(CollectionInterface $distribution, Composer $composer): ?self
......@@ -44,7 +43,9 @@ class AddToRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string
{
$composer->getConfig()->getConfigSource()->addLink('require', $this->vendorName, $this->constraint);
$composer->getConfig()
->getConfigSource()
->addLink('require', $this->vendorName, $this->constraint);
return 'require ' . $this->vendorName . ':' . $this->constraint . ' added.';
}
......
......@@ -34,7 +34,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -46,7 +47,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -55,7 +57,9 @@ class AddToSpipExtraExtensions implements OperationInterface
}
$extensions[] = $this->vendorName;
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', $extensions);
$composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', $extensions);
return 'extensions ' . $this->vendorName . ' added';
}
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/
interface OperationInterface
{
......
......@@ -8,13 +8,13 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveDirectory implements OperationInterface
{
private Filesystem $filesystem;
private string $directory;
private bool $ifEmpty;
public function __construct(Filesystem $filesystem, string $directory, bool $ifEmpty = false)
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveFromRequire implements OperationInterface
{
......@@ -42,7 +40,9 @@ class RemoveFromRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string
{
$composer->getConfig()->getConfigSource()->removeLink('require', $this->vendorName);
$composer->getConfig()
->getConfigSource()
->removeLink('require', $this->vendorName);
return 'require ' . $this->vendorName . ' removed';
}
......
......@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class RemoveFromSpipExtraExtensions implements OperationInterface
{
......@@ -39,7 +37,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -51,7 +50,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{
$extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra();
$extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions'];
}
......@@ -59,7 +59,9 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
return 'nothing to do';
}
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName]));
$composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName]));
return 'extensions ' . $this->vendorName . ' removed';
}
......
......@@ -22,7 +22,6 @@ class RemoveSpecification implements OperationInterface
return 'RemoveSpecification ' . $this->prefix;
}
/**
* @codeCoverageIgnore
*/
......
......@@ -8,15 +8,16 @@ use SpipLeague\Composer\Switch\Operation\OperationInterface;
/**
* @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/
class Switcher
{
private CollectionInterface $distribution;
private Composer $composer;
/** @var array<string,OperationInterface[]> */
/**
* @var array<string,OperationInterface[]>
*/
private array $operations = [
'distribution' => [],
'extensions' => [],
......@@ -33,7 +34,7 @@ class Switcher
public function to(OperationInterface $operation): void
{
$operation = $operation->mark($this->distribution, $this->composer);
if (!\is_null($operation)) {
if ($operation !== null) {
$this->operations[$operation->getType()][] = $operation;
}
}
......
......@@ -10,16 +10,22 @@ class WheelsClearCache
{
public static function clearCache(Event $event): void
{
$event->getIO()->write('Clearing the Textwheel cache ...');
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/';
$event->getIO()
->write('Clearing the Textwheel cache ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor());
$sffs = new SymfonyFilesystem;
$fs->emptyDirectory(
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE)
$sffs = new SymfonyFilesystem();
$fs->emptyDirectory($vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE));
$sffs->chmod(
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE),
SpipPaths::CHMOD,
SpipPaths::UMASK,
);
$sffs->chmod($vendorDir . '../' .SpipPaths::interpolate(SpipPaths::WHEELS_CACHE), SpipPaths::CHMOD, SpipPaths::UMASK);
$event->getIO()->write('Done.');
$event->getIO()
->write('Done.');
}
}
......@@ -44,19 +44,20 @@ class PreferredInstallTest extends TestCase
],
'preferred' => ['spip/*' => 'source'],
'requires' => [
'mandatory' => new Link('mandatory', 'spip/mandatory', new Constraint('=', '*')),
'template' => new Link('template', 'spip/default-template', new Constraint('=', '*')),
'package' => new Link('package', 'spip/package', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
'private-template' => new Link('private-template', 'spip/private-template', new Constraint('=', '*')),
'back-office' => new Link('back-office', 'spip/back-office', new Constraint('=', '*')),
'mandatory' => new Link('mandatory', 'spip/mandatory', new Constraint('=', '*')),
'template' => new Link('template', 'spip/default-template', new Constraint('=', '*')),
'package' => new Link('package', 'spip/package', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
'private-template' => new Link('private-template', 'spip/private-template', new Constraint(
'=',
'*',
)),
'back-office' => new Link('back-office', 'spip/back-office', new Constraint('=', '*')),
],
'extra' => [
'spip' => [
'template' => 'spip/default-template',
'extensions' => [
'spip/mandatory',
],
'extensions' => ['spip/mandatory'],
'private_template' => 'spip/private-template',
'back_office' => 'spip/back-office',
],
......@@ -75,16 +76,14 @@ class PreferredInstallTest extends TestCase
],
'preferred' => ['one/*' => 'source', 'two/*' => 'source'],
'requires' => [
'mandatory1' => new Link('mandatory', 'one/mandatory1', new Constraint('=', '*')),
'template2' => new Link('template', 'two/template2', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
'mandatory1' => new Link('mandatory', 'one/mandatory1', new Constraint('=', '*')),
'template2' => new Link('template', 'two/template2', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
],
'extra' => [
'spip' => [
'template' => 'two/template2',
'extensions' => [
'one/mandatory1',
],
'extensions' => ['one/mandatory1'],
],
],
],
......
......@@ -19,7 +19,9 @@ use SpipLeague\Test\Composer\Fixtures\SpecificationStub;
class CollectionTest extends TestCase
{
private SpecificationStub $validStub;
private Collection $testCollection;
private RemoteUrls $changer;
protected function setUp(): void
......@@ -42,7 +44,6 @@ class CollectionTest extends TestCase
// An exception is thrown
}
public function testInvalidSpecificationByArrayAccess()
{
// Given
......@@ -140,7 +141,10 @@ class CollectionTest extends TestCase
$actual = \json_encode($this->testCollection);
// Then
$this->assertSame('{"valid":{"path":"path","source":"source"},"test":{"path":"path","source":"source"}}', $actual);
$this->assertSame(
'{"valid":{"path":"path","source":"source"},"test":{"path":"path","source":"source"}}',
$actual,
);
}
public static function dataFromJsonFile()
......@@ -186,7 +190,7 @@ class CollectionTest extends TestCase
$this->expectExceptionMessageMatches(',Fixtures/malformed.json" malformed,');
// When
Collection::fromJsonFile($this->changer, __DIR__ . '/../Fixtures/malformed.json');
Collection::fromJsonFile($this->changer, __DIR__ . '/../Fixtures/malformed.json');
// Then
// An exception is thrown
......
......@@ -3,12 +3,9 @@
namespace SpipLeague\Test\Composer\Extensions;
use Composer\Composer;
use Composer\Config;
use Composer\Factory as ComposerFactory;
use Composer\IO\NullIO;
use Composer\Package\Link;
use Composer\Package\RootPackage;
use Composer\Semver\Constraint\Constraint;
use Composer\Util\Platform;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
......@@ -16,7 +13,6 @@ use PHPUnit\Framework\TestCase;
use SpipLeague\Composer\Extensions\InvalidSpecificationException;
use SpipLeague\Composer\Extensions\Specification;
use SpipLeague\Composer\SpipPaths;
use SpipLeague\Test\Composer\Fixtures\DummyConfigSource;
use SpipLeague\Test\Composer\Fixtures\RemoteUrlsStub;
#[CoversClass(Specification::class)]
......@@ -95,7 +91,7 @@ class SpecificationTest extends TestCase
if ($changer) {
$specification->setChanger(new RemoteUrlsStub(
'git@github.com:vendor/prefix.git',
'https://github.com/vendor/prefix.git'
'https://github.com/vendor/prefix.git',
));
}
......@@ -202,7 +198,7 @@ class SpecificationTest extends TestCase
{
// Given
Platform::putEnv('COMPOSER', 'tests/Fixtures/create-from-composer/composer.json');
$composer = ComposerFactory::create(new NullIO);
$composer = ComposerFactory::create(new NullIO());
// When
$actual = Specification::createFromComposer($composer, 'test/prefix');
......
......@@ -10,10 +10,14 @@ class CollectionMock implements CollectionInterface
{
protected int $position = 0;
/** @var string[] */
/**
* @var string[]
*/
protected array $keys = [];
/** @var array<string,SpecificationInterface> */
/**
* @var array<string,SpecificationInterface>
*/
protected array $collection = [];
private string $file;
......@@ -70,7 +74,7 @@ class CollectionMock implements CollectionInterface
public function offsetGet(mixed $offset): mixed
{
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
return $this->collection[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void
......@@ -79,7 +83,7 @@ class CollectionMock implements CollectionInterface
throw new InvalidSpecificationException('A collection must only contain valid specifications.', 3);
}
if (is_null($offset) || !\is_string($offset)) {
if ($offset === null || !\is_string($offset)) {
$offset = $value->getPrefix();
}
......
......@@ -8,10 +8,14 @@ use SpipLeague\Composer\Git\RemoteUrlsInterface;
class RemoteUrlsStub implements RemoteUrlsInterface
{
/** @var string[] */
/**
* @var string[]
*/
private array $ssh = [];
/** @var string[] */
/**
* @var string[]
*/
private array $https = [];
public function __construct(string ...$urls)
......
......@@ -22,7 +22,7 @@ class SpecificationMock implements SpecificationInterface
string $prefix = 'prefix',
string $vendorName = 'vendor/prefix',
string $constraint = '1.0',
string $path = 'path'
string $path = 'path',
) {
$this->prefix = $prefix;
$this->vendorName = $vendorName;
......