Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-organise the code #131

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"sort-packages": true
},
"extra": {
"class": "Bamarni\\Composer\\Bin\\Plugin"
"class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin"
}
}
4 changes: 2 additions & 2 deletions e2e/scenario3/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Package operations: 1 install, 0 updates, 0 removals
Installs: bamarni/composer-bin-plugin:dev-hash
- Installing bamarni/composer-bin-plugin (dev-hash): Symlinking from ../..
Generating autoload files
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
[bamarni-bin] Calling onPostAutoloadDump().
[bamarni-bin] The command is being forwarded.
[bamarni-bin] Original input: update --verbose.
Expand Down Expand Up @@ -54,6 +54,6 @@ Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
[bamarni-bin] Calling onPostAutoloadDump().
[bamarni-bin] Command already forwarded within the process: skipping.
2 changes: 1 addition & 1 deletion e2e/scenario8/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Package operations: 1 install, 0 updates, 0 removals
Installs: bamarni/composer-bin-plugin:dev-hash
- Installing bamarni/composer-bin-plugin (dev-hash): Symlinking from ../..
Generating autoload files
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
[bamarni-bin] Calling onPostAutoloadDump().
[bamarni-bin] The command is being forwarded.
[bamarni-bin] Original input: update --prefer-lowest --verbose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\ApplicationFactory;

use Composer\Console\Application;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\ApplicationFactory;

use Composer\Console\Application;

Expand Down
5 changes: 4 additions & 1 deletion src/Plugin.php → src/BamarniBinPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace Bamarni\Composer\Bin;

