Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes phpcollection/phpcollection redundant #189

Merged
merged 6 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ If you build a GitElephant\Status\Status class, you will get a nice api for gett
$status = $repo->getStatus();
$status = GitElephant\Status\Status::get($repo); // it's the same...

$status->all(); // A PhpCollection of StatusFile objects
$status->all(); // A Sequence of StatusFile objects
$status->untracked();
$status->modified();
$status->added();
Expand All @@ -168,7 +168,7 @@ $status->renamed();
$status->copied();
```

all this methods returns a [PhpCollection](https://github.com/schmittjoh/php-collection) of StatusFile objects
all this methods returns a Sequence of StatusFile objects, credit to [PhpCollection](https://github.com/schmittjoh/php-collection)

a StatusFile instance has all the information about the tree node changes. File names (and new file names for renamed objects), index and working tree status, and also a "git style" description like: *added to index* or *deleted in work tree*

Expand Down Expand Up @@ -354,7 +354,7 @@ Dependencies
- [symfony/process](https://packagist.org/packages/symfony/process)
- [symfony/filesystem](https://packagist.org/packages/symfony/filesystem)
- [symfony/finder](https://packagist.org/packages/symfony/finder)
- [phpcollection/phpcollection](https://github.com/schmittjoh/php-collection)
- [phpoption/phpoption](https://github.com/schmittjoh/php-option)

*for tests*

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/process": ">=3.4",
"symfony/filesystem": ">=3.4",
"symfony/finder": ">=3.4",
"phpcollection/phpcollection": "~0.4|~0.5"
"phpoption/phpoption": "1.*"
},
"require-dev": {
"php": ">=7.2.0",
Expand Down
7 changes: 3 additions & 4 deletions src/GitElephant/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
namespace GitElephant\Command;

use GitElephant\Repository;
use PhpCollection\Map;

/**
* BaseCommand
Expand Down Expand Up @@ -177,7 +176,7 @@ protected function getCommandName(): string
/**
* Set Configs
*
* @param array|Map $configs the config variable. i.e. { "color.status" => "false", "color.diff" => "true" }
* @param array $configs the config variable. i.e. { "color.status" => "false", "color.diff" => "true" }
*/
public function addConfigs($configs): void
{
Expand All @@ -189,7 +188,7 @@ public function addConfigs($configs): void
/**
* Set global configs
*
* @param array|Map $configs the config variable. i.e. { "color.status" => "false", "color.diff" => "true" }
* @param array $configs the config variable. i.e. { "color.status" => "false", "color.diff" => "true" }
*/
protected function addGlobalConfigs($configs): void
{
Expand All @@ -203,7 +202,7 @@ protected function addGlobalConfigs($configs): void
/**
* Set global option
*
* @param array|Map $options a global option
* @param array $options a global option
*/
protected function addGlobalOptions($options): void
{
Expand Down
8 changes: 4 additions & 4 deletions src/GitElephant/Objects/Diff/DiffChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ private function getLinesNumbers(string $line): void
preg_match('/@@ -(.*) \+(.*) @@?(.*)/', $line, $matches);
if (!strpos($matches[1], ',')) {
// one line
$this->originStartLine = $matches[1];
$this->originEndLine = $matches[1];
$this->originStartLine = (int) $matches[1];
$this->originEndLine = (int) $matches[1];
} else {
$this->originStartLine = (int) explode(',', $matches[1])[0];
$this->originEndLine = (int) explode(',', $matches[1])[1];
}

if (!strpos($matches[2], ',')) {
// one line
$this->destStartLine = $matches[2];
$this->destEndLine = $matches[2];
$this->destStartLine = (int) $matches[2];
$this->destEndLine = (int) $matches[2];
} else {
$this->destStartLine = (int) explode(',', $matches[2])[0];
$this->destEndLine = (int) explode(',', $matches[2])[1];
Expand Down
2 changes: 1 addition & 1 deletion src/GitElephant/Objects/Diff/DiffObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private function findSimilarityIndex(string $line): void
{
$matches = [];
if (preg_match('/^similarity index (.*)\%$/', $line, $matches)) {
$this->similarityIndex = $matches[1];
$this->similarityIndex = (int) $matches[1];
}
}

Expand Down
62 changes: 62 additions & 0 deletions src/GitElephant/Sequence/AbstractCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace GitElephant\Sequence;

use PhpOption\LazyOption;
use PhpOption\None;
use PhpOption\Some;

abstract class AbstractCollection implements \IteratorAggregate
{
/**
* @param mixed $searchedElem
*
* @return bool
*/
public function contains($searchedElem): bool
{
foreach ($this as $elem) {
if ($elem === $searchedElem) {
return true;
}
}

return false;
}

/**
* @param callable $callable
*
* @return \PhpOption\LazyOption
*/
public function find(callable $callable): LazyOption
{
$self = $this;

return new LazyOption(function () use ($callable, $self) {
foreach ($self as $elem) {
if ($callable($elem) === true) {
return new Some($elem);
}
}

return None::create();
});
}
}
Loading