Skip to content

Commit c4cefbc

Browse files
authored
Re-organise the code (#131)
1 parent e43ab30 commit c4cefbc

18 files changed

Lines changed: 62 additions & 29 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
"sort-packages": true
4646
},
4747
"extra": {
48-
"class": "Bamarni\\Composer\\Bin\\Plugin"
48+
"class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin"
4949
}
5050
}

e2e/scenario3/expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Package operations: 1 install, 0 updates, 0 removals
1111
Installs: bamarni/composer-bin-plugin:dev-hash
1212
- Installing bamarni/composer-bin-plugin (dev-hash): Symlinking from ../..
1313
Generating autoload files
14-
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
14+
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
1515
[bamarni-bin] Calling onPostAutoloadDump().
1616
[bamarni-bin] The command is being forwarded.
1717
[bamarni-bin] Original input: update --verbose.
@@ -54,6 +54,6 @@ Nothing to modify in lock file
5454
Installing dependencies from lock file (including require-dev)
5555
Nothing to install, update or remove
5656
Generating autoload files
57-
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
57+
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
5858
[bamarni-bin] Calling onPostAutoloadDump().
5959
[bamarni-bin] Command already forwarded within the process: skipping.

e2e/scenario8/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Package operations: 1 install, 0 updates, 0 removals
1111
Installs: bamarni/composer-bin-plugin:dev-hash
1212
- Installing bamarni/composer-bin-plugin (dev-hash): Symlinking from ../..
1313
Generating autoload files
14-
> post-autoload-dump: Bamarni\Composer\Bin\Plugin->onPostAutoloadDump
14+
> post-autoload-dump: Bamarni\Composer\Bin\BamarniBinPlugin->onPostAutoloadDump
1515
[bamarni-bin] Calling onPostAutoloadDump().
1616
[bamarni-bin] The command is being forwarded.
1717
[bamarni-bin] Original input: update --prefer-lowest --verbose.

src/FreshInstanceApplicationFactory.php renamed to src/ApplicationFactory/FreshInstanceApplicationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Bamarni\Composer\Bin;
5+
namespace Bamarni\Composer\Bin\ApplicationFactory;
66

77
use Composer\Console\Application;
88

src/NamespaceApplicationFactory.php renamed to src/ApplicationFactory/NamespaceApplicationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Bamarni\Composer\Bin;
5+
namespace Bamarni\Composer\Bin\ApplicationFactory;
66

77
use Composer\Console\Application;
88

src/Plugin.php renamed to src/BamarniBinPlugin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace Bamarni\Composer\Bin;
66

7+
use Bamarni\Composer\Bin\Command\BinCommand;
78
use Bamarni\Composer\Bin\CommandProvider as BamarniCommandProvider;
9+
use Bamarni\Composer\Bin\Config\Config;
10+
use Bamarni\Composer\Bin\Input\BinInputFactory;
811
use Composer\Composer;
912
use Composer\Console\Application;
1013
use Composer\EventDispatcher\EventSubscriberInterface;
@@ -28,7 +31,7 @@
2831
/**
2932
* @final Will be final in 2.x.
3033
*/
31-
class Plugin implements PluginInterface, Capable, EventSubscriberInterface
34+
class BamarniBinPlugin implements PluginInterface, Capable, EventSubscriberInterface
3235
{
3336
private const FORWARDED_COMMANDS = ['install', 'update'];
3437

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
declare(strict_types=1);
44

5-
namespace Bamarni\Composer\Bin;
6-
5+
namespace Bamarni\Composer\Bin\Command;
6+
7+
use Bamarni\Composer\Bin\Config\Config;
8+
use Bamarni\Composer\Bin\Config\ConfigFactory;
9+
use Bamarni\Composer\Bin\ApplicationFactory\FreshInstanceApplicationFactory;
10+
use Bamarni\Composer\Bin\Input\BinInputFactory;
11+
use Bamarni\Composer\Bin\Logger;
12+
use Bamarni\Composer\Bin\ApplicationFactory\NamespaceApplicationFactory;
713
use Composer\Command\BaseCommand;
814
use Composer\Factory;
915
use Composer\IO\IOInterface;

src/CouldNotCreateNamespaceDir.php renamed to src/Command/CouldNotCreateNamespaceDir.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Bamarni\Composer\Bin;
5+
namespace Bamarni\Composer\Bin\Command;
66

77
use RuntimeException;
88
use function sprintf;

src/CommandProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Bamarni\Composer\Bin;
66

7+
use Bamarni\Composer\Bin\Command\BinCommand;
78
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
89

910
/**

src/Config.php renamed to src/Config/Config.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace Bamarni\Composer\Bin;
5+
namespace Bamarni\Composer\Bin\Config;
66

77
use Composer\Composer;
8-
use UnexpectedValueException;
98
use function array_key_exists;
109
use function array_merge;
10+
use function function_exists;
11+
use function is_bool;
12+
use function is_string;
13+
use function sprintf;
1114

1215
final class Config
1316
{
@@ -43,13 +46,18 @@ final class Config
4346
*/
4447
private $deprecations = [];
4548

49+
/**
50+
* @throws InvalidBamarniComposerExtraConfig
51+
*/
4652
public static function fromComposer(Composer $composer): self
4753
{
4854
return new self($composer->getPackage()->getExtra());
4955
}
5056

5157
/**
5258
* @param mixed[] $extra
59+
*
60+
* @throws InvalidBamarniComposerExtraConfig
5361
*/
5462
public function __construct(array $extra)
5563
{
@@ -62,7 +70,7 @@ public function __construct(array $extra)
6270
$binLinks = $config[self::BIN_LINKS_ENABLED];
6371

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

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

100108
if (!is_bool($forwardCommand)) {
101-
throw new UnexpectedValueException(
109+
throw new InvalidBamarniComposerExtraConfig(
102110
sprintf(
103111
'Expected setting "%s.%s" to be a boolean value. Got "%s".',
104112
self::EXTRA_CONFIG_KEY,

0 commit comments

Comments
 (0)