use Bamarni\Composer\Bin\Command\BinCommand;
use Bamarni\Composer\Bin\CommandProvider as BamarniCommandProvider;
use Bamarni\Composer\Bin\Config\Config;
use Bamarni\Composer\Bin\Input\BinInputFactory;
use Composer\Composer;
use Composer\Console\Application;
use Composer\EventDispatcher\EventSubscriberInterface;
Expand All @@ -28,7 +31,7 @@
/**
* @final Will be final in 2.x.
*/
class Plugin implements PluginInterface, Capable, EventSubscriberInterface
class BamarniBinPlugin implements PluginInterface, Capable, EventSubscriberInterface
{
private const FORWARDED_COMMANDS = ['install', 'update'];

Expand Down
10 changes: 8 additions & 2 deletions src/BinCommand.php → src/Command/BinCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;

namespace Bamarni\Composer\Bin\Command;

use Bamarni\Composer\Bin\Config\Config;
use Bamarni\Composer\Bin\Config\ConfigFactory;
use Bamarni\Composer\Bin\ApplicationFactory\FreshInstanceApplicationFactory;
use Bamarni\Composer\Bin\Input\BinInputFactory;
use Bamarni\Composer\Bin\Logger;
use Bamarni\Composer\Bin\ApplicationFactory\NamespaceApplicationFactory;
use Composer\Command\BaseCommand;
use Composer\Factory;
use Composer\IO\IOInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\Command;

use RuntimeException;
use function sprintf;
Expand Down
1 change: 1 addition & 0 deletions src/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bamarni\Composer\Bin;

use Bamarni\Composer\Bin\Command\BinCommand;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;

/**
Expand Down
18 changes: 13 additions & 5 deletions src/Config.php → src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\Config;

use Composer\Composer;
use UnexpectedValueException;
use function array_key_exists;
use function array_merge;
use function function_exists;
use function is_bool;
use function is_string;
use function sprintf;

final class Config
{
Expand Down Expand Up @@ -43,13 +46,18 @@ final class Config
*/
private $deprecations = [];

/**
* @throws InvalidBamarniComposerExtraConfig
*/
public static function fromComposer(Composer $composer): self
{
return new self($composer->getPackage()->getExtra());
}

/**
* @param mixed[] $extra
*
* @throws InvalidBamarniComposerExtraConfig
*/
public function __construct(array $extra)
{
Expand All @@ -62,7 +70,7 @@ public function __construct(array $extra)
$binLinks = $config[self::BIN_LINKS_ENABLED];

if (!is_bool($binLinks)) {
throw new UnexpectedValueException(
throw new InvalidBamarniComposerExtraConfig(
sprintf(
'Expected setting "%s.%s" to be a boolean value. Got "%s".',
self::EXTRA_CONFIG_KEY,
Expand All @@ -85,7 +93,7 @@ public function __construct(array $extra)
$targetDirectory = $config[self::TARGET_DIRECTORY];

if (!is_string($targetDirectory)) {
throw new UnexpectedValueException(
throw new InvalidBamarniComposerExtraConfig(
sprintf(
'Expected setting "%s.%s" to be a string. Got "%s".',
self::EXTRA_CONFIG_KEY,
Expand All @@ -98,7 +106,7 @@ public function __construct(array $extra)
$forwardCommand = $config[self::FORWARD_COMMAND];

if (!is_bool($forwardCommand)) {
throw new UnexpectedValueException(
throw new InvalidBamarniComposerExtraConfig(
sprintf(
'Expected setting "%s.%s" to be a boolean value. Got "%s".',
self::EXTRA_CONFIG_KEY,
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigFactory.php → src/Config/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\Config;

use Composer\Config as ComposerConfig;
use Composer\Factory;
Expand Down
11 changes: 11 additions & 0 deletions src/Config/InvalidBamarniComposerExtraConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Bamarni\Composer\Bin\Config;

use UnexpectedValueException;

final class InvalidBamarniComposerExtraConfig extends UnexpectedValueException
{
}
2 changes: 1 addition & 1 deletion src/BinInputFactory.php → src/Input/BinInputFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\Input;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
Expand Down
2 changes: 1 addition & 1 deletion src/InvalidBinInput.php → src/Input/InvalidBinInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin;
namespace Bamarni\Composer\Bin\Input;

use RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
7 changes: 4 additions & 3 deletions tests/BinCommandTest.php → tests/Command/BinCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin\Tests;
namespace Bamarni\Composer\Bin\Tests\Command;

use Bamarni\Composer\Bin\BinCommand;
use Bamarni\Composer\Bin\Command\BinCommand;
use Bamarni\Composer\Bin\Tests\Fixtures\MyTestCommand;
use Bamarni\Composer\Bin\Tests\Fixtures\ReuseApplicationFactory;
use Composer\Composer;
Expand All @@ -13,6 +13,7 @@
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
use function array_shift;
use function exec;
use function chdir;
use function file_exists;
use function file_put_contents;
Expand All @@ -24,7 +25,7 @@
use function sys_get_temp_dir;

/**
* @covers \Bamarni\Composer\Bin\BinCommand
* @covers \Bamarni\Composer\Bin\Command\BinCommand
*/
class BinCommandTest extends TestCase
{
Expand Down
11 changes: 7 additions & 4 deletions tests/ConfigTest.php → tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin\Tests;
namespace Bamarni\Composer\Bin\Tests\Config;

use Bamarni\Composer\Bin\Config;
use Bamarni\Composer\Bin\Config\Config;
use Bamarni\Composer\Bin\Config\InvalidBamarniComposerExtraConfig;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;

/**
* @covers \Bamarni\Composer\Bin\Config\Config
*/
final class ConfigTest extends TestCase
{
/**
Expand Down Expand Up @@ -92,7 +95,7 @@ public function test_it_cannot_be_instantiated_with_invalid_config(
array $extra,
string $expectedMessage
): void {
$this->expectException(UnexpectedValueException::class);
$this->expectException(InvalidBamarniComposerExtraConfig::class);
$this->expectExceptionMessage($expectedMessage);

new Config($extra);
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/ReuseApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bamarni\Composer\Bin\Tests\Fixtures;

use Bamarni\Composer\Bin\NamespaceApplicationFactory;
use Bamarni\Composer\Bin\ApplicationFactory\NamespaceApplicationFactory;
use Composer\Console\Application;

final class ReuseApplicationFactory implements NamespaceApplicationFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

declare(strict_types=1);

namespace Bamarni\Composer\Bin\Tests;
namespace Bamarni\Composer\Bin\Tests\Input;

use Bamarni\Composer\Bin\BinInputFactory;
use Bamarni\Composer\Bin\Input\BinInputFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use function sprintf;

/**
* @covers \Bamarni\Composer\Bin\BinInputFactory
* @covers \Bamarni\Composer\Bin\Input\BinInputFactory
*/
final class BinInputFactoryTest extends TestCase
{
Expand Down