Adding comments and parameters

This commit is contained in:
Dennis Eichhorn 2016-03-14 14:22:37 +01:00
parent 776717ad53
commit 7ffcb763e9
12 changed files with 895 additions and 40 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Compression;
/**
* Compression Interface
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface CompressionInterface
{
/**
* Compresses source text
*
* @param string $source Source text to compress
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function compress(string $source) : string;
/**
* Decompresses text
*
* @param string $compressed Compressed text to decompress
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function decompress(string $compressed) : string;
}

View File

@ -1,10 +1,41 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Compression;
/**
* LZW compression class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class LZW implements CompressionInterface
{
public static function compress($unc) {
$i;$c;$wc;
$w = "";
/**
* {@inheritdoc}
*/
public function compress(string $source) : string
{
$wc = '';
$w = '';
$dictionary = [];
$result = [];
$dictSize = 256;
@ -13,8 +44,8 @@ class LZW implements CompressionInterface
$dictionary[chr($i)] = $i;
}
for ($i = 0; $i < strlen($unc); $i++) {
$c = $unc[$i];
for ($i = 0; $i < strlen($source); $i++) {
$c = $source[$i];
$wc = $w.$c;
if (array_key_exists($w. $c, $dictionary)) {
@ -26,29 +57,32 @@ class LZW implements CompressionInterface
}
}
if ($w !== "") {
if ($w !== '') {
array_push($result,$dictionary[$w]);
}
return implode(",",$result);
return implode(',',$result);
}
public static function decompress($com) {
$com = explode(",",$com);
$i;$w;$k;$result;
/**
* {@inheritdoc}
*/
public function decompress(string $compressed) : string
{
$compressed = explode(',', $compressed);
$dictionary = [];
$entry = "";
$entry = '';
$dictSize = 256;
for ($i = 0; $i < 256; $i++) {
$dictionary[$i] = chr($i);
}
$w = chr($com[0]);
$w = chr($compressed[0]);
$result = $w;
for ($i = 1; $i < count($com);$i++) {
$k = $com[$i];
for ($i = 1; $i < count($compressed);$i++) {
$k = $compressed[$i];
if ($dictionary[$k]) {
$entry = $dictionary[$k];

View File

@ -0,0 +1,54 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Encoding;
/**
* Encoding Interface
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface EncodingInterface
{
/**
* Encode source text
*
* @param string $source Source text to decode
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function decode($source);
/**
* Dedecodes text
*
* @param string $decoded decoded text to dedecode
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function decode($decoded);
}

View File

@ -1,11 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Encoding;
class Gray {
/**
* Gray encoding class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
final class Gray {
/**
* {@inheritdoc}
*/
public static function encode(int $source) : int
{
return $source ^ ($source >> 1);
}
/**
* {@inheritdoc}
*/
public static function decode(int $gray) : int
{
$source = $gray;

View File

@ -1,23 +1,85 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Git;
/**
* Gray encoding class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Author
{
/**
* Name.
*
* @var string
* @since 1.0.0
*/
private $name = '';
/**
* Email.
*
* @var string
* @since 1.0.0
*/
private $email = '';
/**
* Constructor
*
* @param string $name Author name
* @param string $email Author email
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $name, string $email)
{
$this->name = $name;
$this->email = $email;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : string
{
return $name;
}
/**
* Get email
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEmail() : string
{
return $email;

View File

@ -1,21 +1,75 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Git;
/**
* Gray encoding class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Branch
{
/**
* Name.
*
* @var string
* @since 1.0.0
*/
private $name = '';
/**
* Constructor
*
* @param string $name Branch name
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $name)
{
$this->name = $name;
}
/**
* Set branch name
*
* @param string $name Branch name
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : string
{
return $this->name;

View File

@ -1,35 +1,143 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Git;
/**
* Gray encoding class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Commit
{
/**
* Hash.
*
* @var string
* @since 1.0.0
*/
private $id = '';
/**
* Author.
*
* @var Author
* @since 1.0.0
*/
private $author = null;
/**
* Branch.
*
* @var Branch
* @since 1.0.0
*/
private $branch = null;
/**
* Tag.
*
* @var Tag
* @since 1.0.0
*/
private $tag = null;
/**
* Commit date.
*
* @var \DateTime
* @since 1.0.0
*/
private $date = null;
/**
* Repository.
*
* @var Repository
* @since 1.0.0
*/
private $repository = null;
/**
* Commit message.
*
* @var string
* @since 1.0.0
*/
private $message = '';
/**
* Files.
*
* @var string[]
* @since 1.0.0
*/
private $files = [];
/**
* Constructor
*
* @param string $id Commit hash
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $id = '') {
$author = new Author();
$branch = new Branch();
$tag = new Tag();
if(!empty($id)) {
// todo: fill base info
}
}
/**
* Add file to commit.
*
* @param string $path File path
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function addFile(string $path) {
if(!isset($this->files[$path])) {
$this->files[$path] = [];
}
}
public function addChange(string $path, int $line, string $old, string $new)
/**
* Add change.
*
* @param string $path File path
* @param int $line Line number
* @param string $old Old line
* @param string $new New line
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function addChange(string $path, int $line, string $old, string $new)
{
if(!isset($this->files[$path])) {
throw new \Exception();
@ -42,64 +150,180 @@ class Commit
}
}
/**
* Set commit message.
*
* @param string $path File path
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setMessage(string $message)
{
$this->message = $message;
}
/**
* Get commit message.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getMessage() : string
{
return $this->message;
}
public function getFiles() : array {
/**
* Get files of this commit.
*
* @return string[]
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFiles() : array
{
return $this->files;
}
public function removeFile(string $path) {
/**
* Get files of this commit.
*
* @param string $path File path
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function removeFile(string $path) : bool
{
if(isset($this->files[$path])) {
unset($this->files[$path]);
return true;
}
return false;
}
/**
* Set commit author.
*
* @param Author $author Commit author
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setAuthor(Author $author)
{
$this->author = $author;
}
/**
* Get commit author.
*
* @return Author
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAuthor() : Author
{
return $this->author;
}
/**
* Set commit branch.
*
* @param Branch $branch Commit branch
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setBranch(Branch $branch) {
$this->branch = $branch;
}
/**
* Get commit branch.
*
* @return Branch
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getBranch() : Branch
{
return $this->branch;
}
/**
* Set commit tag.
*
* @param Repository $tag Commit tag
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setTag(Tag $tag) {
$this->tag = $tag;
}
/**
* Get commit tag.
*
* @return Tag
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTag() : Tag
{
return $this->tag;
}
/**
* Get commit date.
*
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDate() : \DateTime
{
return $this->date;
return $this->date ?? new \DateTime('now');
}
public function setRepository(Reporsitory $repository)
/**
* Set commit repository.
*
* @param Repository $repository Commit repository
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setRepository(Repository $repository)
{
$this->repository = $repository;
}
public function getRepository() : Reporsitory
/**
* Get commit repository.
*
* @return Repository
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getRepository() : Repository
{
retrun $this->repository;
return $this->repository;
}
}
}

View File

@ -1,19 +1,80 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Git;
/**
* Gray encoding class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Git {
/**
* Git path.
*
* @var string
* @since 1.0.0
*/
protected static $bin = '/usr/bin/git';
public static function setBin(string $path) {
self::$bin = $path;
/**
* Set git binary.
*
* @param string $path Git path
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function setBin(string $path)
{
if(realpath($path) === false) {
throw new \PathException($path)
}
self::$bin = realpath($path);
}
public static function getBin() : string {
/**
* Get git binary.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getBin() : string
{
return self::$bin;
}
public static function test() : bool {
/**
* Test git.
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function test() : bool
{
$pipes = [];
$resource = proc_open(Git::getBin(), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);

View File

@ -1,18 +1,79 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\Git;
/**
* Repository class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Repository
{
/**
* Repository path.
*
* @var string
* @since 1.0.0
*/
private $path = '';
/**
* Bare repository.
*
* @var bool
* @since 1.0.0
*/
private $bare = false;
/**
* Env variables.
*
* @var array
* @since 1.0.0
*/
private $envOptions = [];
/**
* Constructor
*
* @param string $path Repository path
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $path)
{
$this->setPath($path);
}
/**
* Create repository
*
* @param string $source Create repository from source (optional, can be remote)
* @param bool $bare Bare repository
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function create(string $source = null, bool $bare = false)
{
if (!is_dir($this->path) || file_exists($this->path . '/.git')) {
@ -26,10 +87,18 @@ class Repository
}
}
/**
* Set repository path.
*
* @param string $path Path to repository
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function setPath(string $path)
{
if (!is_dir($this->path)) {
throw new \Exception('Is not a directory');
if (!is_dir($path)) {
throw new \PathException($path);
}
$this->path = realpath($path);
@ -46,7 +115,15 @@ class Repository
}
}
private function run($cmd)
/**
* Run git command.
*
* @param string $cmd Command to run
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function run(string $cmd) : string
{
$cmd = Git::getBin() . ' ' . $cmd;
$pipes = [];
@ -81,11 +158,27 @@ class Repository
return $stdout;
}
/**
* Get directory path.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDirectoryPath() : string
{
return $this->bare ? $this->path : $this->path . '/.git';
}
/**
* Get status.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function status() : string
{
return $this->run('status');
@ -259,12 +352,20 @@ class Repository
$this->envOptions[$key] = $value;
}
public function getMessage(string $commit) : string
public function getCommit(string $commit) : Commit
{
return $this->run('log --format=%B -n 1 ' . $commit);
}
public function getCommitsCount() : string
/**
* Count Commits.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCommitsCount(\DateTime $start = null, \DateTime $end = null, Author $author = null) : int
{
$result = $this->normalizeResult($this->run('shortlog -s -n --all'));
@ -276,16 +377,44 @@ class Repository
str_replace('\t', '|', trim($result));
}
public function getCommitsBy(string $author, \DateTime $start, \DateTime $end) : string
/**
* Get commits by author.
*
* @param Author $author Commits by author
* @param \DateTime $start Commits from
* @param \DateTime $end Commits to
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCommitsBy(Author $author, \DateTime $start = null, \DateTime $end) : array
{
return $this->run('git log --before="' . $end->format('Y-m-d') . '" --after="' . $start->format('Y-m-d') . '" --author="' . $author . '" --reverse --pretty=format:"%cd %h %s" --date=short');
return $this->run('git log --before="' . $end->format('Y-m-d') . '" --after="' . $start->format('Y-m-d') . '" --author="' . $author->getName() . '" --reverse --pretty=format:"%cd %h %s" --date=short');
}
/**
* Get remote.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getRemote() : string
{
return $this->run('config --get remote.origin.url');
}
/**
* Get newest commit.
*
* @return Commit
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getNewest() : string
{
return $this->run('log --name-status HEAD^..HEAD');

View File

@ -45,10 +45,28 @@ class MultiMap implements \Countable
*/
private $keys = [];
/**
* UID.
*
* @var int[]
* @since 1.0.0
*/
private $uids = [];
/**
* Key type.
*
* @var int
* @since 1.0.0
*/
private $keyType = KeyType::LOOSE;
/**
* Order type.
*
* @var int
* @since 1.0.0
*/
private $orderType = OrderType::LOOSE;
/**

View File

@ -0,0 +1,73 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\RnG;
/**
* Array randomizer class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ArrayRandomize
{
/**
* Yates array shuffler.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function yates(array $arr) : array
{
$shuffled = [];
while($arr){
$rnd = array_rand($arr);
$shuffled[] = $arr[$rnd];
array_splice($arr, $rnd, 1);
}
return $shuffled;
}
/**
* Knuths array shuffler.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function knuth(array $arr) : array
{
$shuffled = [];
for($i = count($arr)-1; $i > 0; $i--){
$rnd = mt_rand(0, $i);
$shuffled[$i] = $arr[$rnd];
$shuffled[$rand] = $arr[$i];
}
return $shuffled;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\RnG;
/**
* Linear congruential generator class
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class LinearCongruentialGenerator
{
/**
* BSD random number
*
* @return \Closure
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function bsd(int $seed)
{
return function() use(&$seed) {
return $seed = (1103515245 * $seed + 12345) % (1 << 31);
}
}
/**
* MS random number
*
* @return \Closure
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function msvcrt(int $seed) {
return function() use (&$seed) {
return ($seed = (214013 * $seed + 2531011) % (1 << 31)) >> 16;
};
}
}