Skip to content
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"scripts": {
"test": "phpunit --testdox --colors=\"auto\"",
"tests": "phpunit --testdox --colors=\"auto\"",
"analyze": "./vendor/bin/phpstan analyse",
"coverage": "XDEBUG_MODE=coverage phpunit --testdox --colors=\"auto\" --coverage-html=\"coverage\""
},
"require": {
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ parameters:
ignoreErrors:
- message: '#message has no type specified#'
path: src/Exceptions/*.php
- message: '#has parameter .+ with no value type specified in iterable type array#'
path: src/Composer.php
69 changes: 69 additions & 0 deletions src/Commands/Remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Winter\Packager\Commands;

use Winter\Packager\Composer;
use Winter\Packager\Exceptions\CommandException;

class Remove extends BaseCommand
{
/**
* Command constructor.
*/
final public function __construct(
protected Composer $composer,
protected string $package,
protected bool $dryRun = false,
protected bool $dev = false
) {
parent::__construct($composer);
}

/**
* @inheritDoc
*/
public function arguments(): array
{
$arguments = [];

if ($this->dryRun) {
$arguments['--dry-run'] = true;
}

if ($this->dev) {
$arguments['--dev'] = true;
}

$arguments['packages'] = [$this->package];

return $arguments;
}

public function execute()
{
$output = $this->runComposerCommand();
$message = implode(PHP_EOL, $output['output']);

if ($output['code'] !== 0) {
throw new CommandException($message);
}

return $message;
}

/**
* @inheritDoc
*/
protected function requiresWorkDir(): bool
{
return true;
}

/**
* @inheritDoc
*/
public function getCommandName(): string
{
return 'remove';
}
}
74 changes: 74 additions & 0 deletions src/Commands/RequireCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Winter\Packager\Commands;

use Winter\Packager\Composer;
use Winter\Packager\Exceptions\CommandException;
use Winter\Packager\Exceptions\WorkDirException;

class RequireCommand extends BaseCommand
{
/**
* Command constructor.
*/
final public function __construct(
protected Composer $composer,
protected string $package,
protected bool $dryRun = false,
protected bool $dev = false
) {
parent::__construct($composer);
}

/**
* @inheritDoc
*/
public function arguments(): array
{
$arguments = [];

if ($this->dryRun) {
$arguments['--dry-run'] = true;
}

if ($this->dev) {
$arguments['--dev'] = true;
}

$arguments['packages'] = [$this->package];

return $arguments;
}

/**
* @throws CommandException
* @throws WorkDirException
*/
public function execute(): string
{
$output = $this->runComposerCommand();
$message = implode(PHP_EOL, $output['output']);

if ($output['code'] !== 0) {
throw new CommandException($message);
}

return $message;
}

/**
* @inheritDoc
*/
protected function requiresWorkDir(): bool
{
return true;
}

/**
* @inheritDoc
*/
public function getCommandName(): string
{
return 'require';
}
}
11 changes: 9 additions & 2 deletions src/Commands/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class Search extends BaseCommand
* @param string $query The search query to find packages.
* @param string|null $type The type of package to search for.
* @param SearchLimitTo $limitTo Limit the returned results.
* @param bool $returnArray Return the search results as an array.
*/
final public function __construct(
Composer $composer,
public string $query,
public ?string $type = null,
public SearchLimitTo $limitTo = SearchLimitTo::ALL
public SearchLimitTo $limitTo = SearchLimitTo::ALL,
public bool $returnArray = false,
) {
parent::__construct($composer);
}
Expand All @@ -44,7 +46,12 @@ public function execute()
throw new CommandException(implode(PHP_EOL, $output['output']));
}

$results = json_decode(implode(PHP_EOL, $output['output']), true);
$results = json_decode(implode(PHP_EOL, $output['output']), flags: JSON_OBJECT_AS_ARRAY) ?? [];

if ($this->returnArray) {
return $results;
}

$packages = [];

foreach ($results as $result) {
Expand Down
7 changes: 6 additions & 1 deletion src/Commands/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function execute()
$name,
$result['description'] ?? '',
$result['type'] ?? '',
null,
$result['version'],
$result['latest'] ?? '',
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE
Expand Down Expand Up @@ -138,6 +139,7 @@ public function execute()
description: $result['description'] ?? '',
keywords: $result['keywords'] ?? [],
type: $result['type'] ?? 'library',
path: $result['path'] ?? null,
homepage: $result['homepage'] ?? '',
authors: $result['authors'] ?? [],
licenses: $result['licenses'] ?? [],
Expand All @@ -158,6 +160,7 @@ public function execute()
description: $result['description'] ?? '',
keywords: $result['keywords'] ?? [],
type: $result['type'] ?? 'library',
path: $result['path'] ?? null,
homepage: $result['homepage'] ?? '',
authors: $result['authors'] ?? [],
licenses: $result['licenses'] ?? [],
Expand All @@ -178,16 +181,18 @@ public function execute()
$name,
$result['description'] ?? '',
$result['type'] ?? '',
$result['path'] ?? null,
$result['version'],
$result['latest'] ?? '',
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE
VersionStatus::tryFrom($result['latest-status'] ?? '') ?? VersionStatus::UP_TO_DATE,
);
} else {
return Composer::newPackage(
$namespace,
$name,
$result['description'] ?? '',
$result['type'] ?? '',
$result['path'] ?? null
);
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/Commands/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Update extends BaseCommand
* @param boolean $ignorePlatformReqs Ignore platform reqs when running the update.
* @param string $installPreference Set an install preference - must be one of "none", "dist", "source"
* @param boolean $ignoreScripts Ignores scripts that run after Composer events.
* @param ?string $package Specify a specific package to update.
* @return void
*/
final public function __construct(
Expand All @@ -74,18 +75,15 @@ final public function __construct(
protected bool $ignorePlatformReqs = false,
protected string $installPreference = 'none',
protected bool $ignoreScripts = false,
protected bool $dryRun = false
protected bool $dryRun = false,
protected ?string $package = null
) {
parent::__construct($composer);

$this->includeDev = $includeDev;
$this->lockFileOnly = $lockFileOnly;
$this->ignorePlatformReqs = $ignorePlatformReqs;
$this->ignoreScripts = $ignoreScripts;
$this->dryRun = $dryRun;

if (in_array($installPreference, [self::PREFER_NONE, self::PREFER_DIST, self::PREFER_SOURCE])) {
$this->installPreference = $installPreference;
if (!in_array($this->installPreference, [self::PREFER_NONE, self::PREFER_DIST, self::PREFER_SOURCE])) {
throw new \InvalidArgumentException(
'installPreference is not an allowed value `' . $this->installPreference . '`. See: "none", "dist", "source"'
);
}
}

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

if ($this->package) {
$arguments['packages'] = [$this->package];
}

return $arguments;
}
}
Loading
Loading