96 lines
1.8 KiB
PHP
96 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Kiri\Di;
|
||
|
|
|
||
|
|
class ChangeSet
|
||
|
|
{
|
||
|
|
private array $changedFiles = [];
|
||
|
|
|
||
|
|
private array $removedFiles = [];
|
||
|
|
|
||
|
|
private array $changedClasses = [];
|
||
|
|
|
||
|
|
private array $removedClasses = [];
|
||
|
|
|
||
|
|
public function addChangedFile(string $file): void
|
||
|
|
{
|
||
|
|
$this->changedFiles[$file] = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addRemovedFile(string $file): void
|
||
|
|
{
|
||
|
|
$this->removedFiles[$file] = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addChangedClass(string $class): void
|
||
|
|
{
|
||
|
|
$this->changedClasses[$class] = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function addRemovedClass(string $class): void
|
||
|
|
{
|
||
|
|
$this->removedClasses[$class] = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function merge(ChangeSet $changeSet): self
|
||
|
|
{
|
||
|
|
foreach ($changeSet->getChangedFiles() as $file) {
|
||
|
|
$this->addChangedFile($file);
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($changeSet->getRemovedFiles() as $file) {
|
||
|
|
$this->addRemovedFile($file);
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($changeSet->getChangedClasses() as $class) {
|
||
|
|
$this->addChangedClass($class);
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($changeSet->getRemovedClasses() as $class) {
|
||
|
|
$this->addRemovedClass($class);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getChangedFiles(): array
|
||
|
|
{
|
||
|
|
return array_keys($this->changedFiles);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getRemovedFiles(): array
|
||
|
|
{
|
||
|
|
return array_keys($this->removedFiles);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getChangedClasses(): array
|
||
|
|
{
|
||
|
|
return array_keys($this->changedClasses);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getRemovedClasses(): array
|
||
|
|
{
|
||
|
|
return array_keys($this->removedClasses);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function hasChanges(): bool
|
||
|
|
{
|
||
|
|
return $this->changedFiles !== []
|
||
|
|
|| $this->removedFiles !== []
|
||
|
|
|| $this->changedClasses !== []
|
||
|
|
|| $this->removedClasses !== [];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'changed_files' => $this->getChangedFiles(),
|
||
|
|
'removed_files' => $this->getRemovedFiles(),
|
||
|
|
'changed_classes' => $this->getChangedClasses(),
|
||
|
|
'removed_classes' => $this->getRemovedClasses(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|