Skip to content

Commit

Permalink
Merge pull request #168 from matteosister/march-2020-improvements
Browse files Browse the repository at this point in the history
March 2020 improvements
  • Loading branch information
imunhatep authored Apr 17, 2020
2 parents abec0aa + 306f14c commit 58c2c96
Show file tree
Hide file tree
Showing 49 changed files with 476 additions and 253 deletions.
76 changes: 52 additions & 24 deletions .github/workflows/code_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Code_Checks

on:
pull_request: null
pull_request:
push:
branches:
- master
Expand All @@ -11,36 +11,64 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4']
php:
- "7.2"
- "7.3"
- "7.4"
symfony:
- 3.*
- 4.*
- 5.*
dependency-version:
# - prefer-lowest
- prefer-stable

name: PHP ${{ matrix.php }} tests
name: PHP ${{ matrix.php }} - S ${{ matrix.symfony }} - ${{ matrix.dependency-version }} - tests
steps:
# basically git clone
- uses: actions/checkout@v2
- uses: actions/checkout@v2

# use PHP of specific version
- uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
coverage: none # disable xdebug, pcov

- run: git --version
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "GitHub Action"
- run: git --version
- name: Setup Git
run: |
git --version
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git --version
# if we 2 steps like this, we can better see if composer failed or tests
- run: composer install --no-progress
- name: Setup PHP
# use PHP of specific version
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
coverage: none # disable xdebug, pcov
tools: composer

- run: composer tests
- name: Install Composer Dependencies
run: |
composer require "symfony/process:${{ matrix.symfony }}" "symfony/filesystem:${{ matrix.symfony }}" "symfony/finder:${{ matrix.symfony }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Run PHPUnit Tests
run: composer tests

static_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.3
coverage: none # disable xdebug, pcov
- run: composer install --no-progress
- run: ./vendor/bin/phpstan analyse -c phpstan.neon

