Skip to content

Commit 8d6f0fb

Browse files
authored
Merge pull request #5 from wintercms/wip/extra-features
Extra features
2 parents e9be8c2 + 18048df commit 8d6f0fb

File tree

14 files changed

+341
-29
lines changed

14 files changed

+341
-29
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"scripts": {
2020
"test": "phpunit --testdox --colors=\"auto\"",
2121
"tests": "phpunit --testdox --colors=\"auto\"",
22+
"analyze": "./vendor/bin/phpstan analyse",
2223
"coverage": "XDEBUG_MODE=coverage phpunit --testdox --colors=\"auto\" --coverage-html=\"coverage\""
2324
},
2425
"require": {

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ parameters:
55
ignoreErrors:
66
- message: '#message has no type specified#'
77
path: src/Exceptions/*.php
8+
- message: '#has parameter .+ with no value type specified in iterable type array#'
9+
path: src/Composer.php

src/Commands/Remove.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Winter\Packager\Commands;
4+
5+
use Winter\Packager\Composer;
6+
use Winter\Packager\Exceptions\CommandException;
7+
8+
class Remove extends BaseCommand
9+
{
10+
/**
11+
* Command constructor.
12+
*/
13+
final public function __construct(
14+
protected Composer $composer,
15+
protected string $package,
16+
protected bool $dryRun = false,
17+
protected bool $dev = false
18+
) {
19+
parent::__construct($composer);
20+
}
21+
22+
/**
23+
* @inheritDoc
24+
*/
25+
public function arguments(): array
26+
{
27+
$arguments = [];
28+
29+
if ($this->dryRun) {
30+
$arguments['--dry-run'] = true;
31+
}
32+
33+
if ($this->dev) {
34+
$arguments['--dev'] = true;
35+
}
36+
37+
$arguments['packages'] = [$this->package];
38+
39+
return $arguments;
40+
}
41+
42+
public function execute()
43+
{
44+
$output = $this->runComposerCommand();
45+
$message = implode(PHP_EOL, $output['output']);
46+
47+
if ($output['code'] !== 0) {
48+
throw new CommandException($message);
49+
}
50+
51+
return $message;
52+
}
53+
54+
/**
55+
* @inheritDoc
56+
*/
57+
protected function requiresWorkDir(): bool
58+
{
59+
return true;
60+
}
61+
62+
/**
63+
* @inheritDoc
64+
*/
65+
public function getCommandName(): string
66+
{
67+
return 'remove';
68+
}
69+
}

src/Commands/RequireCommand.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Winter\Packager\Commands;
4+
5+
use Winter\Packager\Composer;
6+
use Winter\Packager\Exceptions\CommandException;
7+
use Winter\Packager\Exceptions\WorkDirException;
8+
9+
class RequireCommand extends BaseCommand
10+
{
11+
/**
12+
* Command constructor.
13+
*/
14+
final public function __construct(
15+
protected Composer $composer,
16+
protected string $package,
17+
protected bool $dryRun = false,
18+
protected bool $dev = false
19+
) {
20+
parent::__construct($composer);
21+
}
22+
23+
/**
24+
* @inheritDoc
25+
*/
26+
public function arguments(): array
27+
{
28+
$arguments = [];
29+
30+
if ($this->dryRun) {
31+
$arguments['--dry-run'] = true;
32+
}
33+
34+
if ($this->dev) {
35+
$arguments['--dev'] = true;
36+
}
37+
38+
$arguments['packages'] = [$this->package];
39+
40+
return $arguments;
41+
}
42+
43+
/**
44+
* @throws CommandException
45+
* @throws WorkDirException
46+
*/
47+
public function execute(): string
48+
{
49+
$output = $this->runComposerCommand();
50+
$message = implode(PHP_EOL, $output['output']);
51+
52+
if ($output['code'] !== 0) {
53+
throw new CommandException($message);
54+
}
55+
56+
return $message;
57+
}
58+
59+
/**
60+
* @inheritDoc
61+
*/
62+
protected function requiresWorkDir(): bool
63+
{
64+
return true;
65+
}
66+
67+
/**
68+
* @inheritDoc
69+
*/
70+
public function getCommandName(): string
71+
{
72+
return 'require';
73+
}
74+
}

