Skip to content

Commit

Permalink
normalize language around handing patch status (both state and status…
Browse files Browse the repository at this point in the history
… used before)
  • Loading branch information
Allan Paiste committed Sep 11, 2018
1 parent 1a2e70b commit 3d20795
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/Composer/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function generateOutput(OutputInterface $output, array $list)
{
$stateDecorators = array(
$statusDecorators = array(
'new' => '<info>NEW</info>',
'changed' => '<info>CHANGED</info>',
'applied' => '<fg=white;options=bold>APPLIED</>',
Expand All @@ -124,14 +124,14 @@ private function generateOutput(OutputInterface $output, array $list)
$output->writeln(sprintf('<info>%s</info>', $packageName));

foreach ($patches as $path => $info) {
$state = isset($info[PatchDefinition::STATE])
? $info[PatchDefinition::STATE]
$status = isset($info[PatchDefinition::STATUS])
? $info[PatchDefinition::STATUS]
: 'unknown';

$stateLabel = sprintf(' [%s]', $stateDecorators[$state]);
$statusLabel = sprintf(' [%s]', $statusDecorators[$status]);
$owner = $info[PatchDefinition::OWNER];

$output->writeln(sprintf(' ~ <info>%s</info>: %s%s', $owner, $path, $stateLabel));
$output->writeln(sprintf(' ~ <info>%s</info>: %s%s', $owner, $path, $statusLabel));
$output->writeln(sprintf(' <comment>%s</comment>', $info[PatchDefinition::LABEL]));
}

Expand Down
18 changes: 9 additions & 9 deletions src/Managers/PatchListManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public function getPatchesWithStatuses(array $patches, array $packages, array $s
$this->patchListUtils->groupItemsByTarget($patches)
);

$patchStates = array();
$patchStatuses = array();

foreach ($matchesFootprints as $target => $items) {
$newItems = array_diff_key($items, $repositoryState[$target]);
$changeItems = array_diff_key(array_diff_assoc($items, $repositoryState[$target]), $newItems);

$patchStates = array_replace(
$patchStates,
$patchStatuses = array_replace(
$patchStatuses,
array_fill_keys(array_keys($items), 'applied'),
array_fill_keys(array_keys($newItems), 'new'),
array_fill_keys(array_keys($changeItems), 'changed')
Expand All @@ -81,27 +81,27 @@ public function getPatchesWithStatuses(array $patches, array $packages, array $s
$items,
isset($patchesFootprints[$target]) ? $patchesFootprints[$target] : array()
),
$patchStates
$patchStatuses
);
}

$removedItems = $this->patchListUtils->createDetailedList($removedItems);

foreach ($removedItems as $target => $items) {
$patchStates = array_replace(
$patchStates,
$patchStatuses = array_replace(
$patchStatuses,
array_fill_keys(array_keys($items), 'removed')
);
}

$matches = $this->patchListUtils->mergeLists($matches, $removedItems);

$patchStates = preg_grep($statusFilterRegex, $patchStates);
$patchStatuses = preg_grep($statusFilterRegex, $patchStatuses);

foreach ($matches as $target => $items) {
foreach (array_keys($items) as $path) {
if (isset($patchStates[$path])) {
$matches[$target][$path][PatchDefinition::STATE] = $patchStates[$path];
if (isset($patchStatuses[$path])) {
$matches[$target][$path][PatchDefinition::STATUS] = $patchStatuses[$path];

continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Package/PatchApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function __construct(
$this->packageUtils = new \Vaimo\ComposerPatches\Utils\PackageUtils();

$this->stateLabels = array(
PatchDefinition::STATE_NEW => 'NEW',
PatchDefinition::STATE_CHANGED => 'CHANGED'
PatchDefinition::STATUS_NEW => 'NEW',
PatchDefinition::STATUS_CHANGED => 'CHANGED'
);
}

Expand All @@ -93,8 +93,8 @@ public function applyPatches(PackageInterface $package, array $patchesQueue)
$appliedPatches = array();

foreach ($patchesQueue as $source => $info) {
if (isset($info[PatchDefinition::STATE_LABEL])) {
$labelMatches = array($info[PatchDefinition::STATE_LABEL]);
if (isset($info[PatchDefinition::STATUS_LABEL])) {
$labelMatches = array($info[PatchDefinition::STATUS_LABEL]);
} else {
$labelMatches = array_intersect_key($this->stateLabels, array_filter($info));
}
Expand Down
6 changes: 5 additions & 1 deletion src/Patch/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ class Definition
const STATE_NEW = 'new';
const STATE_LABEL = 'state_label';

const STATE = 'state';
const STATUS_CHANGED = 'changed';
const STATUS_NEW = 'new';
const STATUS_LABEL = 'state_label';

const STATUS = 'state';
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function normalize($target, $label, array $data, array $ownerConfig)
PatchDefinition::PATH => isset($data[PatchDefinition::PATH]) && file_exists($data[PatchDefinition::PATH])
? $data[PatchDefinition::PATH]
: '',
PatchDefinition::STATE_NEW => true,
PatchDefinition::STATE_CHANGED => true,
PatchDefinition::STATUS_NEW => true,
PatchDefinition::STATUS_CHANGED => true,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function resolvePatchesQueue(array $patches)
if (array_filter($this->filters)) {
$patches = $this->patchListUtils->embedInfoToItems(
$patches,
array(PatchDefinition::STATE_LABEL => 'MATCH')
array(PatchDefinition::STATUS_LABEL => 'MATCH')
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/PatchListUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ public function generateKnownPatchFlagUpdates($ownerName, array $resetPatchesLis
$patchDefinitionUpdates = array_replace(
array_fill_keys(
array_keys($changedPatches),
array(Patch::STATE_NEW => false)
array(Patch::STATUS_NEW => false)
),
array_fill_keys(
array_keys($knownPatches),
array(Patch::STATE_NEW => false, Patch::STATE_CHANGED => false)
array(Patch::STATUS_NEW => false, Patch::STATUS_CHANGED => false)
)
);

Expand Down

0 comments on commit 3d20795

Please sign in to comment.