Skip to content

Commit

Permalink
Merge 0a762f2 into 9d82dd0
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Feb 3, 2020
2 parents 9d82dd0 + 0a762f2 commit 616f6be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/GitBranches.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use ArrayIterator;
use IteratorAggregate;
use Nette\Utils\Strings;

/**
* Class that parses and returnes an array of branches.
Expand Down Expand Up @@ -34,7 +33,7 @@ public function fetchBranches(bool $onlyRemote = false): array
{
$options = $onlyRemote ? ['r' => true] : ['a' => true];
$output = $this->gitWorkingCopy->branch($options);
$branches = (array) Strings::split(rtrim($output), "/\r\n|\n|\r/");
$branches = $this->splitByNewline(rtrim($output));
return array_map([$this, 'trimBranch'], $branches);
}

Expand Down Expand Up @@ -72,4 +71,9 @@ public function head(): string
{
return trim($this->gitWorkingCopy->run('rev-parse', ['--abbrev-ref', 'HEAD']));
}

private function splitByNewline(string $string): array
{
return (array)preg_split('#\R#', $string, PREG_SPLIT_NO_EMPTY);
}
}
8 changes: 6 additions & 2 deletions src/GitTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use ArrayIterator;
use IteratorAggregate;
use Nette\Utils\Strings;

/**
* Class that parses and returnes an array of Tags.
Expand All @@ -30,7 +29,7 @@ public function __construct(GitWorkingCopy $gitWorkingCopy)
public function fetchTags(): array
{
$output = $this->gitWorkingCopy->tag(['l' => true]);
$tags = (array) Strings::split(rtrim($output), "/\r\n|\n|\r/");
$tags = $this->splitByNewline(rtrim($output));
return array_map([$this, 'trimTags'], $tags);
}

Expand All @@ -55,4 +54,9 @@ public function all(): array
{
return $this->fetchTags();
}

private function splitByNewline(string $string): array
{
return (array)preg_split('#\R#', $string, PREG_SPLIT_NO_EMPTY);
}
}
3 changes: 1 addition & 2 deletions src/GitWorkingCopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace GitWrapper;

use GitWrapper\Exception\GitException;
use Nette\Utils\Strings;

/**
* Interacts with a working copy.
Expand Down Expand Up @@ -679,6 +678,6 @@ private function ensureAddRemoteArgsAreValid(string $name, string $url): void

private function splitByNewline(string $string): array
{
return Strings::split($string, '#\R#');
return (array)preg_split('#\R#', $string, PREG_SPLIT_NO_EMPTY);
}
}
4 changes: 1 addition & 3 deletions src/Strings/GitStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace GitWrapper\Strings;

use Nette\Utils\Strings;

final class GitStrings
{
/**
Expand All @@ -21,7 +19,7 @@ public static function parseRepositoryName(string $repositoryUrl): string
$path = end($parts);
} else {
$strpos = strpos($repositoryUrl, ':');
$path = Strings::substring($repositoryUrl, $strpos + 1);
$path = mb_substr($repositoryUrl, $strpos + 1);
}

/** @var string $path */
Expand Down

0 comments on commit 616f6be

Please sign in to comment.