src/Commands/Search.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ class Search extends BaseCommand
2323
* @param string $query The search query to find packages.
2424
* @param string|null $type The type of package to search for.
2525
* @param SearchLimitTo $limitTo Limit the returned results.
26+
* @param bool $returnArray Return the search results as an array.
2627
*/
2728
final public function __construct(
2829
Composer $composer,
2930
public string $query,
3031
public ?string $type = null,
31-
public SearchLimitTo $limitTo = SearchLimitTo::ALL
32+
public SearchLimitTo $limitTo = SearchLimitTo::ALL,
33+
public bool $returnArray = false,
3234
) {
3335
parent::__construct($composer);
3436
}
@@ -44,7 +46,12 @@ public function execute()
4446
throw new CommandException(implode(PHP_EOL, $output['output']));
4547
}
4648

47-
$results = json_decode(implode(PHP_EOL, $output['output']), true);
49+
$results = json_decode(implode(PHP_EOL, $output['output']), flags: JSON_OBJECT_AS_ARRAY) ?? [];
50+
51+
if ($this->returnArray) {
52+
return $results;
53+
}
54+
4855
$packages = [];
4956

5057
foreach ($results as $result) {

src/Commands/Show.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function execute()
7676
$name,
7777
$result['description'] ?? '',
7878
$result['type'] ?? '',
79+
null,
7980
$result['version'],
8081
$result['latest'] ?? '',
8182
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE
@@ -138,6 +139,7 @@ public function execute()
138139
description: $result['description'] ?? '',
139140
keywords: $result['keywords'] ?? [],
140141
type: $result['type'] ?? 'library',
142+
path: $result['path'] ?? null,
141143
homepage: $result['homepage'] ?? '',
142144
authors: $result['authors'] ?? [],
143145
licenses: $result['licenses'] ?? [],
@@ -158,6 +160,7 @@ public function execute()
158160
description: $result['description'] ?? '',
159161
keywords: $result['keywords'] ?? [],
160162
type: $result['type'] ?? 'library',
163+
path: $result['path'] ?? null,
161164
homepage: $result['homepage'] ?? '',
162165
authors: $result['authors'] ?? [],
163166
licenses: $result['licenses'] ?? [],
@@ -178,16 +181,18 @@ public function execute()
178181
$name,
179182
$result['description'] ?? '',
180183
$result['type'] ?? '',
184+
$result['path'] ?? null,
181185
$result['version'],
182186
$result['latest'] ?? '',
183-
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE
187+
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE,
184188
);
185189
} else {
186190
return Composer::newPackage(
187191
$namespace,
188192
$name,
189193
$result['description'] ?? '',
190194
$result['type'] ?? '',
195+
$result['path'] ?? null
191196
);
192197
}
193198
}

src/Commands/Update.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Update extends BaseCommand
6565
* @param boolean $ignorePlatformReqs Ignore platform reqs when running the update.
6666
* @param string $installPreference Set an install preference - must be one of "none", "dist", "source"
6767
* @param boolean $ignoreScripts Ignores scripts that run after Composer events.
68+
* @param ?string $package Specify a specific package to update.
6869
* @return void
6970
*/
7071
final public function __construct(
@@ -74,18 +75,15 @@ final public function __construct(
7475
protected bool $ignorePlatformReqs = false,
7576
protected string $installPreference = 'none',
7677
protected bool $ignoreScripts = false,
77-
protected bool $dryRun = false
78+
protected bool $dryRun = false,
79+
protected ?string $package = null
7880
) {
7981
parent::__construct($composer);
8082

81-
$this->includeDev = $includeDev;
82-
$this->lockFileOnly = $lockFileOnly;
83-
$this->ignorePlatformReqs = $ignorePlatformReqs;
84-
$this->ignoreScripts = $ignoreScripts;
85-
$this->dryRun = $dryRun;
86-
87-
if (in_array($installPreference, [self::PREFER_NONE, self::PREFER_DIST, self::PREFER_SOURCE])) {
88-
$this->installPreference = $installPreference;
83+
if (!in_array($this->installPreference, [self::PREFER_NONE, self::PREFER_DIST, self::PREFER_SOURCE])) {
84+
throw new \InvalidArgumentException(
85+
'installPreference is not an allowed value `' . $this->installPreference . '`. See: "none", "dist", "source"'
86+
);
8987
}
9088
}
9189

@@ -337,6 +335,10 @@ protected function arguments(): array
337335
$arguments['--prefer-' . $this->installPreference] = true;
338336
}
339337

338+
if ($this->package) {
339+
$arguments['packages'] = [$this->package];
340+
}
341+
340342
return $arguments;
341343
}
342344
}

0 commit comments

Comments
 (0)