composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -0,0 +1,127 @@
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Diff;
use Gitonomy\Git\Parser\DiffParser;
use Gitonomy\Git\Repository;
/**
* Representation of a diff.
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class Diff
{
/**
* @var array
*/
protected $files;
/**
* @var string
*/
protected $rawDiff;
/**
* Constructs a new diff for a given revision.
*
* @param array $files The files
* @param string $rawDiff The raw diff
*/
public function __construct(array $files, $rawDiff)
{
$this->files = $files;
$this->rawDiff = $rawDiff;
}
/**
* @return Diff
*/
public static function parse($rawDiff)
{
$parser = new DiffParser();
$parser->parse($rawDiff);
return new self($parser->files, $rawDiff);
}
public function setRepository(Repository $repository)
{
foreach ($this->files as $file) {
$file->setRepository($repository);
}
}
/**
* @return array
*/
public function getRevisions()
{
return $this->revisions;
}
/**
* Get list of files modified in the diff's revision.
*
* @return array An array of Diff\File objects
*/
public function getFiles()
{
return $this->files;
}
/**
* Returns the raw diff.
*
* @return string The raw diff
*/
public function getRawDiff()
{
return $this->rawDiff;
}
/**
* Export a diff as array.
*
* @return array The array
*/
public function toArray()
{
return array(
'rawDiff' => $this->rawDiff,
'files' => array_map(
function (File $file) {
return $file->toArray();
}, $this->files
),
);
}
/**
* Create a new instance of Diff from an array.
*
* @param array $array The array
*
* @return Diff The new instance
*/
public static function fromArray(array $array)
{
return new static(
array_map(
function ($array) {
return File::fromArray($array);
}, $array['files']
),
$array['rawDiff']
);
}
}

View File

@@ -0,0 +1,289 @@
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Diff;
use Gitonomy\Git\Repository;
/**
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class File
{
/**
* @var string
*/
protected $oldName;
/**
* @var string
*/
protected $newName;
/**
* @var string
*/
protected $oldMode;
/**
* @var string
*/
protected $newMode;
/**
* @var string
*/
protected $oldIndex;
/**
* @var string
*/
protected $newIndex;
/**
* @var bool
*/
protected $isBinary;
/**
* @var array An array of FileChange objects
*/
protected $changes;
/**
* @var Repository
*/
protected $repository;
/**
* Instanciates a new File object.
*/
public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $newIndex, $isBinary)
{
$this->oldName = $oldName;
$this->newName = $newName;
$this->oldMode = $oldMode;
$this->newMode = $newMode;
$this->oldIndex = $oldIndex;
$this->newIndex = $newIndex;
$this->isBinary = $isBinary;
$this->changes = array();
}
public function addChange(FileChange $change)
{
$this->changes[] = $change;
}
/**
* Indicates if this diff file is a creation.
*
* @return bool
*/
public function isCreation()
{
return null === $this->oldName;
}
/**
* Indicates if this diff file is a modification.
*
* @return bool
*/
public function isModification()
{
return null !== $this->oldName && null !== $this->newName;
}
/**
* Indicates if it's a rename.
*
* A rename can only occurs if it's a modification (not a creation or a deletion).
*
* @return bool
*/
public function isRename()
{
return $this->isModification() && $this->oldName !== $this->newName;
}
/**
* Indicates if the file mode has changed.
*/
public function isChangeMode()
{
return $this->isModification() && $this->oldMode !== $this->newMode;
}
/**
* Indicates if this diff file is a deletion.
*
* @return bool
*/
public function isDeletion()
{
return null === $this->newName;
}
/**
* Indicates if this diff file is a deletion.
*
* @return bool
*/
public function isDelete()
{
return null === $this->newName;
}
/**
* @return int Number of added lines
*/
public function getAdditions()
{
$result = 0;
foreach ($this->changes as $change) {
$result += $change->getCount(FileChange::LINE_ADD);
}
return $result;
}
/**
* @return int Number of deleted lines
*/
public function getDeletions()
{
$result = 0;
foreach ($this->changes as $change) {
$result += $change->getCount(FileChange::LINE_REMOVE);
}
return $result;
}
public function getOldName()
{
return $this->oldName;
}
public function getNewName()
{
return $this->newName;
}
public function getName()
{
if (null === $this->newName) {
return $this->oldName;
}
return $this->newName;
}
public function getOldMode()
{
return $this->oldMode;
}
public function getNewMode()
{
return $this->newMode;
}
public function getOldIndex()
{
return $this->oldIndex;
}
public function getNewIndex()
{
return $this->newIndex;
}
public function isBinary()
{
return $this->isBinary;
}
public function getChanges()
{
return $this->changes;
}
public function toArray()
{
return array(
'old_name' => $this->oldName,
'new_name' => $this->newName,
'old_mode' => $this->oldMode,
'new_mode' => $this->newMode,
'old_index' => $this->oldIndex,
'new_index' => $this->newIndex,
'is_binary' => $this->isBinary,
'changes' => array_map(function (FileChange $change) {
return $change->toArray();
}, $this->changes),
);
}
public static function fromArray(array $array)
{
$file = new self($array['old_name'], $array['new_name'], $array['old_mode'], $array['new_mode'], $array['old_index'], $array['new_index'], $array['is_binary']);
foreach ($array['changes'] as $change) {
$file->addChange(FileChange::fromArray($change));
}
return $file;
}
public function getAnchor()
{
return substr($this->newIndex, 0, 12);
}
public function getRepository()
{
return $this->repository;
}
public function setRepository(Repository $repository)
{
$this->repository = $repository;
}
public function getOldBlob()
{
if (null === $this->repository) {
throw new \RuntimeException('Repository is missing to return Blob object.');
}
if ($this->isCreation()) {
throw new \LogicException('Can\'t return old Blob on a creation');
}
return $this->repository->getBlob($this->oldIndex);
}
public function getNewBlob()
{
if (null === $this->repository) {
throw new \RuntimeException('Repository is missing to return Blob object.');
}
if ($this->isDeletion()) {
throw new \LogicException('Can\'t return new Blob on a deletion');
}
return $this->repository->getBlob($this->newIndex);
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Diff;
class FileChange
{
const LINE_CONTEXT = 0;
const LINE_REMOVE = -1;
const LINE_ADD = 1;
protected $rangeOldStart;
protected $rangeOldCount;
protected $rangeNewStart;
protected $rangeNewCount;
protected $lines;
public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $rangeNewCount, $lines)
{
$this->rangeOldStart = $rangeOldStart;
$this->rangeOldCount = $rangeOldCount;
$this->rangeNewStart = $rangeNewStart;
$this->rangeNewCount = $rangeNewCount;
$this->lines = $lines;
}
public function getCount($type)
{
$result = 0;
foreach ($this->lines as $line) {
if ($line[0] === $type) {
++$result;
}
}
return $result;
}
public function getRangeOldStart()
{
return $this->rangeOldStart;
}
public function getRangeOldCount()
{
return $this->rangeOldCount;
}
public function getRangeNewStart()
{
return $this->rangeNewStart;
}
public function getRangeNewCount()
{
return $this->rangeNewCount;
}
public function getLines()
{
return $this->lines;
}
public function toArray()
{
return array(
'range_old_start' => $this->rangeOldStart,
'range_old_count' => $this->rangeOldCount,
'range_new_start' => $this->rangeNewStart,
'range_new_count' => $this->rangeNewCount,
'lines' => $this->lines,
);
}
public static function fromArray(array $array)
{
return new self($array['range_old_start'], $array['range_old_count'], $array['range_new_start'], $array['range_new_count'], $array['lines']);
}
}