code_style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.3
coverage: none # disable xdebug, pcov
- run: composer install --no-progress
- run: composer check-cs
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
with:
php-version: 7.3
coverage: none # disable xdebug, pcov
- run: composer install --no-progress
- run: composer check-cs
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
![GitElephant](https://raw.github.com/matteosister/GitElephant/develop/graphics/gitelephant_600.png)

[![Latest Stable Version](https://poser.pugx.org/cypresslab/GitElephant/v/stable.png)](https://packagist.org/packages/cypresslab/GitElephant) [![License](https://poser.pugx.org/cypresslab/gitelephant/license.png)](https://packagist.org/packages/cypresslab/gitelephant) [![Total Downloads](https://poser.pugx.org/cypresslab/GitElephant/downloads.png)](https://packagist.org/packages/cypresslab/GitElephant) [![Montly Downloads](https://poser.pugx.org/cypresslab/gitelephant/d/monthly.png)](https://packagist.org/packages/cypresslab/gitelephant)

[![Build Status](https://travis-ci.org/matteosister/GitElephant.png?branch=master)](https://travis-ci.org/matteosister/GitElephant) [![Dependency Status](https://www.versioneye.com/user/projects/53da38094b3ac86052000019/badge.svg?style=flat)](https://www.versioneye.com/user/projects/53da38094b3ac86052000019) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/matteosister/GitElephant/badges/quality-score.png?s=c7ca8a7c5ea9c64b291f6bcaef27955ed6d8a836)](https://scrutinizer-ci.com/g/matteosister/GitElephant/) [![Code Coverage](https://scrutinizer-ci.com/g/matteosister/GitElephant/badges/coverage.png?s=fd7981a4f57fd639912d1a415e3dd92615ddce51)](https://scrutinizer-ci.com/g/matteosister/GitElephant/) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d6da541e-d928-4f70-868a-dd0b6426a7b5/mini.png)](https://insight.sensiolabs.com/projects/d6da541e-d928-4f70-868a-dd0b6426a7b5)
[![Latest Stable Version](https://poser.pugx.org/cypresslab/GitElephant/v/stable.png)](https://packagist.org/packages/cypresslab/GitElephant)
[![License](https://poser.pugx.org/cypresslab/gitelephant/license.png)](https://packagist.org/packages/cypresslab/gitelephant)
[![Total Downloads](https://poser.pugx.org/cypresslab/GitElephant/downloads.png)](https://packagist.org/packages/cypresslab/GitElephant)
[![Montly Downloads](https://poser.pugx.org/cypresslab/gitelephant/d/monthly.png)](https://packagist.org/packages/cypresslab/gitelephant)

[![Build Status](https://travis-ci.org/matteosister/GitElephant.png?branch=master)](https://travis-ci.org/matteosister/GitElephant)
[![Code Check](https://github.com/matteosister/GitElephant/workflows/.github/workflows/code_checks.yaml/badge.svg)](.github/workflows/code_checks.yaml)
[![Dependency Status](https://www.versioneye.com/user/projects/53da38094b3ac86052000019/badge.svg?style=flat)](https://www.versioneye.com/user/projects/53da38094b3ac86052000019)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/matteosister/GitElephant/badges/quality-score.png?s=c7ca8a7c5ea9c64b291f6bcaef27955ed6d8a836)](https://scrutinizer-ci.com/g/matteosister/GitElephant/)
[![Code Coverage](https://scrutinizer-ci.com/g/matteosister/GitElephant/badges/coverage.png?s=fd7981a4f57fd639912d1a415e3dd92615ddce51)](https://scrutinizer-ci.com/g/matteosister/GitElephant/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d6da541e-d928-4f70-868a-dd0b6426a7b5/mini.png)](https://insight.sensiolabs.com/projects/d6da541e-d928-4f70-868a-dd0b6426a7b5)

GitElephant is an abstraction layer to manage your git repositories with php

Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
],
"require": {
"php": ">=7.2.0",
"symfony/process": "~2.8|~3.0|~4.0|~5.0",
"symfony/filesystem": "~2.8|~3.0|~4.0|~5.0",
"symfony/finder": "~2.8|~3.0|~4.0|~5.0",
"phpcollection/phpcollection": "~0.4|~5.0"
"symfony/process": "~3.4|~4.0|~5.0",
"symfony/filesystem": "~3.4|~4.0|~5.0",
"symfony/finder": "~3.4|~4.0|~5.0",
"phpcollection/phpcollection": "~0.4|~0.5"
},
"require-dev": {
"php": ">=7.2.0",
"phpunit/phpunit": "~8.0|~9.0",
"mockery/mockery": "~1.1",
"symfony/var-dumper": "~3.0|~4.0|~5.0",
"rector/rector": "^0.7.6",
"symplify/easy-coding-standard": "^v7.2.5"
"rector/rector": "*",
"symplify/easy-coding-standard": "*",
"phpstan/phpstan": "*",
"phpstan/phpstan-phpunit": "*"
},
"minimum-stability": "stable",
"autoload": {
Expand Down
20 changes: 20 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
level: 6
paths:
- src
# - tests

# things we disable for the moement, but one day...
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
-
message: '#Unsafe usage of new static\(\).#'
path: %currentWorkingDirectory%
-
message: '#Parameter \#1 \$command of class Symfony\\Component\\Process\\Process constructor expects array, string given.#'
path: src/GitElephant/Command/Caller/Caller.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
24 changes: 16 additions & 8 deletions src/GitElephant/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BaseCommand
/**
* the command name
*
* @var string
* @var string|null
*/
private $commandName = null;

Expand Down Expand Up @@ -77,31 +77,31 @@ class BaseCommand
/**
* the command subject
*
* @var string|SubCommandCommand
* @var string|SubCommandCommand|null
*/
private $commandSubject = null;

/**
* the command second subject (i.e. for branch)
*
* @var string|SubCommandCommand
* @var string|SubCommandCommand|null
*/
private $commandSubject2 = null;

/**
* the path
*
* @var string
* @var string|null
*/
private $path = null;

/**
* @var string
* @var string|null
*/
private $binaryVersion;

/**
* @var Repository
* @var Repository|null
*/
private $repo;

Expand Down Expand Up @@ -143,6 +143,12 @@ public function clearAll(): void
$this->binaryVersion = null;
}

/**
* Get a new instance of this command
*
* @param Repository $repo
* @return static
*/
public static function getInstance(Repository $repo = null)
{
return new static($repo);
Expand All @@ -153,7 +159,7 @@ public static function getInstance(Repository $repo = null)
*
* @param string $commandName the command name
*/
protected function addCommandName($commandName): void
protected function addCommandName(string $commandName): void
{
$this->commandName = $commandName;
}
Expand Down Expand Up @@ -456,9 +462,11 @@ private function getCLISubjects(): string
}

/**
* Get the version of the git binary
*
* @return string|null
*/
public function getBinaryVersion(): string
public function getBinaryVersion(): ?string
{
if (is_null($this->binaryVersion)) {
$this->binaryVersion = $this->repo->getCaller()->getBinaryVersion();
Expand Down
21 changes: 19 additions & 2 deletions src/GitElephant/Command/Caller/AbstractCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ abstract class AbstractCaller implements CallerInterface
/**
* Git binary path
*
* @var string
* @var string|null
*/
protected $binaryPath;

/**
* Git binary version
*
* @var string
* @var string|null
*/
protected $binaryVersion;

Expand All @@ -48,6 +48,13 @@ abstract class AbstractCaller implements CallerInterface
*/
protected $outputLines = [];

/**
* raw output of the command
*
* @var string
*/
protected $rawOutput;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -117,4 +124,14 @@ public function getOutputLines(bool $stripBlankLines = false): array

return $this->outputLines;
}

/**
* Get RawOutput
*
* @return string
*/
public function getRawOutput(): string
{
return $this->rawOutput;
}
}
7 changes: 0 additions & 7 deletions src/GitElephant/Command/Caller/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class Caller extends AbstractCaller
*/
private $repositoryPath;

/**
* raw output
*
* @var string
*/
private $rawOutput;

/**
* Class constructor
*
Expand Down
24 changes: 22 additions & 2 deletions src/GitElephant/Command/Caller/CallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,37 @@ interface CallerInterface
*
* @return CallerInterface
*/
public function execute(string $cmd, bool $git = true, string $cwd = null): CallerInterface;
public function execute(
string $cmd,
bool $git = true,
string $cwd = null
): CallerInterface;

/**
* after calling execute this method should return the output
*
* @param bool $stripBlankLines strips the blank lines
*
* @return array
* @return array<string>
*/
public function getOutputLines(bool $stripBlankLines = false): array;

/**
* Returns the output of the last executed command.
* May be adjusted, such as trimmed.
*
* @return string
*/
public function getOutput(): string;

/**
* Returns the output of the last executed command.
* May not be adjusted, not trimmed or anything, really raw.
*
* @return string
*/
public function getRawOutput(): string;

/**
* Get the binary path
*
Expand Down
13 changes: 9 additions & 4 deletions src/GitElephant/Command/Caller/CallerSSH2.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,22 @@ public function __construct($resource, $gitPath = '/usr/bin/git')
*
* @return CallerInterface
*/
public function execute($cmd, $git = true, $cwd = null): \GitElephant\Command\Caller\CallerInterface
{
public function execute(
$cmd,
$git = true,
$cwd = null
): \GitElephant\Command\Caller\CallerInterface {
if ($git) {
$cmd = $this->getBinaryPath() . ' ' . $cmd;
}
$stream = ssh2_exec($this->resource, $cmd);
stream_set_blocking($stream, 1);
stream_set_blocking($stream, true);
$data = stream_get_contents($stream);
fclose($stream);

$this->rawOutput = $data === false ? '' : $data;
// rtrim values
$values = array_map('rtrim', explode(PHP_EOL, $data));
$values = array_map('rtrim', explode(PHP_EOL, $this->rawOutput));
$this->outputLines = $values;

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/GitElephant/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(Repository $repo = null)
*
* @param TreeishInterface $of the reference to diff
* @param TreeishInterface|null $with the source reference to diff with $of, if not specified is the current HEAD
* @param null $path the path to diff, if not specified the full repository
* @param string|null $path the path to diff, if not specified the full repository
*
* @throws \RuntimeException
* @return string
Expand Down Expand Up @@ -83,7 +83,7 @@ public function diff($of, $with = null, $path = null): string
}
$this->addPath($path);
}

$this->addCommandSubject($subject);

return $this->getCommand();
Expand Down
2 changes: 1 addition & 1 deletion src/GitElephant/Command/LsTreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function fullTree($ref = 'HEAD'): string
/**
* tree of a given path
*
* @param string $ref reference
* @param string|TreeishInterface $ref reference
* @param string|NodeObject $path path
*
* @throws \RuntimeException
Expand Down
Loading

0 comments on commit 58c2c96

Please sign in to comment.