diff --git a/.check-author.yml b/.check-author.yml index b381930..f360b1b 100644 --- a/.check-author.yml +++ b/.check-author.yml @@ -1,3 +1,4 @@ mapping: Tristan Lins : Tristan Lins David Molineus : David Molineus + Ahmad Marzouq : ahmad-marzouq diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml new file mode 100644 index 0000000..9952d42 --- /dev/null +++ b/.github/workflows/diagnostics.yml @@ -0,0 +1,48 @@ +name: Git php + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php: [5.6, 7.1, 7.2, 7.3, 7.4] + + steps: + - name: PHP ${{ matrix.php }} Pull source + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # see https://github.com/shivammathur/setup-php + - name: PHP ${{ matrix.php }} Setup PHP. + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: PHP ${{ matrix.php }} Cache composer cache directory + uses: actions/cache@v1 + env: + cache-name: composer-cache-dir + with: + path: ~/.cache/composer + key: ${{ runner.os }}-build-${{ env.cache-name }} + + - name: PHP ${{ matrix.php }} Cache vendor directory + uses: actions/cache@v1 + env: + cache-name: composer-vendor + with: + path: vendor + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + - name: PHP ${{ matrix.php }} Install composer dependencies + run: composer update --prefer-dist --no-interaction --no-suggest + + - name: PHP ${{ matrix.php }} Run tests + run: ant -keep-going diff --git a/.gitignore b/.gitignore index 47cde99..d870bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # composer related /vendor/ /composer.phar +/composer.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fb84704..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: php - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - -sudo: false - -install: - - travis_retry composer self-update && composer --version - - travis_retry composer update --prefer-dist --dev --no-interaction - -script: ant -keep-going - -# Hack to make things work again - we can not use a shallow repository. -git: - depth: 2147483647 diff --git a/README.md b/README.md index 9c7be21..cddc204 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -[![Version](http://img.shields.io/packagist/v/bit3/git-php.svg?style=flat-square)](https://packagist.org/packages/bit3/git-php) -[![Stable Build Status](http://img.shields.io/travis/bit3/git-php/master.svg?style=flat-square&label=stable build)](https://travis-ci.org/bit3/git-php) -[![Upstream Build Status](http://img.shields.io/travis/bit3/git-php/develop.svg?style=flat-square&label=dev build)](https://travis-ci.org/bit3/git-php) -[![License](http://img.shields.io/packagist/l/bit3/git-php.svg?style=flat-square)](https://github.com/bit3/git-php/blob/master/LICENSE) -[![Downloads](http://img.shields.io/packagist/dt/bit3/git-php.svg?style=flat-square)](https://packagist.org/packages/bit3/git-php) +[![Build Status](https://github.com/bit3/git-php/actions/workflows/diagnostics.yml/badge.svg)](https://github.com/bit3/git-php/actions) +[![Latest Version tagged](http://img.shields.io/github/tag/bit3/git-php.svg)](https://github.com/bit3/git-php/tags) +[![Latest Version on Packagist](http://img.shields.io/packagist/v/bit3/git-php.svg)](https://packagist.org/packages/bit3/git-php) +[![Installations via composer per month](http://img.shields.io/packagist/dm/bit3/git-php.svg)](https://packagist.org/packages/bit3/git-php) Easy to use GIT wrapper for php =============================== diff --git a/build.xml b/build.xml index 295be32..daac69b 100644 --- a/build.xml +++ b/build.xml @@ -1,21 +1,12 @@ - - - - - - - - + + diff --git a/composer.json b/composer.json index 91f1162..bdb4c38 100644 --- a/composer.json +++ b/composer.json @@ -3,15 +3,14 @@ "description": "Easy to use GIT wrapper for PHP.", "license": "MIT", "require": { - "php": ">=5.3", - "bit3/no-op-logger": "~1.0", - "symfony/process": "~2.3" + "php": "^5.6 || ^7.0", + "psr/log": "^1.0", + "symfony/process": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { - "monolog/monolog": "~1.0", - "phpunit/phpunit": "3.7.*", - "symfony/filesystem": "~2.3", - "phpcq/all-tasks": "~1.0" + "symfony/filesystem": "^3.4 || ^4.0 || ^5.0", + "phpcq/all-tasks": "^1.1", + "phpunit/phpunit": "^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { @@ -19,12 +18,9 @@ "Bit3\\GitPhp\\Test\\": "tests" } }, - "minimum-stability": "dev", - "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "1.2.x-dev", - "dev-develop": "1.3.x-dev" + "dev-master": "1.5.x-dev" } } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 460b2cb..0000000 --- a/composer.lock +++ /dev/null @@ -1,1898 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "5df1bc1118ecfab16f9be46df3566e27", - "packages": [ - { - "name": "bit3/no-op-logger", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/bit3/no-op-logger.git", - "reference": "e659e85674a1d584a937e5d113c49083e4a2933b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/bit3/no-op-logger/zipball/e659e85674a1d584a937e5d113c49083e4a2933b", - "reference": "e659e85674a1d584a937e5d113c49083e4a2933b", - "shasum": "" - }, - "require": { - "psr/log": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Bit3\\NoOpLogger\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "A no-operation PSR-3 logger.", - "time": "2014-12-29 15:01:01" - }, - { - "name": "psr/log", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", - "shasum": "" - }, - "type": "library", - "autoload": { - "psr-0": { - "Psr\\Log\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2012-12-21 11:40:51" - }, - { - "name": "symfony/process", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Process.git", - "reference": "48aeb0e48600321c272955132d7606ab0a49adb3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/48aeb0e48600321c272955132d7606ab0a49adb3", - "reference": "48aeb0e48600321c272955132d7606ab0a49adb3", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2015-07-01 11:25:50" - } - ], - "packages-dev": [ - { - "name": "monolog/monolog", - "version": "1.15.0", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/monolog.git", - "reference": "dc5150cc608f2334c72c3b6a553ec9668a4156b0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/dc5150cc608f2334c72c3b6a553ec9668a4156b0", - "reference": "dc5150cc608f2334c72c3b6a553ec9668a4156b0", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/log": "~1.0" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "aws/aws-sdk-php": "^2.4.9", - "doctrine/couchdb": "~1.0@dev", - "graylog2/gelf-php": "~1.0", - "php-console/php-console": "^3.1.3", - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "2.3.0", - "raven/raven": "~0.8", - "ruflin/elastica": ">=0.90 <3.0", - "swiftmailer/swiftmailer": "~5.3", - "videlalvaro/php-amqplib": "~2.4" - }, - "suggest": { - "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", - "doctrine/couchdb": "Allow sending log messages to a CouchDB server", - "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", - "ext-mongo": "Allow sending log messages to a MongoDB server", - "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "php-console/php-console": "Allow sending log messages to Google Chrome", - "raven/raven": "Allow sending log messages to a Sentry server", - "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server", - "videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.15.x-dev" - } - }, - "autoload": { - "psr-4": { - "Monolog\\": "src/Monolog" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Sends your logs to files, sockets, inboxes, databases and various web services", - "homepage": "http://github.com/Seldaek/monolog", - "keywords": [ - "log", - "logging", - "psr-3" - ], - "time": "2015-07-12 13:54:09" - }, - { - "name": "pdepend/pdepend", - "version": "2.0.6", - "source": { - "type": "git", - "url": "https://github.com/pdepend/pdepend.git", - "reference": "a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/pdepend/pdepend/zipball/a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4", - "reference": "a15ffcbfbcc4570d4a733ca7b76e9cac0a56c3f4", - "shasum": "" - }, - "require": { - "symfony/config": ">=2.4", - "symfony/dependency-injection": ">=2.4", - "symfony/filesystem": ">=2.4" - }, - "require-dev": { - "phpunit/phpunit": "4.*@stable", - "squizlabs/php_codesniffer": "@stable" - }, - "bin": [ - "src/bin/pdepend" - ], - "type": "library", - "autoload": { - "psr-0": { - "PDepend\\": "src/main/php/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Official version of pdepend to be handled with Composer", - "time": "2015-03-02 08:06:43" - }, - { - "name": "phpcq/all-tasks", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpcq/all-tasks.git", - "reference": "71a29b47bb83279a1b478ad3d4439a6a645f9e61" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/all-tasks/zipball/71a29b47bb83279a1b478ad3d4439a6a645f9e61", - "reference": "71a29b47bb83279a1b478ad3d4439a6a645f9e61", - "shasum": "" - }, - "require": { - "bit3/git-php": "~1.0", - "pdepend/pdepend": "2.0.*", - "phpcq/author-validation": "~1.0", - "phpcq/autoload-validation": "~1.0", - "phpcq/branch-alias-validation": "~1.0", - "phpcq/coding-standard": "~1.0", - "phpcq/phpcq": "~1.0", - "phpcq/travis-configuration-check": "~1.0", - "phploc/phploc": "~2.0", - "phpmd/phpmd": "~2.0", - "phpunit/phpunit": "~3.7", - "sebastian/phpcpd": "~1.4", - "squizlabs/php_codesniffer": "~1.0" - }, - "type": "metapackage", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "Meta package to enable all tasks of the PHP code quality project", - "time": "2015-01-11 21:57:07" - }, - { - "name": "phpcq/author-validation", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/phpcq/author-validation.git", - "reference": "c0847ed86df5b86a04be4494f785f691039c64e2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/author-validation/zipball/c0847ed86df5b86a04be4494f785f691039c64e2", - "reference": "c0847ed86df5b86a04be4494f785f691039c64e2", - "shasum": "" - }, - "require": { - "bit3/git-php": "~1.0", - "php": ">=5.3.4", - "phpspec/php-diff": "~1.0", - "symfony/console": "~2.3", - "symfony/finder": "~2.3" - }, - "require-dev": { - "phpcq/all-tasks": "~1.0", - "phpcq/coding-standard": "~1.0" - }, - "bin": [ - "bin/check-author.php" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PhpCodeQuality\\AuthorValidation\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "Check if all authors of a particular file are mentioned in the copyright header.", - "time": "2015-08-01 01:09:23" - }, - { - "name": "phpcq/autoload-validation", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/phpcq/autoload-validation.git", - "reference": "9a8a3580058a9cb40d2f629b47d47e67d201a117" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/autoload-validation/zipball/9a8a3580058a9cb40d2f629b47d47e67d201a117", - "reference": "9a8a3580058a9cb40d2f629b47d47e67d201a117", - "shasum": "" - }, - "require": { - "php": ">=5.3.4", - "symfony/console": "~2.3" - }, - "require-dev": { - "phpcq/all-tasks": "~1.0", - "phpcq/coding-standard": "~1.0" - }, - "bin": [ - "bin/check-autoloading.php" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PhpCodeQuality\\AutoloadValidation\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "Check that the contents of the composer.json autoload keys are correct.", - "time": "2015-08-05 18:24:57" - }, - { - "name": "phpcq/branch-alias-validation", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpcq/branch-alias-validation.git", - "reference": "f6a9cfdf65d7021acceaf05b646d9ab6247668b6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/branch-alias-validation/zipball/f6a9cfdf65d7021acceaf05b646d9ab6247668b6", - "reference": "f6a9cfdf65d7021acceaf05b646d9ab6247668b6", - "shasum": "" - }, - "require": { - "bit3/git-php": "~1.0", - "php": ">=5.3.4", - "symfony/console": "~2.3" - }, - "require-dev": { - "phpcq/all-tasks": "~1.0" - }, - "bin": [ - "bin/validate-branch-alias.php" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PhpCodeQuality\\BranchAliasValidation\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "Validation tool to ensure that all branches are ahead of the most recent tag.", - "time": "2015-01-11 22:01:58" - }, - { - "name": "phpcq/coding-standard", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpcq/coding-standard.git", - "reference": "35ce5b6979303cf6ede530f846d3a3d2cafdec03" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/coding-standard/zipball/35ce5b6979303cf6ede530f846d3a3d2cafdec03", - "reference": "35ce5b6979303cf6ede530f846d3a3d2cafdec03", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "require-dev": { - "phpunit/phpunit": "~3.7", - "squizlabs/php_codesniffer": "~1.0" - }, - "suggest": { - "phpcq/phpcq": "The PHP code quality project core tasks." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause and MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "PHP code quality project coding standard", - "homepage": "http://phpcq.org/", - "time": "2015-01-11 22:02:20" - }, - { - "name": "phpcq/phpcq", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpcq/phpcq.git", - "reference": "8d5c82e0defaea1b790b352db8205a0396d30bec" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/phpcq/zipball/8d5c82e0defaea1b790b352db8205a0396d30bec", - "reference": "8d5c82e0defaea1b790b352db8205a0396d30bec", - "shasum": "" - }, - "suggest": { - "pdepend/pdepend": "Enable the pdepend task (suggested version: ~2.0)", - "phpcq/author-validation": "Enable the author-validation task (suggested version: ~1.0)", - "phpcq/branch-alias-validation": "Enable the branch-alias-validation task (suggested version: ~1.0)", - "phpcq/travis-configuration-check": "Enable the travis-configuration-check task (suggested version: ~1.0)", - "phploc/phploc": "Enable the phploc task (suggested version: ~2.0)", - "phpmd/phpmd": "Enable the phpmd task (suggested version: ~2.0)", - "phpunit/phpunit": "Enable the phpunit task (suggested version: ~3.7).", - "sebastian/phpcpd": "Enable the phpcpd task (suggested version: ~1.4).", - "squizlabs/php_codesniffer": "Enable the phpcs task (suggested version: ~1.0)" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://cyberspectrum.de", - "role": "lead" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.de", - "homepage": "https://tristan.lins.io", - "role": "lead" - } - ], - "description": "PHP code quality project.", - "time": "2015-01-11 22:03:34" - }, - { - "name": "phpcq/travis-configuration-check", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpcq/travis-configuration-check.git", - "reference": "0290b7fa561bdc6ef34ed08f5e86c9aa8b4e5a14" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpcq/travis-configuration-check/zipball/0290b7fa561bdc6ef34ed08f5e86c9aa8b4e5a14", - "reference": "0290b7fa561bdc6ef34ed08f5e86c9aa8b4e5a14", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "symfony/console": "~2.3", - "symfony/yaml": "~2.3" - }, - "require-dev": { - "pdepend/pdepend": "1.1.*", - "phpcq/branch-alias-validation": "~1.0", - "phpcq/coding-standard": "~1.0", - "phpcq/phpcq": "~1.0", - "phpunit/phpunit": ">=3.7.10,<4-dev", - "squizlabs/php_codesniffer": "*" - }, - "bin": [ - "bin/check-travis-configuration.php" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PhpCodeQuality\\TravisConfigurationCheck\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Schiffler", - "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", - "role": "Developer" - }, - { - "name": "Tristan Lins", - "email": "tristan@lins.io", - "homepage": "https://tristan.lins.io", - "role": "Developer" - } - ], - "description": "Validation tool to ensure that the contents of a .travis.yml make sense.", - "time": "2015-01-11 22:03:52" - }, - { - "name": "phploc/phploc", - "version": "2.1.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phploc.git", - "reference": "6cdf01336c06d20825831fe8cee70764fe373585" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phploc/zipball/6cdf01336c06d20825831fe8cee70764fe373585", - "reference": "6cdf01336c06d20825831fe8cee70764fe373585", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/finder-facade": "~1.1", - "sebastian/git": "~2.0", - "sebastian/version": "~1.0.3", - "symfony/console": "~2.5" - }, - "require-dev": { - "phpunit/phpunit": "~4" - }, - "bin": [ - "phploc" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "A tool for quickly measuring the size of a PHP project.", - "homepage": "https://github.com/sebastianbergmann/phploc", - "time": "2015-08-04 07:41:00" - }, - { - "name": "phpmd/phpmd", - "version": "2.2.3", - "source": { - "type": "git", - "url": "https://github.com/phpmd/phpmd.git", - "reference": "5eeb5a4d39c8304910b33ae49f8813905346cc35" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpmd/phpmd/zipball/5eeb5a4d39c8304910b33ae49f8813905346cc35", - "reference": "5eeb5a4d39c8304910b33ae49f8813905346cc35", - "shasum": "" - }, - "require": { - "pdepend/pdepend": "~2.0", - "php": ">=5.3.0", - "symfony/config": ">=2.4", - "symfony/dependency-injection": ">=2.4", - "symfony/filesystem": ">=2.4" - }, - "require-dev": { - "phpunit/phpunit": "*", - "squizlabs/php_codesniffer": "*" - }, - "bin": [ - "src/bin/phpmd" - ], - "type": "project", - "autoload": { - "psr-0": { - "PHPMD\\": "src/main/php" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Manuel Pichler", - "email": "github@manuel-pichler.de", - "homepage": "https://github.com/manuelpichler", - "role": "Project founder" - }, - { - "name": "Other contributors", - "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", - "role": "Contributors" - } - ], - "description": "PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.", - "homepage": "http://phpmd.org/", - "keywords": [ - "mess detection", - "mess detector", - "pdepend", - "phpmd", - "pmd" - ], - "time": "2015-05-27 18:16:57" - }, - { - "name": "phpspec/php-diff", - "version": "v1.0.2", - "source": { - "type": "git", - "url": "https://github.com/phpspec/php-diff.git", - "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/php-diff/zipball/30e103d19519fe678ae64a60d77884ef3d71b28a", - "reference": "30e103d19519fe678ae64a60d77884ef3d71b28a", - "shasum": "" - }, - "type": "library", - "autoload": { - "psr-0": { - "Diff": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Chris Boulton", - "homepage": "http://github.com/chrisboulton", - "role": "Original developer" - } - ], - "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", - "time": "2013-11-01 13:02:21" - }, - { - "name": "phpunit/php-code-coverage", - "version": "1.2.18", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b", - "reference": "fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.0@stable", - "phpunit/php-text-template": ">=1.2.0@stable", - "phpunit/php-token-stream": ">=1.1.3,<1.3.0" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*@dev" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.0.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2014-09-02 10:13:14" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2015-06-21 13:08:43" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21 13:50:34" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.7", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2015-06-21 08:01:12" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/ad4e1e23ae01b483c16f600ff1bebec184588e32", - "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2014-03-03 05:10:30" - }, - { - "name": "phpunit/phpunit", - "version": "3.7.38", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/38709dc22d519a3d1be46849868aa2ddf822bcf6", - "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpunit/php-code-coverage": "~1.2", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.1", - "phpunit/php-timer": "~1.0", - "phpunit/phpunit-mock-objects": "~1.2", - "symfony/yaml": "~2.0" - }, - "require-dev": { - "pear-pear.php.net/pear": "1.9.4" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "composer/bin/phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.7.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "", - "../../symfony/yaml/" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2014-10-17 09:04:17" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "1.2.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-text-template": ">=1.1.1@stable" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2013-01-13 10:24:48" - }, - { - "name": "sebastian/finder-facade", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/finder-facade.git", - "reference": "a520dcc3dd39160eea480daa3426f4fd419a327b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/finder-facade/zipball/a520dcc3dd39160eea480daa3426f4fd419a327b", - "reference": "a520dcc3dd39160eea480daa3426f4fd419a327b", - "shasum": "" - }, - "require": { - "symfony/finder": "~2.3", - "theseer/fdomdocument": "~1.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "FinderFacade is a convenience wrapper for Symfony's Finder component.", - "homepage": "https://github.com/sebastianbergmann/finder-facade", - "time": "2015-06-04 08:11:58" - }, - { - "name": "sebastian/git", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/git.git", - "reference": "2d5c139d0eedcb9e67e0e9ca08023be6e9b7b47b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/git/zipball/2d5c139d0eedcb9e67e0e9ca08023be6e9b7b47b", - "reference": "2d5c139d0eedcb9e67e0e9ca08023be6e9b7b47b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Simple wrapper for Git", - "homepage": "http://www.github.com/sebastianbergmann/git", - "keywords": [ - "git" - ], - "time": "2015-04-06 16:23:43" - }, - { - "name": "sebastian/phpcpd", - "version": "1.4.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpcpd.git", - "reference": "090575dbd6486bff545a7426f98e988c8c597c1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpcpd/zipball/090575dbd6486bff545a7426f98e988c8c597c1b", - "reference": "090575dbd6486bff545a7426f98e988c8c597c1b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-timer": ">=1.0.4,<1.1.0", - "sebastian/finder-facade": "~1.1", - "sebastian/version": ">=1.0.0", - "symfony/finder": ">=2.1.2", - "theseer/fdomdocument": "~1.4", - "zetacomponents/base": ">=1.8", - "zetacomponents/console-tools": ">=1.6" - }, - "bin": [ - "composer/bin/phpcpd" - ], - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Copy/Paste Detector (CPD) for PHP code.", - "homepage": "https://github.com/sebastianbergmann/phpcpd", - "time": "2013-07-30 14:37:42" - }, - { - "name": "sebastian/version", - "version": "1.0.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "1.5.6", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6f3e42d311b882b25b4d409d23a289f4d3b803d5", - "reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.1.2" - }, - "suggest": { - "phpunit/php-timer": "dev-master" - }, - "bin": [ - "scripts/phpcs" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-phpcs-fixer": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/CommentParser/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2014-12-04 22:32:15" - }, - { - "name": "symfony/config", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Config.git", - "reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/6c905bbed1e728226de656e4c07d620dfe9e80d9", - "reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9", - "shasum": "" - }, - "require": { - "php": ">=5.3.9", - "symfony/filesystem": "~2.3" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Config\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Config Component", - "homepage": "https://symfony.com", - "time": "2015-07-09 16:07:40" - }, - { - "name": "symfony/console", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Console.git", - "reference": "d6cf02fe73634c96677e428f840704bfbcaec29e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/d6cf02fe73634c96677e428f840704bfbcaec29e", - "reference": "d6cf02fe73634c96677e428f840704bfbcaec29e", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.1", - "symfony/phpunit-bridge": "~2.7", - "symfony/process": "~2.1" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "https://symfony.com", - "time": "2015-07-28 15:18:12" - }, - { - "name": "symfony/dependency-injection", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/DependencyInjection.git", - "reference": "851e3ffe8a366b1590bdaf3df2c1395f2d27d8a6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/851e3ffe8a366b1590bdaf3df2c1395f2d27d8a6", - "reference": "851e3ffe8a366b1590bdaf3df2c1395f2d27d8a6", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "conflict": { - "symfony/expression-language": "<2.6" - }, - "require-dev": { - "symfony/config": "~2.2", - "symfony/expression-language": "~2.6", - "symfony/phpunit-bridge": "~2.7", - "symfony/yaml": "~2.1" - }, - "suggest": { - "symfony/config": "", - "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\DependencyInjection\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony DependencyInjection Component", - "homepage": "https://symfony.com", - "time": "2015-07-28 14:07:07" - }, - { - "name": "symfony/filesystem", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Filesystem.git", - "reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/2d7b2ddaf3f548f4292df49a99d19c853d43f0b8", - "reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Filesystem Component", - "homepage": "https://symfony.com", - "time": "2015-07-09 16:07:40" - }, - { - "name": "symfony/finder", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Finder.git", - "reference": "ae0f363277485094edc04c9f3cbe595b183b78e4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/ae0f363277485094edc04c9f3cbe595b183b78e4", - "reference": "ae0f363277485094edc04c9f3cbe595b183b78e4", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Finder Component", - "homepage": "https://symfony.com", - "time": "2015-07-09 16:07:40" - }, - { - "name": "symfony/yaml", - "version": "v2.7.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "71340e996171474a53f3d29111d046be4ad8a0ff" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/71340e996171474a53f3d29111d046be4ad8a0ff", - "reference": "71340e996171474a53f3d29111d046be4ad8a0ff", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2015-07-28 14:07:07" - }, - { - "name": "theseer/fdomdocument", - "version": "1.6.1", - "source": { - "type": "git", - "url": "https://github.com/theseer/fDOMDocument.git", - "reference": "d9ad139d6c2e8edf5e313ffbe37ff13344cf0684" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theseer/fDOMDocument/zipball/d9ad139d6c2e8edf5e313ffbe37ff13344cf0684", - "reference": "d9ad139d6c2e8edf5e313ffbe37ff13344cf0684", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "lib-libxml": "*", - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "lead" - } - ], - "description": "The classes contained within this repository extend the standard DOM to use exceptions at all occasions of errors instead of PHP warnings or notices. They also add various custom methods and shortcuts for convenience and to simplify the usage of DOM.", - "homepage": "https://github.com/theseer/fDOMDocument", - "time": "2015-05-27 22:58:02" - }, - { - "name": "zetacomponents/base", - "version": "1.9", - "source": { - "type": "git", - "url": "https://github.com/zetacomponents/Base.git", - "reference": "f20df24e8de3e48b6b69b2503f917e457281e687" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zetacomponents/Base/zipball/f20df24e8de3e48b6b69b2503f917e457281e687", - "reference": "f20df24e8de3e48b6b69b2503f917e457281e687", - "shasum": "" - }, - "require-dev": { - "zetacomponents/unit-test": "*" - }, - "type": "library", - "autoload": { - "classmap": [ - "src" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Sergey Alexeev" - }, - { - "name": "Sebastian Bergmann" - }, - { - "name": "Jan Borsodi" - }, - { - "name": "Raymond Bosman" - }, - { - "name": "Frederik Holljen" - }, - { - "name": "Kore Nordmann" - }, - { - "name": "Derick Rethans" - }, - { - "name": "Vadym Savchuk" - }, - { - "name": "Tobias Schlitt" - }, - { - "name": "Alexandru Stanoi" - } - ], - "description": "The Base package provides the basic infrastructure that all packages rely on. Therefore every component relies on this package.", - "homepage": "https://github.com/zetacomponents", - "time": "2014-09-19 03:28:34" - }, - { - "name": "zetacomponents/console-tools", - "version": "1.7", - "source": { - "type": "git", - "url": "https://github.com/zetacomponents/ConsoleTools.git", - "reference": "30d67e9d04f458ac8cae4c49e50f81061460ff2c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zetacomponents/ConsoleTools/zipball/30d67e9d04f458ac8cae4c49e50f81061460ff2c", - "reference": "30d67e9d04f458ac8cae4c49e50f81061460ff2c", - "shasum": "" - }, - "require": { - "zetacomponents/base": "~1.8" - }, - "require-dev": { - "zetacomponents/unit-test": "*" - }, - "type": "library", - "autoload": { - "classmap": [ - "src" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Sergey Alexeev" - }, - { - "name": "Sebastian Bergmann" - }, - { - "name": "Jan Borsodi" - }, - { - "name": "Raymond Bosman" - }, - { - "name": "Frederik Holljen" - }, - { - "name": "Kore Nordmann" - }, - { - "name": "Derick Rethans" - }, - { - "name": "Vadym Savchuk" - }, - { - "name": "Tobias Schlitt" - }, - { - "name": "Alexandru Stanoi" - } - ], - "description": "A set of classes to do different actions with the console (also called shell). It can render a progress bar, tables and a status bar and contains a class for parsing command line options.", - "homepage": "https://github.com/zetacomponents", - "time": "2014-09-27 19:26:09" - } - ], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], - "prefer-stable": true, - "prefer-lowest": false, - "platform": { - "php": ">=5.3" - }, - "platform-dev": [] -} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d648aef..336c61f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,25 @@ - - + + + forceCoversAnnotation="true" + failOnRisky="true" + failOnWarning="true" + beStrictAboutChangesToGlobalState="true" + beStrictAboutOutputDuringTests="true" + beStrictAboutResourceUsageDuringSmallTests="true" + beStrictAboutTodoAnnotatedTests="true" + bootstrap="vendor/autoload.php" +> - ./tests/ + ./tests - \ No newline at end of file + + + ./src + + + diff --git a/src/Command/AbstractCommandBuilder.php b/src/Command/AbstractCommandBuilder.php index 551af19..0ba22b1 100644 --- a/src/Command/AbstractCommandBuilder.php +++ b/src/Command/AbstractCommandBuilder.php @@ -13,136 +13,23 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ namespace Bit3\GitPhp\Command; -use Bit3\GitPhp\GitException; -use Bit3\GitPhp\GitRepository; -use Symfony\Component\Process\ProcessBuilder; - /** * Abstract command builder. * * @SuppressWarnings(PHPMD.NumberOfChildren) + * + * @deprecated This class is deprecated since 1.5 and where removed in 2.0. Use the trait CommandBuilderTrait. */ abstract class AbstractCommandBuilder implements CommandBuilderInterface { - /** - * The path to the git repository. - * - * @var GitRepository - */ - public $repository; - - /** - * The process builder in use. - * - * @var ProcessBuilder - */ - protected $processBuilder; - - /** - * The process output. - * - * @var null|string - */ - protected $output = null; - - /** - * Flag if we want to dry run. - * - * @var bool - */ - protected $dryRun = false; - - /** - * Constructor. - * - * @param GitRepository $repository The git repository to work on. - */ - public function __construct(GitRepository $repository) - { - $this->repository = $repository; - - $this->processBuilder = new ProcessBuilder(); - $this->processBuilder->setWorkingDirectory($repository->getRepositoryPath()); - $this->processBuilder->add($this->repository->getConfig()->getGitExecutablePath()); - - $this->initializeProcessBuilder(); - } - - /** - * Enable dry run. If dry run is enabled, the execute() method return the executed command. - * - * @return $this - */ - public function enableDryRun() - { - $this->dryRun = true; - return $this; - } - - /** - * Initialize the process builder. - * - * @return void - */ - protected function initializeProcessBuilder() - { - } - - /** - * Retrieve the output text. - * - * @return null|string - */ - public function getOutput() - { - return $this->output; - } - - /** - * Execute the command. - * - * @return mixed Depend on the command. - * - * @throws GitException When the command is executed the second time or could not be executed. - */ - protected function run() - { - $process = $this->processBuilder->getProcess(); - - if ($this->output !== null) { - throw new GitException( - 'Command cannot be executed twice', - $process->getWorkingDirectory(), - $process->getCommandLine(), - $this->output, - '' - ); - } - - $this->repository->getConfig()->getLogger()->debug( - sprintf('[ccabs-repository-git] exec [%s] %s', $process->getWorkingDirectory(), $process->getCommandLine()) - ); - - if ($this->dryRun) { - return $process->getCommandLine(); - } - - $process->run(); - $this->output = $process->getOutput(); - $this->output = rtrim($this->output, "\r\n"); - - if (!$process->isSuccessful()) { - throw GitException::createFromProcess('Could not execute git command', $process); - } - - return $this->output; - } + use CommandBuilderTrait; } diff --git a/src/Command/AddCommandBuilder.php b/src/Command/AddCommandBuilder.php index b8138cb..482abfe 100644 --- a/src/Command/AddCommandBuilder.php +++ b/src/Command/AddCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Add command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class AddCommandBuilder extends AbstractCommandBuilder +class AddCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('add'); + $this->arguments[] = 'add'; } /** @@ -41,7 +46,7 @@ protected function initializeProcessBuilder() */ public function dryRun() { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; return $this; } @@ -52,7 +57,7 @@ public function dryRun() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -63,7 +68,7 @@ public function verbose() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -74,7 +79,7 @@ public function force() */ public function patch() { - $this->processBuilder->add('--patch'); + $this->arguments[] = '--patch'; return $this; } @@ -85,7 +90,7 @@ public function patch() */ public function update() { - $this->processBuilder->add('--update'); + $this->arguments[] = '--update'; return $this; } @@ -96,7 +101,7 @@ public function update() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -107,7 +112,7 @@ public function all() */ public function noAll() { - $this->processBuilder->add('--no-all'); + $this->arguments[] = '--no-all'; return $this; } @@ -118,7 +123,7 @@ public function noAll() */ public function intentToAdd() { - $this->processBuilder->add('--intent-to-add'); + $this->arguments[] = '--intent-to-add'; return $this; } @@ -129,7 +134,7 @@ public function intentToAdd() */ public function refresh() { - $this->processBuilder->add('--refresh'); + $this->arguments[] = '--refresh'; return $this; } @@ -140,7 +145,7 @@ public function refresh() */ public function ignoreErrors() { - $this->processBuilder->add('--ignore-errors'); + $this->arguments[] = '--ignore-errors'; return $this; } @@ -151,7 +156,7 @@ public function ignoreErrors() */ public function ignoreMissing() { - $this->processBuilder->add('--ignore-missing'); + $this->arguments[] = '--ignore-missing'; return $this; } @@ -170,13 +175,13 @@ public function ignoreMissing() */ public function execute($pathspec = null, $_ = null) { - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathspec) { - $this->processBuilder->add($pathspec); + $this->arguments[] = $pathspec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/BranchCommandBuilder.php b/src/Command/BranchCommandBuilder.php index bc5bbad..8f1349a 100644 --- a/src/Command/BranchCommandBuilder.php +++ b/src/Command/BranchCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Branch command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class BranchCommandBuilder extends AbstractCommandBuilder +class BranchCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const WHEN_ALWAYS = 'always'; const WHEN_NEVER = 'never'; @@ -37,7 +42,7 @@ class BranchCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('branch'); + $this->arguments[] = 'branch'; } /** @@ -47,7 +52,7 @@ protected function initializeProcessBuilder() */ public function delete() { - $this->processBuilder->add('-D'); + $this->arguments[] = '-D'; return $this; } @@ -58,7 +63,7 @@ public function delete() */ public function createReflog() { - $this->processBuilder->add('--create-reflog'); + $this->arguments[] = '--create-reflog'; return $this; } @@ -69,7 +74,7 @@ public function createReflog() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -82,9 +87,9 @@ public function force() */ public function move($oldName = false) { - $this->processBuilder->add('-M'); + $this->arguments[] = '-M'; if ($oldName) { - $this->processBuilder->add($oldName); + $this->arguments[] = $oldName; } return $this; } @@ -96,13 +101,13 @@ public function move($oldName = false) * * @return BranchCommandBuilder * - * @see BranchCommandBuilder::WHEN_ALWAYS - * @see BranchCommandBuilder::WHEN_NEVER - * @see BranchCommandBuilder::WHEN_AUTO. + * @see BranchCommandBuilder::WHEN_ALWAYS + * @see BranchCommandBuilder::WHEN_NEVER + * @see BranchCommandBuilder::WHEN_AUTO. */ public function color($when) { - $this->processBuilder->add('--color=' . $when); + $this->arguments[] = '--color=' . $when; return $this; } @@ -113,7 +118,7 @@ public function color($when) */ public function noColor() { - $this->processBuilder->add('--no-color'); + $this->arguments[] = '--no-color'; return $this; } @@ -126,7 +131,7 @@ public function noColor() */ public function column($options = false) { - $this->processBuilder->add('--column' . ($options ? '=' . $options : '')); + $this->arguments[] = '--column' . ($options ? '=' . $options : ''); return $this; } @@ -137,7 +142,7 @@ public function column($options = false) */ public function noColumn() { - $this->processBuilder->add('--no-column'); + $this->arguments[] = '--no-column'; return $this; } @@ -148,7 +153,7 @@ public function noColumn() */ public function remotes() { - $this->processBuilder->add('--remotes'); + $this->arguments[] = '--remotes'; return $this; } @@ -159,7 +164,7 @@ public function remotes() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -170,7 +175,7 @@ public function all() */ public function listBranches() { - $this->processBuilder->add('--list'); + $this->arguments[] = '--list'; return $this; } @@ -181,7 +186,7 @@ public function listBranches() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -192,7 +197,7 @@ public function verbose() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -205,7 +210,7 @@ public function quiet() */ public function abbrev($length) { - $this->processBuilder->add('--abbrev=' . $length); + $this->arguments[] = '--abbrev=' . $length; return $this; } @@ -216,7 +221,7 @@ public function abbrev($length) */ public function noAbbrev() { - $this->processBuilder->add('--no-abbrev'); + $this->arguments[] = '--no-abbrev'; return $this; } @@ -227,7 +232,7 @@ public function noAbbrev() */ public function track() { - $this->processBuilder->add('--track'); + $this->arguments[] = '--track'; return $this; } @@ -238,7 +243,7 @@ public function track() */ public function noTrack() { - $this->processBuilder->add('--no-track'); + $this->arguments[] = '--no-track'; return $this; } @@ -249,7 +254,7 @@ public function noTrack() */ public function setUpstream() { - $this->processBuilder->add('--set-upstream'); + $this->arguments[] = '--set-upstream'; return $this; } @@ -262,7 +267,7 @@ public function setUpstream() */ public function setUpstreamTo($upstream) { - $this->processBuilder->add('--set-upstream-to=' . $upstream); + $this->arguments[] = '--set-upstream-to=' . $upstream; return $this; } @@ -273,7 +278,7 @@ public function setUpstreamTo($upstream) */ public function unsetUpstream() { - $this->processBuilder->add('--unset-upstream'); + $this->arguments[] = '--unset-upstream'; return $this; } @@ -286,7 +291,8 @@ public function unsetUpstream() */ public function contains($commit) { - $this->processBuilder->add('--contains')->add($commit); + $this->arguments[] = '--contains'; + $this->arguments[] = $commit; return $this; } @@ -299,7 +305,8 @@ public function contains($commit) */ public function merged($commit) { - $this->processBuilder->add('--merged')->add($commit); + $this->arguments[] = '--merged'; + $this->arguments[] = $commit; return $this; } @@ -312,7 +319,8 @@ public function merged($commit) */ public function noMerged($commit) { - $this->processBuilder->add('--no-merged')->add($commit); + $this->arguments[] = '--no-merged'; + $this->arguments[] = $commit; return $this; } @@ -326,9 +334,9 @@ public function noMerged($commit) public function execute($branchName = null) { if ($branchName) { - $this->processBuilder->add($branchName); + $this->arguments[] = $branchName; } - return parent::run(); + return $this->run(); } /** @@ -339,15 +347,15 @@ public function execute($branchName = null) public function getNames() { $branches = $this->execute(); - $branches = explode("\n", $branches); - $branches = array_map( + $branches = \explode("\n", $branches); + $branches = \array_map( function ($branch) { - return ltrim($branch, '*'); + return \ltrim($branch, '*'); }, $branches ); - $branches = array_map('trim', $branches); - $branches = array_filter($branches); + $branches = \array_map('trim', $branches); + $branches = \array_filter($branches); return $branches; } diff --git a/src/Command/CheckoutCommandBuilder.php b/src/Command/CheckoutCommandBuilder.php index 26ee601..87fe062 100644 --- a/src/Command/CheckoutCommandBuilder.php +++ b/src/Command/CheckoutCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2022 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Checkout command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class CheckoutCommandBuilder extends AbstractCommandBuilder +class CheckoutCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('checkout'); + $this->arguments[] = 'checkout'; } /** @@ -41,7 +46,7 @@ protected function initializeProcessBuilder() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -52,7 +57,7 @@ public function quiet() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -63,7 +68,7 @@ public function force() */ public function ours() { - $this->processBuilder->add('--ours'); + $this->arguments[] = '--ours'; return $this; } @@ -74,7 +79,7 @@ public function ours() */ public function theirs() { - $this->processBuilder->add('--theirs'); + $this->arguments[] = '--theirs'; return $this; } @@ -85,7 +90,7 @@ public function theirs() */ public function create() { - $this->processBuilder->add('-b'); + $this->arguments[] = '-b'; return $this; } @@ -96,7 +101,7 @@ public function create() */ public function overwrite() { - $this->processBuilder->add('-B'); + $this->arguments[] = '-B'; return $this; } @@ -107,7 +112,7 @@ public function overwrite() */ public function track() { - $this->processBuilder->add('--track'); + $this->arguments[] = '--track'; return $this; } @@ -118,7 +123,7 @@ public function track() */ public function noTrack() { - $this->processBuilder->add('--no-track'); + $this->arguments[] = '--no-track'; return $this; } @@ -129,18 +134,7 @@ public function noTrack() */ public function reflog() { - $this->processBuilder->add('-l'); - return $this; - } - - /** - * Add the detach option to the command line. - * - * @return CheckoutCommandBuilder - */ - public function detach() - { - $this->processBuilder->add('--detach'); + $this->arguments[] = '-l'; return $this; } @@ -153,9 +147,9 @@ public function detach() */ public function orphan($newBranch = null) { - $this->processBuilder->add('--orphan'); + $this->arguments[] = '--orphan'; if ($newBranch) { - $this->processBuilder->add($newBranch); + $this->arguments[] = $newBranch; } return $this; } @@ -167,7 +161,7 @@ public function orphan($newBranch = null) */ public function ignoreSkipWorktreeBits() { - $this->processBuilder->add('--ignore-skip-worktree-bits'); + $this->arguments[] = '--ignore-skip-worktree-bits'; return $this; } @@ -178,7 +172,7 @@ public function ignoreSkipWorktreeBits() */ public function merge() { - $this->processBuilder->add('--merge'); + $this->arguments[] = '--merge'; return $this; } @@ -191,7 +185,7 @@ public function merge() */ public function conflict($style) { - $this->processBuilder->add('--conflict=' . $style); + $this->arguments[] = '--conflict=' . $style; return $this; } @@ -202,7 +196,7 @@ public function conflict($style) */ public function patch() { - $this->processBuilder->add('--patch'); + $this->arguments[] = '--patch'; return $this; } @@ -211,7 +205,7 @@ public function patch() * * @param null|string $branchOrTreeIsh Name of the branch or tree. * - * @param null| $path Path to which check out. + * @param null $path Path to which check out. * * @param null|string $_ More optional arguments to append to the command. * @@ -224,18 +218,18 @@ public function patch() public function execute($branchOrTreeIsh = null, $path = null, $_ = null) { if ($branchOrTreeIsh) { - $this->processBuilder->add($branchOrTreeIsh); + $this->arguments[] = $branchOrTreeIsh; } - $paths = func_get_args(); - array_shift($paths); - if (count($paths)) { - $this->processBuilder->add('--'); + $paths = \func_get_args(); + \array_shift($paths); + if (\count($paths)) { + $this->arguments[] = '--'; foreach ($paths as $path) { - $this->processBuilder->add($path); + $this->arguments[] = $path; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/CloneCommandBuilder.php b/src/Command/CloneCommandBuilder.php index ae86205..0c021c4 100644 --- a/src/Command/CloneCommandBuilder.php +++ b/src/Command/CloneCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Clone command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class CloneCommandBuilder extends AbstractCommandBuilder +class CloneCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('clone'); + $this->arguments[] = 'clone'; } /** @@ -41,7 +46,7 @@ protected function initializeProcessBuilder() */ public function local() { - $this->processBuilder->add('--local'); + $this->arguments[] = '--local'; return $this; } @@ -52,7 +57,7 @@ public function local() */ public function noHardlinks() { - $this->processBuilder->add('--no-hardlinks'); + $this->arguments[] = '--no-hardlinks'; return $this; } @@ -63,7 +68,7 @@ public function noHardlinks() */ public function shared() { - $this->processBuilder->add('--shared'); + $this->arguments[] = '--shared'; return $this; } @@ -76,7 +81,8 @@ public function shared() */ public function reference($repository) { - $this->processBuilder->add('--reference')->add($repository); + $this->arguments[] = '--reference'; + $this->arguments[] = $repository; return $this; } @@ -87,7 +93,7 @@ public function reference($repository) */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -98,7 +104,7 @@ public function quiet() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -109,7 +115,7 @@ public function verbose() */ public function progress() { - $this->processBuilder->add('--progress'); + $this->arguments[] = '--progress'; return $this; } @@ -120,7 +126,7 @@ public function progress() */ public function noCheckout() { - $this->processBuilder->add('--no-checkout'); + $this->arguments[] = '--no-checkout'; return $this; } @@ -131,7 +137,7 @@ public function noCheckout() */ public function bare() { - $this->processBuilder->add('--bare'); + $this->arguments[] = '--bare'; return $this; } @@ -142,7 +148,7 @@ public function bare() */ public function mirror() { - $this->processBuilder->add('--mirror'); + $this->arguments[] = '--mirror'; return $this; } @@ -155,7 +161,8 @@ public function mirror() */ public function origin($name) { - $this->processBuilder->add('--origin')->add($name); + $this->arguments[] = '--origin'; + $this->arguments[] = $name; return $this; } @@ -168,7 +175,8 @@ public function origin($name) */ public function branch($name) { - $this->processBuilder->add('--branch')->add($name); + $this->arguments[] = '--branch'; + $this->arguments[] = $name; return $this; } @@ -181,7 +189,8 @@ public function branch($name) */ public function uploadPack($uploadPack) { - $this->processBuilder->add('--upload-pack')->add($uploadPack); + $this->arguments[] = '--upload-pack'; + $this->arguments[] = $uploadPack; return $this; } @@ -194,7 +203,7 @@ public function uploadPack($uploadPack) */ public function template($templateDirectory) { - $this->processBuilder->add('--template=' . $templateDirectory); + $this->arguments[] = '--template=' . $templateDirectory; return $this; } @@ -209,20 +218,22 @@ public function template($templateDirectory) */ public function config($key, $value) { - $this->processBuilder->add('--config')->add($key . '=' . $value); + $this->arguments[] = '--config'; + $this->arguments[] = $key . '=' . $value; return $this; } /** * Add the depth option to the command line. * - * @param string $depth The depth. + * @param string $depth The depth.arguments[] = rn CloneCommandBuildr. * * @return CloneCommandBuilder */ public function depth($depth) { - $this->processBuilder->add('--depth')->add($depth); + $this->arguments[] = '--depth'; + $this->arguments[] = $depth; return $this; } @@ -233,7 +244,7 @@ public function depth($depth) */ public function noSingleBranch() { - $this->processBuilder->add('--no-single-branch'); + $this->arguments[] = '--no-single-branch'; return $this; } @@ -244,7 +255,7 @@ public function noSingleBranch() */ public function singleBranch() { - $this->processBuilder->add('--single-branch'); + $this->arguments[] = '--single-branch'; return $this; } @@ -255,7 +266,7 @@ public function singleBranch() */ public function recursive() { - $this->processBuilder->add('--recursive'); + $this->arguments[] = '--recursive'; return $this; } @@ -268,7 +279,7 @@ public function recursive() */ public function separateGitDir($gitDir) { - $this->processBuilder->add('--separate-git-dir=' . $gitDir); + $this->arguments[] = '--separate-git-dir=' . $gitDir; return $this; } @@ -281,8 +292,8 @@ public function separateGitDir($gitDir) */ public function execute($repositoryUrl) { - $this->processBuilder->add($repositoryUrl); - $this->processBuilder->add($this->repository->getRepositoryPath()); - return parent::run(); + $this->arguments[] = $repositoryUrl; + $this->arguments[] = $this->repository->getRepositoryPath(); + return $this->run(); } } diff --git a/src/Command/CommandBuilderInterface.php b/src/Command/CommandBuilderInterface.php index 311a9a2..d16e47f 100644 --- a/src/Command/CommandBuilderInterface.php +++ b/src/Command/CommandBuilderInterface.php @@ -12,9 +12,10 @@ * * @package bit3/git-php * @author Tristan Lins + * @author Christian Schiffler * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ diff --git a/src/Command/CommandBuilderTrait.php b/src/Command/CommandBuilderTrait.php new file mode 100644 index 0000000..c9216b2 --- /dev/null +++ b/src/Command/CommandBuilderTrait.php @@ -0,0 +1,171 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * This project is provided in good faith and hope to be usable by anyone. + * + * @package bit3/git-php + * @author Tristan Lins + * @author Christian Schiffler + * @author Sven Baumann + * @copyright 2014-2022 Tristan Lins + * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php + * @filesource + */ + +namespace Bit3\GitPhp\Command; + +use Bit3\GitPhp\GitException; +use Bit3\GitPhp\GitRepository; +use Symfony\Component\Process\Exception\LogicException; +use Symfony\Component\Process\Process; + +/** + * Abstract command builder. + * + * @SuppressWarnings(PHPMD.NumberOfChildren) + */ +trait CommandBuilderTrait +{ + /** + * The path to the git repository. + * + * @var GitRepository + */ + public $repository; + + /** + * The directory in their the process called. + * + * @var string + */ + protected $workingDirectory; + + /** + * The arguments for the command line process. + * + * @var array + */ + protected $arguments = []; + + /** + * The process output. + * + * @var null|string + */ + protected $output; + + /** + * Flag if we want to dry run. + * + * @var bool + */ + protected $dryRun = false; + + /** + * Constructor. + * + * @param GitRepository $repository The git repository to work on. + */ + public function __construct(GitRepository $repository) + { + $this->repository = $repository; + $this->workingDirectory = $repository->getRepositoryPath(); + $this->arguments[] = $this->repository->getConfig()->getGitExecutablePath(); + + $this->initializeProcessBuilder(); + } + + /** + * Enable dry run. If dry run is enabled, the execute() method return the executed command. + * + * @return $this + */ + public function enableDryRun() + { + $this->dryRun = true; + return $this; + } + + /** + * Initialize the process builder. + * + * @return void + */ + abstract protected function initializeProcessBuilder(); + + /** + * Retrieve the output text. + * + * @return null|string + */ + public function getOutput() + { + return $this->output; + } + + /** + * Build the the command line process. + * + * @return Process + * + * @throws LogicException In case no arguments have been provided. + */ + protected function buildProcess() + { + if (!\count($this->arguments)) { + throw new LogicException('You must add command arguments before the process can build.'); + } + + $process = new Process($this->arguments, $this->workingDirectory); + + return $process; + } + + /** + * Execute the command. + * + * @return mixed Depend on the command. + * + * @throws GitException When the command is executed the second time or could not be executed. + */ + protected function run() + { + $process = $this->buildProcess(); + + if ($this->output !== null) { + throw new GitException( + 'Command cannot be executed twice', + $process->getWorkingDirectory(), + $process->getCommandLine(), + $this->output, + '' + ); + } + + $this->repository->getConfig()->getLogger()->debug( + \sprintf('[ccabs-repository-git] exec [%s] %s', $this->workingDirectory, $process->getCommandLine()) + ); + + if ($this->dryRun) { + return $process->getCommandLine(); + } + + $process->run(); + $this->output = $process->getOutput(); + $this->output = \rtrim($this->output, "\r\n"); + + if (!$process->isSuccessful()) { + throw GitException::createFromProcess('Could not execute git command', $process); + } + + return $this->output; + } +} diff --git a/src/Command/CommitCommandBuilder.php b/src/Command/CommitCommandBuilder.php index 833261f..08d20c2 100644 --- a/src/Command/CommitCommandBuilder.php +++ b/src/Command/CommitCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2022 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Commit command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class CommitCommandBuilder extends AbstractCommandBuilder +class CommitCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const CLEANUP_STRIP = 'strip'; const CLEANUP_WHITESPACE = 'whitespace'; @@ -52,7 +57,7 @@ class CommitCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('commit'); + $this->arguments[] = 'commit'; } /** @@ -62,7 +67,7 @@ protected function initializeProcessBuilder() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -73,7 +78,7 @@ public function all() */ public function patch() { - $this->processBuilder->add('--patch'); + $this->arguments[] = '--patch'; return $this; } @@ -86,7 +91,7 @@ public function patch() */ public function reuseMessage($commit) { - $this->processBuilder->add('--reuse-message=' . $commit); + $this->arguments[] = '--reuse-message=' . $commit; return $this; } @@ -99,7 +104,7 @@ public function reuseMessage($commit) */ public function fixup($commit) { - $this->processBuilder->add('--fixup=' . $commit); + $this->arguments[] = '--fixup=' . $commit; return $this; } @@ -112,7 +117,7 @@ public function fixup($commit) */ public function squash($commit) { - $this->processBuilder->add('--squash=' . $commit); + $this->arguments[] = '--squash=' . $commit; return $this; } @@ -123,7 +128,7 @@ public function squash($commit) */ public function resetAuthor() { - $this->processBuilder->add('--reset-author'); + $this->arguments[] = '--reset-author'; return $this; } @@ -134,7 +139,7 @@ public function resetAuthor() */ public function short() { - $this->processBuilder->add('--short'); + $this->arguments[] = '--short'; return $this; } @@ -145,7 +150,7 @@ public function short() */ public function branch() { - $this->processBuilder->add('--branch'); + $this->arguments[] = '--branch'; return $this; } @@ -156,7 +161,7 @@ public function branch() */ public function porcelain() { - $this->processBuilder->add('--porcelain'); + $this->arguments[] = '--porcelain'; return $this; } @@ -167,7 +172,7 @@ public function porcelain() */ public function long() { - $this->processBuilder->add('--long'); + $this->arguments[] = '--long'; return $this; } @@ -178,7 +183,7 @@ public function long() */ public function null() { - $this->processBuilder->add('--null'); + $this->arguments[] = '--null'; return $this; } @@ -191,7 +196,7 @@ public function null() */ public function file($file) { - $this->processBuilder->add('--file=' . $file); + $this->arguments[] = '--file=' . $file; return $this; } @@ -204,7 +209,7 @@ public function file($file) */ public function author($author) { - $this->processBuilder->add('--author=' . $author); + $this->arguments[] = '--author=' . $author; return $this; } @@ -220,7 +225,7 @@ public function date($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--date=' . $date); + $this->arguments[] = '--date=' . $date; return $this; } @@ -233,7 +238,7 @@ public function date($date) */ public function message($message) { - $this->processBuilder->add('--message=' . $message); + $this->arguments[] = '--message=' . $message; return $this; } @@ -246,7 +251,7 @@ public function message($message) */ public function template($file) { - $this->processBuilder->add('--template=' . $file); + $this->arguments[] = '--template=' . $file; return $this; } @@ -257,7 +262,7 @@ public function template($file) */ public function signoff() { - $this->processBuilder->add('--signoff'); + $this->arguments[] = '--signoff'; return $this; } @@ -268,7 +273,7 @@ public function signoff() */ public function noVerity() { - $this->processBuilder->add('--no-verify'); + $this->arguments[] = '--no-verify'; return $this; } @@ -279,7 +284,7 @@ public function noVerity() */ public function allowEmpty() { - $this->processBuilder->add('--allow-empty'); + $this->arguments[] = '--allow-empty'; return $this; } @@ -290,7 +295,7 @@ public function allowEmpty() */ public function allowEmptyMessage() { - $this->processBuilder->add('--allow-empty-message'); + $this->arguments[] = '--allow-empty-message'; return $this; } @@ -303,7 +308,7 @@ public function allowEmptyMessage() */ public function cleanup($mode) { - $this->processBuilder->add('--cleanup=' . $mode); + $this->arguments[] = '--cleanup=' . $mode; return $this; } @@ -314,7 +319,7 @@ public function cleanup($mode) */ public function amend() { - $this->processBuilder->add('--amend'); + $this->arguments[] = '--amend'; return $this; } @@ -325,7 +330,7 @@ public function amend() */ public function noPostRewrite() { - $this->processBuilder->add('--no-post-rewrite'); + $this->arguments[] = '--no-post-rewrite'; return $this; } @@ -336,7 +341,7 @@ public function noPostRewrite() */ public function includ() { - $this->processBuilder->add('--include'); + $this->arguments[] = '--include'; return $this; } @@ -347,7 +352,7 @@ public function includ() */ public function only() { - $this->processBuilder->add('--only'); + $this->arguments[] = '--only'; return $this; } @@ -360,7 +365,7 @@ public function only() */ public function untrackedFiles($mode = null) { - $this->processBuilder->add('--untracked-files' . ($mode ? '=' . $mode : '')); + $this->arguments[] = '--untracked-files' . ($mode ? '=' . $mode : ''); return $this; } @@ -371,7 +376,7 @@ public function untrackedFiles($mode = null) */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -382,7 +387,7 @@ public function verbose() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -393,7 +398,7 @@ public function quiet() */ public function dryRun() { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; return $this; } @@ -404,7 +409,7 @@ public function dryRun() */ public function status() { - $this->processBuilder->add('--status'); + $this->arguments[] = '--status'; return $this; } @@ -415,7 +420,7 @@ public function status() */ public function noStatus() { - $this->processBuilder->add('--no-status'); + $this->arguments[] = '--no-status'; return $this; } @@ -429,14 +434,14 @@ public function noStatus() public function gpgSign($keyId = null) { $this->gpgSignIsset = true; - $this->processBuilder->add('--gpg-sign' . ($keyId ? '=' . $keyId : '')); + $this->arguments[] = '--gpg-sign' . ($keyId ? '=' . $keyId : ''); return $this; } /** * Build the command and execute it. * - * @param null| $pathspec Path to commit. + * @param null $pathspec Path to commit. * * @param null|string $_ More optional pathes to commit. * @@ -449,20 +454,20 @@ public function gpgSign($keyId = null) public function execute($pathspec = null, $_ = null) { // prevent launching the editor - $this->processBuilder->add('--no-edit'); + $this->arguments[] = '--no-edit'; if (!$this->gpgSignIsset && $this->repository->getConfig()->isSignCommitsEnabled()) { $this->gpgSign($this->repository->getConfig()->getSignCommitUser()); } - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathspec) { - $this->processBuilder->add($pathspec); + $this->arguments[] = $pathspec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/ConfigCommandBuilder.php b/src/Command/ConfigCommandBuilder.php new file mode 100644 index 0000000..4584f20 --- /dev/null +++ b/src/Command/ConfigCommandBuilder.php @@ -0,0 +1,379 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * This project is provided in good faith and hope to be usable by anyone. + * + * @package bit3/git-php + * @author Matthew Gamble + * @author Christian Schiffler + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins + * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php + * @filesource + */ + +namespace Bit3\GitPhp\Command; + +/** + * Config command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ +class ConfigCommandBuilder implements CommandBuilderInterface +{ + use CommandBuilderTrait; + + /** + * {@inheritDoc} + */ + protected function initializeProcessBuilder() + { + $this->arguments[] = 'config'; + } + + /** + * Specify a single config file that should be looked at. + * Has special support for the global, system and local flags. + * + * @param string $file The config file to use. + * + * @return ConfigCommandBuilder + */ + public function file($file) + { + if (\in_array($file, ['global', 'system', 'local'])) { + $this->arguments[] = '--' . $file; + } else { + $this->arguments[] = '--file'; + $this->arguments[] = $file; + } + return $this; + } + + /** + * Add the blob option to the command line. + * + * See "SPECIFYING REVISIONS" section in gitrevisions(7) for a list of ways to spell blob names. + * + * @param string $blobId The blob id to use. + * + * @return ConfigCommandBuilder + */ + public function blob($blobId) + { + $this->arguments[] = '--blob ' . $blobId; + return $this; + } + + /** + * Add a type option to the command line. + * + * @param string $type The type name. + * + * @return ConfigCommandBuilder + * + * @throws \InvalidArgumentException When an invalid type name is encountered. + */ + public function type($type) + { + if (\in_array($type, ['bool', 'int', 'bool-or-int', 'path'])) { + $this->arguments[] = '--' . $type; + } else { + throw new \InvalidArgumentException('Invalid configuration type supplied.'); + } + return $this; + } + + /** + * Add the add option and associated parameters to the command line. + * + * @param string $name The config value name. + * + * @param string $value The value to use. + * + * @return ConfigCommandBuilder + */ + public function add($name, $value) + { + $this->arguments[] = '--add'; + $this->arguments[] = $name; + $this->arguments[] = $value; + return $this; + } + + /** + * Add the replace-all option and associated parameters to the command line. + * + * @param string $name The config value name. + * + * @param string $value The value to use. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function replaceAll($name, $value, $valueRegex = null) + { + $this->arguments[] = '--replace-all'; + $this->arguments[] = $name; + $this->arguments[] = $value; + if ($valueRegex !== null) { + $this->arguments[] = $valueRegex; + } + return $this; + } + + /** + * Adds the NUL byte termination option to the command line. + * + * @return ConfigCommandBuilder + */ + public function terminateWithNUL() + { + $this->arguments[] = '--null'; + return $this; + } + + /** + * Add the get option and associated parameters to the command line. + * + * @param string $name The config value name. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function get($name, $valueRegex = null) + { + $this->arguments[] = '--get'; + $this->addNameAndPattern($name, $valueRegex); + return $this; + } + + /** + * Add the get-all option and associated parameters to the command line. + * + * @param string $name The config value name. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function getAll($name, $valueRegex = null) + { + $this->arguments[] = '--get-all'; + $this->addNameAndPattern($name, $valueRegex); + return $this; + } + + /** + * Add the get-regexp option and associated parameters to the command line. + * + * @param string $nameRegex The config name regex. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function getRegexp($nameRegex, $valueRegex = null) + { + $this->arguments[] = '--get-regexp'; + $this->addNameAndPattern($nameRegex, $valueRegex); + return $this; + } + + /** + * Add the get-urlmatch option and associated parameters to the command line. + * + * @param string $name The config name. + * + * @param string $url The url to match. + * + * @return ConfigCommandBuilder + */ + public function getUrlmatch($name, $url) + { + $this->arguments[] = '--get-urlmatch'; + $this->addNameAndPattern($name, $url); + return $this; + } + + /** + * Add the unset option and associated parameters to the command line. + * + * @param string $name The name of the config value to unset. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function unsetOpt($name, $valueRegex = null) + { + $this->arguments[] = '--unset'; + $this->addNameAndPattern($name, $valueRegex); + return $this; + } + + /** + * Add the unset-all option and associated parameters to the command line. + * + * @param string $name The name of the config value to unset. + * + * @param null|string $valueRegex The value regex to use. + * + * @return ConfigCommandBuilder + */ + public function unsetAll($name, $valueRegex = null) + { + $this->arguments[] = '--unset-all'; + $this->addNameAndPattern($name, $valueRegex); + return $this; + } + + /** + * Add the passed name and the passed pattern if not null. + * + * @param string $name The name to add. + * + * @param null|string $pattern The pattern to add (if not null). + * + * @return void + */ + private function addNameAndPattern($name, $pattern) + { + $this->arguments[] = $name; + if ($pattern !== null) { + $this->arguments[] = $pattern; + } + } + + /** + * Add the rename-section option and associated parameters to the command line. + * + * @param string $oldName The old section name. + * + * @param string $newName The new section name. + * + * @return ConfigCommandBuilder + */ + public function renameSection($oldName, $newName) + { + $this->arguments[] = '--rename-section'; + $this->arguments[] = $oldName; + $this->arguments[] = $newName; + return $this; + } + + /** + * Add the remove-section option to the command line. + * + * @param string $name The section name. + * + * @return ConfigCommandBuilder + */ + public function removeSection($name) + { + $this->arguments[] = '--remove-section'; + $this->arguments[] = $name; + return $this; + } + + /** + * Add the list option to the command line. + * + * @return ConfigCommandBuilder + */ + public function listOpt() + { + $this->arguments[] = '--list'; + return $this; + } + + /** + * Add the get-color option and associated parameters to the command line. + * + * @param string $name The name of the color to retrieve. + * + * @param null|string $default The default value to return. + * + * @return ConfigCommandBuilder + */ + public function getColor($name, $default = null) + { + $this->arguments[] = '--get-color'; + $this->arguments[] = $name; + if ($default !== null) { + $this->arguments[] = $default; + } + return $this; + } + + /** + * Add the get-colorbool option and associated parameters to the command line. + * + * @param string $name The name of the color to check. + * + * @param bool|null $stdoutIsTty Flag if stdout is a tty. + * + * @return ConfigCommandBuilder + */ + public function getColorBool($name, $stdoutIsTty = null) + { + $this->arguments[] = '--get-colorbool'; + $this->arguments[] = $name; + if (\is_bool($stdoutIsTty)) { + $this->arguments[] = $stdoutIsTty ? 'true' : 'false'; + } + return $this; + } + + /** + * Add the includes or no-includes option to the command line. + * + * @param bool $allow Flag if include.* directives in config files shall be respected when looking up values. + * + * @return ConfigCommandBuilder + */ + public function includes($allow = true) + { + $this->arguments[] = $allow ? '--includes' : '--no-includes'; + return $this; + } + + /** + * Build the command and execute it. + * + * @param null|string $name Pass name of setting here to perform a basic get or set operation. + * + * @param null|string $value Pass a value for the setting to turn this into a set command. + * + * @param null|string $valueRegex Pass a regex to limit changing of a multi-value setting to certain settings. + * + * @return mixed + * + * @SuppressWarnings(PHPMD.ShortVariableName) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + */ + public function execute($name = null, $value = null, $valueRegex = null) + { + if ($name !== null) { + $this->arguments[] = $name; + if ($value !== null) { + $this->arguments[] = $value; + if ($valueRegex !== null) { + $this->arguments[] = $valueRegex; + } + } + } + return $this->run(); + } +} diff --git a/src/Command/DescribeCommandBuilder.php b/src/Command/DescribeCommandBuilder.php index af5c2a4..d1f2415 100644 --- a/src/Command/DescribeCommandBuilder.php +++ b/src/Command/DescribeCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Describe command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class DescribeCommandBuilder extends AbstractCommandBuilder +class DescribeCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('describe'); + $this->arguments[] = 'describe'; } /** @@ -43,9 +48,9 @@ protected function initializeProcessBuilder() */ public function dirty($mark = false) { - $this->processBuilder->add('--dirty'); + $this->arguments[] = '--dirty'; if ($mark) { - $this->processBuilder->add($mark); + $this->arguments[] = $mark; } return $this; } @@ -57,7 +62,7 @@ public function dirty($mark = false) */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -68,7 +73,7 @@ public function all() */ public function tags() { - $this->processBuilder->add('--tags'); + $this->arguments[] = '--tags'; return $this; } @@ -79,7 +84,7 @@ public function tags() */ public function contains() { - $this->processBuilder->add('--contains'); + $this->arguments[] = '--contains'; return $this; } @@ -94,7 +99,7 @@ public function contains() */ public function abbrev($n) { - $this->processBuilder->add('--abbrev=' . $n); + $this->arguments[] = '--abbrev=' . $n; return $this; } @@ -109,7 +114,7 @@ public function abbrev($n) */ public function candidates($n) { - $this->processBuilder->add('--candidates=' . $n); + $this->arguments[] = '--candidates=' . $n; return $this; } @@ -120,7 +125,7 @@ public function candidates($n) */ public function exactMatch() { - $this->processBuilder->add('--exact-match'); + $this->arguments[] = '--exact-match'; return $this; } @@ -131,7 +136,7 @@ public function exactMatch() */ public function debug() { - $this->processBuilder->add('--debug'); + $this->arguments[] = '--debug'; return $this; } @@ -142,7 +147,7 @@ public function debug() */ public function long() { - $this->processBuilder->add('--long'); + $this->arguments[] = '--long'; return $this; } @@ -155,7 +160,8 @@ public function long() */ public function match($pattern) { - $this->processBuilder->add('--match')->add($pattern); + $this->arguments[] = '--match'; + $this->arguments[] = $pattern; return $this; } @@ -166,7 +172,7 @@ public function match($pattern) */ public function always() { - $this->processBuilder->add('--always'); + $this->arguments[] = '--always'; return $this; } @@ -177,7 +183,7 @@ public function always() */ public function firstParent() { - $this->processBuilder->add('--first-parent'); + $this->arguments[] = '--first-parent'; return $this; } @@ -190,7 +196,7 @@ public function firstParent() */ public function execute($commit = 'HEAD') { - $this->processBuilder->add($commit); - return parent::run(); + $this->arguments[] = $commit; + return $this->run(); } } diff --git a/src/Command/FetchCommandBuilder.php b/src/Command/FetchCommandBuilder.php index 313c924..c288047 100644 --- a/src/Command/FetchCommandBuilder.php +++ b/src/Command/FetchCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Fetch command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class FetchCommandBuilder extends AbstractCommandBuilder +class FetchCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const RECURSE_SUBMODULES_YES = 'yes'; const RECURSE_SUBMODULES_ON_DEMAND = 'on-demand'; @@ -37,7 +42,7 @@ class FetchCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('fetch'); + $this->arguments[] = 'fetch'; } /** @@ -47,7 +52,7 @@ protected function initializeProcessBuilder() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -58,7 +63,7 @@ public function all() */ public function append() { - $this->processBuilder->add('--append'); + $this->arguments[] = '--append'; return $this; } @@ -71,7 +76,7 @@ public function append() */ public function depth($depth) { - $this->processBuilder->add('--depth=' . $depth); + $this->arguments[] = '--depth=' . $depth; return $this; } @@ -82,7 +87,7 @@ public function depth($depth) */ public function unshallow() { - $this->processBuilder->add('--unshallow'); + $this->arguments[] = '--unshallow'; return $this; } @@ -93,7 +98,7 @@ public function unshallow() */ public function updateShallow() { - $this->processBuilder->add('--update-shallow'); + $this->arguments[] = '--update-shallow'; return $this; } @@ -104,7 +109,7 @@ public function updateShallow() */ public function dryRun() { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; return $this; } @@ -115,7 +120,7 @@ public function dryRun() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -126,7 +131,7 @@ public function force() */ public function keep() { - $this->processBuilder->add('--keep'); + $this->arguments[] = '--keep'; return $this; } @@ -137,7 +142,7 @@ public function keep() */ public function multiple() { - $this->processBuilder->add('--multiple'); + $this->arguments[] = '--multiple'; return $this; } @@ -148,7 +153,7 @@ public function multiple() */ public function prune() { - $this->processBuilder->add('--prune'); + $this->arguments[] = '--prune'; return $this; } @@ -159,7 +164,7 @@ public function prune() */ public function noTags() { - $this->processBuilder->add('--no-tags'); + $this->arguments[] = '--no-tags'; return $this; } @@ -170,7 +175,7 @@ public function noTags() */ public function tags() { - $this->processBuilder->add('--tags'); + $this->arguments[] = '--tags'; return $this; } @@ -183,7 +188,7 @@ public function tags() */ public function recurseSubmodules($recurse = false) { - $this->processBuilder->add('--recurse-submodules' . ($recurse ? '=' . $recurse : '')); + $this->arguments[] = '--recurse-submodules' . ($recurse ? '=' . $recurse : ''); return $this; } @@ -194,7 +199,7 @@ public function recurseSubmodules($recurse = false) */ public function noRecurseSubmodules() { - $this->processBuilder->add('--no-recurse-submodules'); + $this->arguments[] = '--no-recurse-submodules'; return $this; } @@ -207,7 +212,7 @@ public function noRecurseSubmodules() */ public function submodulePrefix($path) { - $this->processBuilder->add('--submodule-prefix=' . $path); + $this->arguments[] = '--submodule-prefix=' . $path; return $this; } @@ -220,7 +225,7 @@ public function submodulePrefix($path) */ public function recurseSubmodulesDefault($recurse) { - $this->processBuilder->add('--recurse-submodules-default=' . $recurse); + $this->arguments[] = '--recurse-submodules-default=' . $recurse; return $this; } @@ -231,7 +236,7 @@ public function recurseSubmodulesDefault($recurse) */ public function updateHeadOk() { - $this->processBuilder->add('--update-head-ok'); + $this->arguments[] = '--update-head-ok'; return $this; } @@ -244,7 +249,8 @@ public function updateHeadOk() */ public function uploadPack($uploadPack) { - $this->processBuilder->add('--upload-pack')->add($uploadPack); + $this->arguments[] = '--upload-pack'; + $this->arguments[] = $uploadPack; return $this; } @@ -255,7 +261,7 @@ public function uploadPack($uploadPack) */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -266,7 +272,7 @@ public function quiet() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -287,14 +293,14 @@ public function verbose() */ public function execute($repository = 'origin', $refspec = null, $_ = null) { - $this->processBuilder->add($repository); + $this->arguments[] = $repository; - $refspecs = func_get_args(); - array_shift($refspecs); + $refspecs = \func_get_args(); + \array_shift($refspecs); foreach ($refspecs as $refspec) { - $this->processBuilder->add($refspec); + $this->arguments[] = $refspec; } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/InitCommandBuilder.php b/src/Command/InitCommandBuilder.php index 5d42727..6864b23 100644 --- a/src/Command/InitCommandBuilder.php +++ b/src/Command/InitCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -24,8 +25,10 @@ /** * Init command builder. */ -class InitCommandBuilder extends AbstractCommandBuilder +class InitCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const SHARE_FALSE = 'false'; const SHARE_TRUE = 'true'; @@ -45,28 +48,28 @@ class InitCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('init'); + $this->arguments[] = 'init'; } /** * Add the quiet option to the command line. * - * @return FetchCommandBuilder + * @return InitCommandBuilder */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } /** * Add the bare option to the command line. * - * @return FetchCommandBuilder + * @return InitCommandBuilder */ public function bare() { - $this->processBuilder->add('--bare'); + $this->arguments[] = '--bare'; return $this; } @@ -75,11 +78,11 @@ public function bare() * * @param string $templateDirectory Path to the template directory. * - * @return FetchCommandBuilder + * @return InitCommandBuilder */ public function template($templateDirectory) { - $this->processBuilder->add('--template=' . $templateDirectory); + $this->arguments[] = '--template=' . $templateDirectory; return $this; } @@ -88,11 +91,11 @@ public function template($templateDirectory) * * @param string $gitDir Path to the .git dir. * - * @return FetchCommandBuilder + * @return InitCommandBuilder */ public function separateGitDir($gitDir) { - $this->processBuilder->add('--separate-git-dir=' . $gitDir); + $this->arguments[] = '--separate-git-dir=' . $gitDir; return $this; } @@ -101,11 +104,11 @@ public function separateGitDir($gitDir) * * @param string $share The share value. * - * @return FetchCommandBuilder + * @return InitCommandBuilder */ public function shared($share) { - $this->processBuilder->add('--shared=' . $share); + $this->arguments[] = '--shared=' . $share; return $this; } @@ -116,7 +119,7 @@ public function shared($share) */ public function execute() { - $this->processBuilder->add($this->repository->getRepositoryPath()); - return parent::run(); + $this->arguments[] = $this->repository->getRepositoryPath(); + return $this->run(); } } diff --git a/src/Command/LogCommandBuilder.php b/src/Command/LogCommandBuilder.php index ef2d457..55dd086 100644 --- a/src/Command/LogCommandBuilder.php +++ b/src/Command/LogCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -27,9 +28,12 @@ * @SuppressWarnings(PHPMD.ExcessiveClassLength) * @SuppressWarnings(PHPMD.ExcessivePublicCount) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class LogCommandBuilder extends AbstractCommandBuilder +class LogCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const DECORATE_SHORT = 'short'; const DECORATE_FULL = 'full'; @@ -59,7 +63,7 @@ class LogCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('log'); + $this->arguments[] = 'log'; } /** @@ -69,7 +73,7 @@ protected function initializeProcessBuilder() */ public function follow() { - $this->processBuilder->add('--follow'); + $this->arguments[] = '--follow'; return $this; } @@ -80,7 +84,7 @@ public function follow() */ public function noDecorate() { - $this->processBuilder->add('--no-decorate'); + $this->arguments[] = '--no-decorate'; return $this; } @@ -93,7 +97,7 @@ public function noDecorate() */ public function decorate($decorate) { - $this->processBuilder->add('--decorate' . ($decorate ? '=' . $decorate : '')); + $this->arguments[] = '--decorate' . ($decorate ? '=' . $decorate : ''); return $this; } @@ -104,7 +108,7 @@ public function decorate($decorate) */ public function source() { - $this->processBuilder->add('--source'); + $this->arguments[] = '--source'; return $this; } @@ -115,7 +119,7 @@ public function source() */ public function useMailmap() { - $this->processBuilder->add('--use-mailmap'); + $this->arguments[] = '--use-mailmap'; return $this; } @@ -126,7 +130,7 @@ public function useMailmap() */ public function fullDiff() { - $this->processBuilder->add('--full-diff'); + $this->arguments[] = '--full-diff'; return $this; } @@ -137,7 +141,7 @@ public function fullDiff() */ public function logSize() { - $this->processBuilder->add('--log-size'); + $this->arguments[] = '--log-size'; return $this; } @@ -150,7 +154,7 @@ public function logSize() */ public function revisionRange($revisionRange) { - $this->processBuilder->add($revisionRange); + $this->arguments[] = $revisionRange; return $this; } @@ -163,7 +167,7 @@ public function revisionRange($revisionRange) */ public function maxCount($number) { - $this->processBuilder->add('--max-count=' . $number); + $this->arguments[] = '--max-count=' . $number; return $this; } @@ -176,7 +180,7 @@ public function maxCount($number) */ public function skip($number) { - $this->processBuilder->add('--skip=' . $number); + $this->arguments[] = '--skip=' . $number; return $this; } @@ -192,7 +196,7 @@ public function since($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--since=' . $date); + $this->arguments[] = '--since=' . $date; return $this; } @@ -208,7 +212,7 @@ public function after($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--after=' . $date); + $this->arguments[] = '--after=' . $date; return $this; } @@ -224,7 +228,7 @@ public function until($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--until=' . $date); + $this->arguments[] = '--until=' . $date; return $this; } @@ -240,7 +244,7 @@ public function before($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--before=' . $date); + $this->arguments[] = '--before=' . $date; return $this; } @@ -253,7 +257,7 @@ public function before($date) */ public function author($pattern) { - $this->processBuilder->add('--author=' . $pattern); + $this->arguments[] = '--author=' . $pattern; return $this; } @@ -266,7 +270,7 @@ public function author($pattern) */ public function grepReflog($pattern) { - $this->processBuilder->add('--grep-reflog=' . $pattern); + $this->arguments[] = '--grep-reflog=' . $pattern; return $this; } @@ -279,7 +283,7 @@ public function grepReflog($pattern) */ public function grep($pattern) { - $this->processBuilder->add('--grep=' . $pattern); + $this->arguments[] = '--grep=' . $pattern; return $this; } @@ -290,7 +294,7 @@ public function grep($pattern) */ public function allMatch() { - $this->processBuilder->add('--all-match'); + $this->arguments[] = '--all-match'; return $this; } @@ -301,7 +305,7 @@ public function allMatch() */ public function regexpIgnoreCase() { - $this->processBuilder->add('--regexp-ignore-case'); + $this->arguments[] = '--regexp-ignore-case'; return $this; } @@ -312,7 +316,7 @@ public function regexpIgnoreCase() */ public function basicRegexp() { - $this->processBuilder->add('--basicRegexp'); + $this->arguments[] = '--basicRegexp'; return $this; } @@ -323,7 +327,7 @@ public function basicRegexp() */ public function extendedRegexp() { - $this->processBuilder->add('--extended-regexp'); + $this->arguments[] = '--extended-regexp'; return $this; } @@ -334,7 +338,7 @@ public function extendedRegexp() */ public function fixedStrings() { - $this->processBuilder->add('--fixed-strings'); + $this->arguments[] = '--fixed-strings'; return $this; } @@ -345,7 +349,7 @@ public function fixedStrings() */ public function perlRegexp() { - $this->processBuilder->add('--perl-regexp'); + $this->arguments[] = '--perl-regexp'; return $this; } @@ -356,7 +360,7 @@ public function perlRegexp() */ public function removeEmpty() { - $this->processBuilder->add('--remove-empty'); + $this->arguments[] = '--remove-empty'; return $this; } @@ -367,7 +371,7 @@ public function removeEmpty() */ public function merges() { - $this->processBuilder->add('--merges'); + $this->arguments[] = '--merges'; return $this; } @@ -378,7 +382,7 @@ public function merges() */ public function noMerges() { - $this->processBuilder->add('--no-merges'); + $this->arguments[] = '--no-merges'; return $this; } @@ -391,7 +395,7 @@ public function noMerges() */ public function minParents($number) { - $this->processBuilder->add('--min-parents=' . $number); + $this->arguments[] = '--min-parents=' . $number; return $this; } @@ -404,7 +408,7 @@ public function minParents($number) */ public function maxParents($number) { - $this->processBuilder->add('--max-parents=' . $number); + $this->arguments[] = '--max-parents=' . $number; return $this; } @@ -415,7 +419,7 @@ public function maxParents($number) */ public function noMinParents() { - $this->processBuilder->add('--no-min-parents'); + $this->arguments[] = '--no-min-parents'; return $this; } @@ -426,7 +430,7 @@ public function noMinParents() */ public function noMaxParents() { - $this->processBuilder->add('--no-max-parents'); + $this->arguments[] = '--no-max-parents'; return $this; } @@ -437,7 +441,7 @@ public function noMaxParents() */ public function firstParent() { - $this->processBuilder->add('--first-parent'); + $this->arguments[] = '--first-parent'; return $this; } @@ -448,7 +452,7 @@ public function firstParent() */ public function not() { - $this->processBuilder->add('--not'); + $this->arguments[] = '--not'; return $this; } @@ -459,7 +463,7 @@ public function not() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -472,7 +476,7 @@ public function all() */ public function branches($pattern = null) { - $this->processBuilder->add('--branches' . ($pattern ? '=' . $pattern : '')); + $this->arguments[] = '--branches' . ($pattern ? '=' . $pattern : ''); return $this; } @@ -485,7 +489,7 @@ public function branches($pattern = null) */ public function tags($pattern = null) { - $this->processBuilder->add('--tags' . ($pattern ? '=' . $pattern : '')); + $this->arguments[] = '--tags' . ($pattern ? '=' . $pattern : ''); return $this; } @@ -498,7 +502,7 @@ public function tags($pattern = null) */ public function remotes($pattern = null) { - $this->processBuilder->add('--remotes' . ($pattern ? '=' . $pattern : '')); + $this->arguments[] = '--remotes' . ($pattern ? '=' . $pattern : ''); return $this; } @@ -511,7 +515,7 @@ public function remotes($pattern = null) */ public function glob($pattern = null) { - $this->processBuilder->add('--glob=' . $pattern); + $this->arguments[] = '--glob=' . $pattern; return $this; } @@ -524,7 +528,7 @@ public function glob($pattern = null) */ public function exclude($pattern = null) { - $this->processBuilder->add('--exclude=' . $pattern); + $this->arguments[] = '--exclude=' . $pattern; return $this; } @@ -535,7 +539,7 @@ public function exclude($pattern = null) */ public function ignoreMissing() { - $this->processBuilder->add('--ignore-missing'); + $this->arguments[] = '--ignore-missing'; return $this; } @@ -546,7 +550,7 @@ public function ignoreMissing() */ public function bisect() { - $this->processBuilder->add('--bisect'); + $this->arguments[] = '--bisect'; return $this; } @@ -557,7 +561,7 @@ public function bisect() */ public function cherryMark() { - $this->processBuilder->add('--cherry-mark'); + $this->arguments[] = '--cherry-mark'; return $this; } @@ -568,7 +572,7 @@ public function cherryMark() */ public function cherryPick() { - $this->processBuilder->add('--cherry-pick'); + $this->arguments[] = '--cherry-pick'; return $this; } @@ -579,7 +583,7 @@ public function cherryPick() */ public function leftOnly() { - $this->processBuilder->add('--left-only'); + $this->arguments[] = '--left-only'; return $this; } @@ -590,7 +594,7 @@ public function leftOnly() */ public function rightOnly() { - $this->processBuilder->add('--right-only'); + $this->arguments[] = '--right-only'; return $this; } @@ -601,7 +605,7 @@ public function rightOnly() */ public function cherry() { - $this->processBuilder->add('--cherry'); + $this->arguments[] = '--cherry'; return $this; } @@ -612,7 +616,7 @@ public function cherry() */ public function walkReflogs() { - $this->processBuilder->add('--walk-reflogs'); + $this->arguments[] = '--walk-reflogs'; return $this; } @@ -623,7 +627,7 @@ public function walkReflogs() */ public function merge() { - $this->processBuilder->add('--merge'); + $this->arguments[] = '--merge'; return $this; } @@ -634,7 +638,7 @@ public function merge() */ public function boundary() { - $this->processBuilder->add('--boundary'); + $this->arguments[] = '--boundary'; return $this; } @@ -645,7 +649,7 @@ public function boundary() */ public function simplifyByDecoration() { - $this->processBuilder->add('--simplify-by-decoration'); + $this->arguments[] = '--simplify-by-decoration'; return $this; } @@ -656,7 +660,7 @@ public function simplifyByDecoration() */ public function fullHistory() { - $this->processBuilder->add('--full-history'); + $this->arguments[] = '--full-history'; return $this; } @@ -667,7 +671,7 @@ public function fullHistory() */ public function dense() { - $this->processBuilder->add('--dense'); + $this->arguments[] = '--dense'; return $this; } @@ -678,7 +682,7 @@ public function dense() */ public function sparse() { - $this->processBuilder->add('--sparse'); + $this->arguments[] = '--sparse'; return $this; } @@ -689,7 +693,7 @@ public function sparse() */ public function simplifyMerges() { - $this->processBuilder->add('--simplify-merges'); + $this->arguments[] = '--simplify-merges'; return $this; } @@ -700,7 +704,7 @@ public function simplifyMerges() */ public function ancestryPath() { - $this->processBuilder->add('--ancestry-path'); + $this->arguments[] = '--ancestry-path'; return $this; } @@ -711,7 +715,7 @@ public function ancestryPath() */ public function dateOrder() { - $this->processBuilder->add('--date-order'); + $this->arguments[] = '--date-order'; return $this; } @@ -722,7 +726,7 @@ public function dateOrder() */ public function authorDateOrder() { - $this->processBuilder->add('--author-date-order'); + $this->arguments[] = '--author-date-order'; return $this; } @@ -733,7 +737,7 @@ public function authorDateOrder() */ public function topoOrder() { - $this->processBuilder->add('--topo-order'); + $this->arguments[] = '--topo-order'; return $this; } @@ -744,7 +748,7 @@ public function topoOrder() */ public function reverse() { - $this->processBuilder->add('--reverse'); + $this->arguments[] = '--reverse'; return $this; } @@ -755,7 +759,7 @@ public function reverse() */ public function objects() { - $this->processBuilder->add('--objects'); + $this->arguments[] = '--objects'; return $this; } @@ -766,7 +770,7 @@ public function objects() */ public function objectsEdge() { - $this->processBuilder->add('--objects-edge'); + $this->arguments[] = '--objects-edge'; return $this; } @@ -777,7 +781,7 @@ public function objectsEdge() */ public function unpacked() { - $this->processBuilder->add('--unpacked'); + $this->arguments[] = '--unpacked'; return $this; } @@ -790,7 +794,7 @@ public function unpacked() */ public function noWalk($walk = null) { - $this->processBuilder->add('--no-walk' . ($walk ? '=' . $walk : '')); + $this->arguments[] = '--no-walk' . ($walk ? '=' . $walk : ''); return $this; } @@ -801,7 +805,7 @@ public function noWalk($walk = null) */ public function doWalk() { - $this->processBuilder->add('--do-walk'); + $this->arguments[] = '--do-walk'; return $this; } @@ -814,7 +818,7 @@ public function doWalk() */ public function pretty($format = null) { - $this->processBuilder->add('--pretty' . ($format ? '=' . $format : '')); + $this->arguments[] = '--pretty' . ($format ? '=' . $format : ''); return $this; } @@ -827,7 +831,7 @@ public function pretty($format = null) */ public function format($format) { - $this->processBuilder->add('--format=' . $format); + $this->arguments[] = '--format=' . $format; return $this; } @@ -838,7 +842,7 @@ public function format($format) */ public function abbrevCommit() { - $this->processBuilder->add('--abbrev-commit'); + $this->arguments[] = '--abbrev-commit'; return $this; } @@ -849,7 +853,7 @@ public function abbrevCommit() */ public function noAbbrevCommit() { - $this->processBuilder->add('--no-abbrev-commit'); + $this->arguments[] = '--no-abbrev-commit'; return $this; } @@ -860,7 +864,7 @@ public function noAbbrevCommit() */ public function oneline() { - $this->processBuilder->add('--oneline'); + $this->arguments[] = '--oneline'; return $this; } @@ -873,7 +877,7 @@ public function oneline() */ public function encoding($encoding) { - $this->processBuilder->add('--encoding=' . $encoding); + $this->arguments[] = '--encoding=' . $encoding; return $this; } @@ -886,7 +890,7 @@ public function encoding($encoding) */ public function notes($ref = null) { - $this->processBuilder->add('--notes' . ($ref ? '=' . $ref : '')); + $this->arguments[] = '--notes' . ($ref ? '=' . $ref : ''); return $this; } @@ -897,7 +901,7 @@ public function notes($ref = null) */ public function noNotes() { - $this->processBuilder->add('--no-notes'); + $this->arguments[] = '--no-notes'; return $this; } @@ -910,7 +914,7 @@ public function noNotes() */ public function showNotes($ref = null) { - $this->processBuilder->add('--show-notes' . ($ref ? '=' . $ref : '')); + $this->arguments[] = '--show-notes' . ($ref ? '=' . $ref : ''); return $this; } @@ -921,7 +925,7 @@ public function showNotes($ref = null) */ public function showSignature() { - $this->processBuilder->add('--show-signature'); + $this->arguments[] = '--show-signature'; return $this; } @@ -932,7 +936,7 @@ public function showSignature() */ public function relativeDate() { - $this->processBuilder->add('--relative-date'); + $this->arguments[] = '--relative-date'; return $this; } @@ -945,7 +949,7 @@ public function relativeDate() */ public function date($format) { - $this->processBuilder->add('--date=' . $format); + $this->arguments[] = '--date=' . $format; return $this; } @@ -956,7 +960,7 @@ public function date($format) */ public function parents() { - $this->processBuilder->add('--parents'); + $this->arguments[] = '--parents'; return $this; } @@ -967,7 +971,7 @@ public function parents() */ public function children() { - $this->processBuilder->add('--children'); + $this->arguments[] = '--children'; return $this; } @@ -978,7 +982,7 @@ public function children() */ public function leftRight() { - $this->processBuilder->add('--left-right'); + $this->arguments[] = '--left-right'; return $this; } @@ -989,7 +993,7 @@ public function leftRight() */ public function graph() { - $this->processBuilder->add('--graph'); + $this->arguments[] = '--graph'; return $this; } @@ -1002,7 +1006,7 @@ public function graph() */ public function c() { - $this->processBuilder->add('-c'); + $this->arguments[] = '-c'; return $this; } @@ -1015,7 +1019,7 @@ public function c() */ public function cc() { - $this->processBuilder->add('--cc'); + $this->arguments[] = '--cc'; return $this; } @@ -1028,7 +1032,7 @@ public function cc() */ public function m() { - $this->processBuilder->add('-m'); + $this->arguments[] = '-m'; return $this; } @@ -1041,7 +1045,7 @@ public function m() */ public function r() { - $this->processBuilder->add('-r'); + $this->arguments[] = '-r'; return $this; } @@ -1054,7 +1058,7 @@ public function r() */ public function t() { - $this->processBuilder->add('-t'); + $this->arguments[] = '-t'; return $this; } @@ -1073,13 +1077,13 @@ public function t() */ public function execute($pathspec = null, $_ = null) { - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathspec) { - $this->processBuilder->add($pathspec); + $this->arguments[] = $pathspec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/LsRemoteCommandBuilder.php b/src/Command/LsRemoteCommandBuilder.php index 37c00d3..a2b20ec 100644 --- a/src/Command/LsRemoteCommandBuilder.php +++ b/src/Command/LsRemoteCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -24,14 +25,16 @@ /** * Ls remote command builder. */ -class LsRemoteCommandBuilder extends AbstractCommandBuilder +class LsRemoteCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('ls-remote'); + $this->arguments[] = 'ls-remote'; } /** @@ -41,7 +44,7 @@ protected function initializeProcessBuilder() */ public function heads() { - $this->processBuilder->add('--heads'); + $this->arguments[] = '--heads'; return $this; } @@ -52,7 +55,7 @@ public function heads() */ public function tags() { - $this->processBuilder->add('--tags'); + $this->arguments[] = '--tags'; return $this; } @@ -65,7 +68,8 @@ public function tags() */ public function uploadPack($exec) { - $this->processBuilder->add('--upload-pack')->add($exec); + $this->arguments[] = '--upload-pack'; + $this->arguments[] = $exec; return $this; } @@ -76,7 +80,7 @@ public function uploadPack($exec) */ public function exitCode() { - $this->processBuilder->add('--exit-code'); + $this->arguments[] = '--exit-code'; return $this; } @@ -97,12 +101,12 @@ public function exitCode() */ public function execute($remote, $refSpec = null, $_ = null) { - $this->processBuilder->add($remote); + $this->arguments[] = $remote; - $refSpec = func_get_args(); - array_shift($refSpec); + $refSpec = \func_get_args(); + \array_shift($refSpec); foreach ($refSpec as $ref) { - $this->processBuilder->add($ref); + $this->arguments[] = $ref; } return $this->run(); @@ -125,17 +129,17 @@ public function execute($remote, $refSpec = null, $_ = null) */ public function getRefs($remote, $refSpec = null, $_ = null) { - $output = call_user_func_array(array($this, 'execute'), func_get_args()); - $output = explode("\n", $output); - $output = array_map('trim', $output); - $output = array_filter($output); + $output = \call_user_func_array([$this, 'execute'], \func_get_args()); + $output = \explode("\n", $output); + $output = \array_map('trim', $output); + $output = \array_filter($output); - $refs = array(); + $refs = []; foreach ($output as $line) { - $line = preg_split('~\s+~', $line); + $line = \preg_split('~\s+~', $line); - if ('^{}' != substr($line[1], -3)) { + if ('^{}' != \substr($line[1], -3)) { $refs[$line[1]] = $line[0]; } } diff --git a/src/Command/MergeCommandBuilder.php b/src/Command/MergeCommandBuilder.php index 1be80bd..82c40a7 100644 --- a/src/Command/MergeCommandBuilder.php +++ b/src/Command/MergeCommandBuilder.php @@ -12,9 +12,11 @@ * * @package bit3/git-php * @author Aaron Rubin - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Christian Schiffler + * @author Sven Baumann + * @copyright 2014-2022 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,70 +25,72 @@ /** * Merge command builder. */ -class MergeCommandBuilder extends AbstractCommandBuilder +class MergeCommandBuilder implements CommandBuilderInterface { - /** - * {@inheritDoc} - */ + use CommandBuilderTrait; + + /** + * {@inheritDoc} + */ protected function initializeProcessBuilder() { - $this->processBuilder->add('merge'); + $this->arguments[] = 'merge'; } - /** - * Add the quiet option to the command line. - * - * @return MergeCommandBuilder - */ + /** + * Add the quiet option to the command line. + * + * @return MergeCommandBuilder + */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } - /** - * Add the strategy option to the command line with the given strategy. - * - * @param string $strategy Strategy to use when merging. - * - * @return MergeCommandBuilder - */ + /** + * Add the strategy option to the command line with the given strategy. + * + * @param string $strategy Strategy to use when merging. + * + * @return MergeCommandBuilder + */ public function strategy($strategy) { - $this->processBuilder->add('--strategy='.$strategy); + $this->arguments[] = '--strategy=' . $strategy; return $this; } - /** - * Build the command and execute it. - * - * @param null|string $branchOrTreeIsh Name of the branch or tree. - * - * @param null| $path Path to which check out. - * - * @param null|string $_ More optional arguments to append to the command. - * - * @return mixed - * - * @SuppressWarnings(PHPMD.ShortVariableName) - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @SuppressWarnings(PHPMD.CamelCaseParameterName) - */ + /** + * Build the command and execute it. + * + * @param null|string $branchOrTreeIsh Name of the branch or tree. + * + * @param null $path Path to which check out. + * + * @param null|string $_ More optional arguments to append to the command. + * + * @return mixed + * + * @SuppressWarnings(PHPMD.ShortVariableName) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + */ public function execute($branchOrTreeIsh = null, $path = null, $_ = null) { if ($branchOrTreeIsh) { - $this->processBuilder->add($branchOrTreeIsh); + $this->arguments[] = $branchOrTreeIsh; } - $paths = func_get_args(); - array_shift($paths); - if (count($paths)) { - $this->processBuilder->add('--'); + $paths = \func_get_args(); + \array_shift($paths); + if (\count($paths)) { + $this->arguments[] = '--'; foreach ($paths as $path) { - $this->processBuilder->add($path); + $this->arguments[] = $path; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/PullCommandBuilder.php b/src/Command/PullCommandBuilder.php new file mode 100644 index 0000000..443e686 --- /dev/null +++ b/src/Command/PullCommandBuilder.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * This project is provided in good faith and hope to be usable by anyone. + * + * @package bit3/git-php + * @author Ahmad Marzouq + * @author Christian Schiffler + * @author Sven Baumann + * @author Idris Dose + * @copyright 2014-2022 Tristan Lins + * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php + * @filesource + */ + +namespace Bit3\GitPhp\Command; + +/** + * Pull command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ +class PullCommandBuilder implements CommandBuilderInterface +{ + use CommandBuilderTrait; + + /** + * {@inheritDoc} + */ + protected function initializeProcessBuilder() + { + $this->arguments[] = 'pull'; + } + + /** + * Add the quiet option to the command line. + * + * @return PullCommandBuilder + */ + public function quiet() + { + $this->arguments[] = '--quiet'; + return $this; + } + + /** + * Add the verbose option to the command line. + * + * @return PullCommandBuilder + */ + public function verbose() + { + $this->arguments[] = '--verbose'; + return $this; + } + + /** + * Add the recurse-submodules option to the command line. + * + * @param string $recurse The value. + * + * @return PullCommandBuilder + */ + public function recurseSubmodules($recurse) + { + $this->arguments[] = '--recurse-submodules=' . $recurse; + return $this; + } + + + /** + * Build the command and execute it. + * + * @param string $repository Name of the remote to pull from. + * + * @param null|string $refspec Ref spec to pull. + * + * @param null|string $_ More optional ref specs to pull. + * + * @return string + * + * @SuppressWarnings(PHPMD.ShortVariableName) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + */ + public function execute($repository = 'origin', $refspec = null, $_ = null) + { + $this->arguments[] = $repository; + + $refspecs = \func_get_args(); + \array_shift($refspecs); + foreach ($refspecs as $refspec) { + $this->arguments[] = $refspec; + } + + return $this->run(); + } +} diff --git a/src/Command/PushCommandBuilder.php b/src/Command/PushCommandBuilder.php index 4cc9a44..84e53f9 100644 --- a/src/Command/PushCommandBuilder.php +++ b/src/Command/PushCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Push command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class PushCommandBuilder extends AbstractCommandBuilder +class PushCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const RECURSE_SUBMODULES_CHECK = 'check'; const RECURSE_SUBMODULES_ON_DEMAND = 'on-demand'; @@ -35,7 +40,7 @@ class PushCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('push'); + $this->arguments[] = 'push'; } /** @@ -45,7 +50,7 @@ protected function initializeProcessBuilder() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -56,7 +61,7 @@ public function all() */ public function prune() { - $this->processBuilder->add('--prune'); + $this->arguments[] = '--prune'; return $this; } @@ -67,7 +72,7 @@ public function prune() */ public function mirror() { - $this->processBuilder->add('--mirror'); + $this->arguments[] = '--mirror'; return $this; } @@ -78,7 +83,7 @@ public function mirror() */ public function dryRun() { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; return $this; } @@ -89,7 +94,7 @@ public function dryRun() */ public function porcelain() { - $this->processBuilder->add('--porcelain'); + $this->arguments[] = '--porcelain'; return $this; } @@ -100,7 +105,7 @@ public function porcelain() */ public function delete() { - $this->processBuilder->add('--delete'); + $this->arguments[] = '--delete'; return $this; } @@ -111,7 +116,7 @@ public function delete() */ public function tags() { - $this->processBuilder->add('--tags'); + $this->arguments[] = '--tags'; return $this; } @@ -122,7 +127,7 @@ public function tags() */ public function followTags() { - $this->processBuilder->add('--follow-tags'); + $this->arguments[] = '--follow-tags'; return $this; } @@ -135,7 +140,7 @@ public function followTags() */ public function receivePack($gitReceivePack) { - $this->processBuilder->add('--receive-pack=' . $gitReceivePack); + $this->arguments[] = '--receive-pack=' . $gitReceivePack; return $this; } @@ -150,9 +155,7 @@ public function receivePack($gitReceivePack) */ public function forceWithLease($refname, $expect = null) { - $this->processBuilder->add( - '--force-with-lease' . ($refname ? ('=' . $refname . ($expect ? ':' . $expect : '')) : '') - ); + $this->arguments[] = '--force-with-lease' . ($refname ? ('=' . $refname . ($expect ? ':' . $expect : '')) : ''); return $this; } @@ -163,7 +166,7 @@ public function forceWithLease($refname, $expect = null) */ public function noForceWithLease() { - $this->processBuilder->add('--no-force-with-lease'); + $this->arguments[] = '--no-force-with-lease'; return $this; } @@ -174,7 +177,7 @@ public function noForceWithLease() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -187,7 +190,7 @@ public function force() */ public function repo($repository) { - $this->processBuilder->add('--repo=' . $repository); + $this->arguments[] = '--repo=' . $repository; return $this; } @@ -198,7 +201,7 @@ public function repo($repository) */ public function setUpstream() { - $this->processBuilder->add('--set-upstream'); + $this->arguments[] = '--set-upstream'; return $this; } @@ -209,7 +212,7 @@ public function setUpstream() */ public function thin() { - $this->processBuilder->add('--thin'); + $this->arguments[] = '--thin'; return $this; } @@ -220,7 +223,7 @@ public function thin() */ public function noThin() { - $this->processBuilder->add('--no-thin'); + $this->arguments[] = '--no-thin'; return $this; } @@ -231,7 +234,7 @@ public function noThin() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -242,7 +245,7 @@ public function quiet() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -255,7 +258,7 @@ public function verbose() */ public function recurseSubmodules($recurse) { - $this->processBuilder->add('--recurse-submodules=' . $recurse); + $this->arguments[] = '--recurse-submodules=' . $recurse; return $this; } @@ -266,7 +269,7 @@ public function recurseSubmodules($recurse) */ public function verify() { - $this->processBuilder->add('--verify'); + $this->arguments[] = '--verify'; return $this; } @@ -277,7 +280,7 @@ public function verify() */ public function noVerify() { - $this->processBuilder->add('--no-verify'); + $this->arguments[] = '--no-verify'; return $this; } @@ -298,14 +301,14 @@ public function noVerify() */ public function execute($repository, $refspec = null, $_ = null) { - $this->processBuilder->add($repository); + $this->arguments[] = $repository; - $refspecs = func_get_args(); - array_shift($refspecs); + $refspecs = \func_get_args(); + \array_shift($refspecs); foreach ($refspecs as $refspec) { - $this->processBuilder->add($refspec); + $this->arguments[] = $refspec; } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/RemoteCommandBuilder.php b/src/Command/RemoteCommandBuilder.php index 121a453..5d56c6b 100644 --- a/src/Command/RemoteCommandBuilder.php +++ b/src/Command/RemoteCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Remote command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class RemoteCommandBuilder extends AbstractCommandBuilder +class RemoteCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('remote'); + $this->arguments[] = 'remote'; } /** @@ -41,7 +46,7 @@ protected function initializeProcessBuilder() */ public function verbose() { - $this->processBuilder->add('--verbose'); + $this->arguments[] = '--verbose'; return $this; } @@ -56,7 +61,9 @@ public function verbose() */ public function add($name, $url) { - $this->processBuilder->add('add')->add($name)->add($url); + $this->arguments[] = 'add'; + $this->arguments[] = $name; + $this->arguments[] = $url; return $this; } @@ -71,11 +78,11 @@ public function add($name, $url) */ public function rename($new, $old = null) { - $this->processBuilder->add('rename'); + $this->arguments[] = 'rename'; if ($old) { - $this->processBuilder->add($old); + $this->arguments[] = $old; } - $this->processBuilder->add($new); + $this->arguments[] = $new; return $this; } @@ -88,7 +95,8 @@ public function rename($new, $old = null) */ public function remove($name) { - $this->processBuilder->add('remove')->add($name); + $this->arguments[] = 'remove'; + $this->arguments[] = $name; return $this; } @@ -103,7 +111,9 @@ public function remove($name) */ public function setHead($name, $branch) { - $this->processBuilder->add('set-head')->add($name)->add($branch); + $this->arguments[] = 'set-head'; + $this->arguments[] = $name; + $this->arguments[] = $branch; return $this; } @@ -116,7 +126,9 @@ public function setHead($name, $branch) */ public function setHeadAuto($name) { - $this->processBuilder->add('set-head')->add($name)->add('--auto'); + $this->arguments[] = 'set-head'; + $this->arguments[] = $name; + $this->arguments[] = '--auto'; return $this; } @@ -129,7 +141,9 @@ public function setHeadAuto($name) */ public function setHeadDelete($name) { - $this->processBuilder->add('set-head')->add($name)->add('--delete'); + $this->arguments[] = 'set-head'; + $this->arguments[] = $name; + $this->arguments[] = '--delete'; return $this; } @@ -146,11 +160,12 @@ public function setHeadDelete($name) */ public function setBranches($name, $branch, $add = false) { - $this->processBuilder->add('set-branches'); + $this->arguments[] = 'set-branches'; if ($add) { - $this->processBuilder->add('--add'); + $this->arguments[] = '--add'; } - $this->processBuilder->add($name)->add($branch); + $this->arguments[] = $name; + $this->arguments[] = $branch; return $this; } @@ -167,9 +182,11 @@ public function setBranches($name, $branch, $add = false) */ public function setUrl($name, $url, $oldUrl = null) { - $this->processBuilder->add('set-url')->add($name)->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = $name; + $this->arguments[] = $url; if ($oldUrl) { - $this->processBuilder->add($oldUrl); + $this->arguments[] = $oldUrl; } return $this; } @@ -187,9 +204,12 @@ public function setUrl($name, $url, $oldUrl = null) */ public function setPushUrl($name, $url, $oldUrl = null) { - $this->processBuilder->add('set-url')->add($name)->add('--push')->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = $name; + $this->arguments[] = '--push'; + $this->arguments[] = $url; if ($oldUrl) { - $this->processBuilder->add($oldUrl); + $this->arguments[] = $oldUrl; } return $this; } @@ -205,7 +225,10 @@ public function setPushUrl($name, $url, $oldUrl = null) */ public function addUrl($name, $url) { - $this->processBuilder->add('set-url')->add('--add')->add($name)->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = '--add'; + $this->arguments[] = $name; + $this->arguments[] = $url; return $this; } @@ -220,7 +243,11 @@ public function addUrl($name, $url) */ public function addPushUrl($name, $url) { - $this->processBuilder->add('set-url')->add('--add')->add('--push')->add($name)->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = '--add'; + $this->arguments[] = '--push'; + $this->arguments[] = $name; + $this->arguments[] = $url; return $this; } @@ -235,7 +262,10 @@ public function addPushUrl($name, $url) */ public function deleteUrl($name, $url) { - $this->processBuilder->add('set-url')->add('--delete')->add($name)->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = '--delete'; + $this->arguments[] = $name; + $this->arguments[] = $url; return $this; } @@ -250,7 +280,11 @@ public function deleteUrl($name, $url) */ public function deletePushUrl($name, $url) { - $this->processBuilder->add('set-url')->add('--delete')->add('--push')->add($name)->add($url); + $this->arguments[] = 'set-url'; + $this->arguments[] = '--delete'; + $this->arguments[] = '--push'; + $this->arguments[] = $name; + $this->arguments[] = $url; return $this; } @@ -263,7 +297,8 @@ public function deletePushUrl($name, $url) */ public function show($name) { - $this->processBuilder->add('show')->add($name); + $this->arguments[] = 'show'; + $this->arguments[] = $name; return $this; } @@ -278,11 +313,11 @@ public function show($name) */ public function prune($name, $dryRun = false) { - $this->processBuilder->add('prune'); + $this->arguments[] = 'prune'; if ($dryRun) { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; } - $this->processBuilder->add($name); + $this->arguments[] = $name; return $this; } @@ -297,11 +332,11 @@ public function prune($name, $dryRun = false) */ public function update($groupOrRemote, $prune = false) { - $this->processBuilder->add('update'); + $this->arguments[] = 'update'; if ($prune) { - $this->processBuilder->add('--prune'); + $this->arguments[] = '--prune'; } - $this->processBuilder->add($groupOrRemote); + $this->arguments[] = $groupOrRemote; return $this; } @@ -323,9 +358,9 @@ public function execute() public function getNames() { $remotes = $this->execute(); - $remotes = explode("\n", $remotes); - $remotes = array_map('trim', $remotes); - $remotes = array_filter($remotes); + $remotes = \explode("\n", $remotes); + $remotes = \array_map('trim', $remotes); + $remotes = \array_filter($remotes); return $remotes; } diff --git a/src/Command/ResetCommandBuilder.php b/src/Command/ResetCommandBuilder.php index 28a3f31..11235ca 100644 --- a/src/Command/ResetCommandBuilder.php +++ b/src/Command/ResetCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -24,14 +25,16 @@ /** * Reset command builder. */ -class ResetCommandBuilder extends AbstractCommandBuilder +class ResetCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('reset'); + $this->arguments[] = 'reset'; } /** @@ -41,7 +44,7 @@ protected function initializeProcessBuilder() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -52,7 +55,7 @@ public function quiet() */ public function patch() { - $this->processBuilder->add('--patch'); + $this->arguments[] = '--patch'; return $this; } @@ -63,7 +66,7 @@ public function patch() */ public function soft() { - $this->processBuilder->add('--soft'); + $this->arguments[] = '--soft'; return $this; } @@ -74,7 +77,7 @@ public function soft() */ public function mixed() { - $this->processBuilder->add('--mixed'); + $this->arguments[] = '--mixed'; return $this; } @@ -85,7 +88,7 @@ public function mixed() */ public function hard() { - $this->processBuilder->add('--hard'); + $this->arguments[] = '--hard'; return $this; } @@ -96,7 +99,7 @@ public function hard() */ public function merge() { - $this->processBuilder->add('--merge'); + $this->arguments[] = '--merge'; return $this; } @@ -107,7 +110,7 @@ public function merge() */ public function keep() { - $this->processBuilder->add('--keep'); + $this->arguments[] = '--keep'; return $this; } @@ -120,7 +123,7 @@ public function keep() */ public function commit($commit) { - $this->processBuilder->add($commit); + $this->arguments[] = $commit; return $this; } @@ -139,10 +142,10 @@ public function commit($commit) */ public function execute($path = null, $_ = null) { - $this->processBuilder->add('--'); - foreach (func_get_args() as $path) { - $this->processBuilder->add($path); + $this->arguments[] = '--'; + foreach (\func_get_args() as $path) { + $this->arguments[] = $path; } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/RevParseCommandBuilder.php b/src/Command/RevParseCommandBuilder.php index 3cbe80e..ac47b7a 100644 --- a/src/Command/RevParseCommandBuilder.php +++ b/src/Command/RevParseCommandBuilder.php @@ -13,9 +13,11 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Radek Crlik + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +25,13 @@ /** * Rev-parse command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class RevParseCommandBuilder extends AbstractCommandBuilder +class RevParseCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const ABBREV_REF_STRICT = 'strict'; const ABBREV_REF_LOOSE = 'loose'; @@ -35,7 +41,7 @@ class RevParseCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('rev-parse'); + $this->arguments[] = 'rev-parse'; } /** @@ -45,7 +51,7 @@ protected function initializeProcessBuilder() */ public function parseopt() { - $this->processBuilder->add('--parseopt'); + $this->arguments[] = '--parseopt'; return $this; } @@ -56,7 +62,7 @@ public function parseopt() */ public function keepDashDash() { - $this->processBuilder->add('--keep-dashdash'); + $this->arguments[] = '--keep-dashdash'; return $this; } @@ -67,7 +73,7 @@ public function keepDashDash() */ public function stopAtNonOption() { - $this->processBuilder->add('--stop-at-non-option'); + $this->arguments[] = '--stop-at-non-option'; return $this; } @@ -78,7 +84,7 @@ public function stopAtNonOption() */ public function stuckLong() { - $this->processBuilder->add('--stuck-long'); + $this->arguments[] = '--stuck-long'; return $this; } @@ -89,7 +95,7 @@ public function stuckLong() */ public function sqQuote() { - $this->processBuilder->add('--sq-quote'); + $this->arguments[] = '--sq-quote'; return $this; } @@ -100,7 +106,7 @@ public function sqQuote() */ public function revsOnly() { - $this->processBuilder->add('--revs-only'); + $this->arguments[] = '--revs-only'; return $this; } @@ -111,7 +117,7 @@ public function revsOnly() */ public function noRevs() { - $this->processBuilder->add('--no-revs'); + $this->arguments[] = '--no-revs'; return $this; } @@ -122,7 +128,7 @@ public function noRevs() */ public function flags() { - $this->processBuilder->add('--flags'); + $this->arguments[] = '--flags'; return $this; } @@ -133,7 +139,7 @@ public function flags() */ public function noFlags() { - $this->processBuilder->add('--no-flags'); + $this->arguments[] = '--no-flags'; return $this; } @@ -146,7 +152,8 @@ public function noFlags() */ public function defaultRev($arg) { - $this->processBuilder->add('--default')->add($arg); + $this->arguments[] = '--default'; + $this->arguments[] = $arg; return $this; } @@ -159,7 +166,8 @@ public function defaultRev($arg) */ public function prefix($arg) { - $this->processBuilder->add('--prefix')->add($arg); + $this->arguments[] = '--prefix'; + $this->arguments[] = $arg; return $this; } @@ -170,7 +178,7 @@ public function prefix($arg) */ public function verify() { - $this->processBuilder->add('--verify'); + $this->arguments[] = '--verify'; return $this; } @@ -181,7 +189,7 @@ public function verify() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -194,7 +202,7 @@ public function quiet() */ public function sq() { - $this->processBuilder->add('--sq'); + $this->arguments[] = '--sq'; return $this; } @@ -205,7 +213,7 @@ public function sq() */ public function not() { - $this->processBuilder->add('--not'); + $this->arguments[] = '--not'; return $this; } @@ -218,7 +226,7 @@ public function not() */ public function abbrevRef($abbrev = null) { - $this->processBuilder->add('--abbref-ref' . ($abbrev ? '=' . $abbrev : '')); + $this->arguments[] = '--abbrev-ref' . ($abbrev ? '=' . $abbrev : ''); return $this; } @@ -231,7 +239,7 @@ public function abbrevRef($abbrev = null) */ public function short($number = null) { - $this->processBuilder->add('--short' . ($number ? '=' . $number : '')); + $this->arguments[] = '--short' . ($number ? '=' . $number : ''); return $this; } @@ -242,7 +250,7 @@ public function short($number = null) */ public function symbolic() { - $this->processBuilder->add('--symbolic'); + $this->arguments[] = '--symbolic'; return $this; } @@ -253,7 +261,7 @@ public function symbolic() */ public function symbolicFullName() { - $this->processBuilder->add('--symbolic-full-name'); + $this->arguments[] = '--symbolic-full-name'; return $this; } @@ -264,7 +272,7 @@ public function symbolicFullName() */ public function all() { - $this->processBuilder->add('--all'); + $this->arguments[] = '--all'; return $this; } @@ -277,7 +285,7 @@ public function all() */ public function branches($pattern) { - $this->processBuilder->add('--branches=' . $pattern); + $this->arguments[] = '--branches=' . $pattern; return $this; } @@ -290,7 +298,7 @@ public function branches($pattern) */ public function tags($pattern) { - $this->processBuilder->add('--tags=' . $pattern); + $this->arguments[] = '--tags=' . $pattern; return $this; } @@ -303,7 +311,7 @@ public function tags($pattern) */ public function remotes($pattern) { - $this->processBuilder->add('--remotes=' . $pattern); + $this->arguments[] = '--remotes=' . $pattern; return $this; } @@ -316,7 +324,7 @@ public function remotes($pattern) */ public function glob($pattern) { - $this->processBuilder->add('--glob=' . $pattern); + $this->arguments[] = '--glob=' . $pattern; return $this; } @@ -329,7 +337,7 @@ public function glob($pattern) */ public function exclude($pattern) { - $this->processBuilder->add('--exclude=' . $pattern); + $this->arguments[] = '--exclude=' . $pattern; return $this; } @@ -342,7 +350,7 @@ public function exclude($pattern) */ public function disambiguate($prefix) { - $this->processBuilder->add('--disambiguate=' . $prefix); + $this->arguments[] = '--disambiguate=' . $prefix; return $this; } @@ -358,7 +366,7 @@ public function since($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--since=' . $date); + $this->arguments[] = '--since=' . $date; return $this; } @@ -374,7 +382,7 @@ public function after($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--after=' . $date); + $this->arguments[] = '--after=' . $date; return $this; } @@ -390,7 +398,7 @@ public function until($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--until=' . $date); + $this->arguments[] = '--until=' . $date; return $this; } @@ -406,7 +414,7 @@ public function before($date) if ($date instanceof \DateTime) { $date = $date->format('Y-m-d H:i:s'); } - $this->processBuilder->add('--before=' . $date); + $this->arguments[] = '--before=' . $date; return $this; } @@ -425,9 +433,9 @@ public function before($date) */ public function execute($arg = null, $_ = null) { - foreach (func_get_args() as $arg) { - $this->processBuilder->add($arg); + foreach (\func_get_args() as $arg) { + $this->arguments[] = $arg; } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/RmCommandBuilder.php b/src/Command/RmCommandBuilder.php index 3559608..3911aef 100644 --- a/src/Command/RmCommandBuilder.php +++ b/src/Command/RmCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -24,14 +25,16 @@ /** * Rm command builder. */ -class RmCommandBuilder extends AbstractCommandBuilder +class RmCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('rm'); + $this->arguments[] = 'rm'; } /** @@ -41,7 +44,7 @@ protected function initializeProcessBuilder() */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -52,7 +55,7 @@ public function force() */ public function dryRun() { - $this->processBuilder->add('--dry-run'); + $this->arguments[] = '--dry-run'; return $this; } @@ -63,7 +66,7 @@ public function dryRun() */ public function recursive() { - $this->processBuilder->add('-r'); + $this->arguments[] = '-r'; return $this; } @@ -74,7 +77,7 @@ public function recursive() */ public function cached() { - $this->processBuilder->add('--cached'); + $this->arguments[] = '--cached'; return $this; } @@ -85,7 +88,7 @@ public function cached() */ public function ignoreUnmatch() { - $this->processBuilder->add('--ignore-unmatch'); + $this->arguments[] = '--ignore-unmatch'; return $this; } @@ -96,7 +99,7 @@ public function ignoreUnmatch() */ public function quiet() { - $this->processBuilder->add('--quiet'); + $this->arguments[] = '--quiet'; return $this; } @@ -115,13 +118,13 @@ public function quiet() */ public function execute($pathspec = null, $_ = null) { - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathspec) { - $this->processBuilder->add($pathspec); + $this->arguments[] = $pathspec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/ShortLogCommandBuilder.php b/src/Command/ShortLogCommandBuilder.php index 80aaa05..a871d9a 100644 --- a/src/Command/ShortLogCommandBuilder.php +++ b/src/Command/ShortLogCommandBuilder.php @@ -13,10 +13,10 @@ * @package bit3/git-php * @author David Molineus * @author Christian Schiffler - * @author Tristan Lins - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -25,14 +25,16 @@ /** * ShortLog command builder. */ -class ShortLogCommandBuilder extends AbstractCommandBuilder +class ShortLogCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('shortlog'); + $this->arguments[] = 'shortlog'; } /** @@ -42,7 +44,7 @@ protected function initializeProcessBuilder() */ public function numbered() { - $this->processBuilder->add('--numbered'); + $this->arguments[] = '--numbered'; return $this; } @@ -54,7 +56,7 @@ public function numbered() */ public function summary() { - $this->processBuilder->add('--summary'); + $this->arguments[] = '--summary'; return $this; } @@ -66,7 +68,7 @@ public function summary() */ public function email() { - $this->processBuilder->add('--email'); + $this->arguments[] = '--email'; return $this; } @@ -80,7 +82,7 @@ public function email() */ public function format($format) { - $this->processBuilder->add('--format=' . $format); + $this->arguments[] = '--format=' . $format; return $this; } @@ -94,7 +96,7 @@ public function format($format) */ public function revisionRange($revisionRange) { - $this->processBuilder->add($revisionRange); + $this->arguments[] = $revisionRange; return $this; } @@ -129,7 +131,7 @@ public function w($width, $indent1 = null, $indent2 = null) } } - $this->processBuilder->add('-w' . $width); + $this->arguments[] = '-w' . $width; return $this; } @@ -149,14 +151,14 @@ public function w($width, $indent1 = null, $indent2 = null) */ public function execute($pathSpec = null, $_ = null) { - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathSpec) { - $this->processBuilder->add($pathSpec); + $this->arguments[] = $pathSpec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/ShowCommandBuilder.php b/src/Command/ShowCommandBuilder.php index c896c7c..020577e 100644 --- a/src/Command/ShowCommandBuilder.php +++ b/src/Command/ShowCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,15 +24,19 @@ /** * Show command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class ShowCommandBuilder extends AbstractCommandBuilder +class ShowCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + /** * {@inheritDoc} */ protected function initializeProcessBuilder() { - $this->processBuilder->add('show'); + $this->arguments[] = 'show'; } /** @@ -43,7 +48,7 @@ protected function initializeProcessBuilder() */ public function pretty($format = null) { - $this->processBuilder->add('--pretty' . ($format ? '=' . $format : '')); + $this->arguments[] = '--pretty' . ($format ? '=' . $format : ''); return $this; } @@ -56,7 +61,7 @@ public function pretty($format = null) */ public function format($format) { - $this->processBuilder->add('--format=' . $format); + $this->arguments[] = '--format=' . $format; return $this; } @@ -67,7 +72,7 @@ public function format($format) */ public function abbrevCommit() { - $this->processBuilder->add('--abbrev-commit'); + $this->arguments[] = '--abbrev-commit'; return $this; } @@ -78,7 +83,7 @@ public function abbrevCommit() */ public function noAbbrevCommit() { - $this->processBuilder->add('--no-abbrev-commit'); + $this->arguments[] = '--no-abbrev-commit'; return $this; } @@ -89,7 +94,7 @@ public function noAbbrevCommit() */ public function oneline() { - $this->processBuilder->add('--oneline'); + $this->arguments[] = '--oneline'; return $this; } @@ -102,7 +107,7 @@ public function oneline() */ public function encoding($encoding) { - $this->processBuilder->add('--encoding=' . $encoding); + $this->arguments[] = '--encoding=' . $encoding; return $this; } @@ -115,7 +120,7 @@ public function encoding($encoding) */ public function notes($ref = null) { - $this->processBuilder->add('--notes' . ($ref ? '=' . $ref : '')); + $this->arguments[] = '--notes' . ($ref ? '=' . $ref : ''); return $this; } @@ -126,7 +131,7 @@ public function notes($ref = null) */ public function noNotes() { - $this->processBuilder->add('--no-notes'); + $this->arguments[] = '--no-notes'; return $this; } @@ -139,7 +144,7 @@ public function noNotes() */ public function showNotes($ref = null) { - $this->processBuilder->add('--show-notes' . ($ref ? '=' . $ref : '')); + $this->arguments[] = '--show-notes' . ($ref ? '=' . $ref : ''); return $this; } @@ -150,7 +155,7 @@ public function showNotes($ref = null) */ public function standardNotes() { - $this->processBuilder->add('--standard-notes'); + $this->arguments[] = '--standard-notes'; return $this; } @@ -161,7 +166,7 @@ public function standardNotes() */ public function noStandardNotes() { - $this->processBuilder->add('--no-standard-notes'); + $this->arguments[] = '--no-standard-notes'; return $this; } @@ -172,7 +177,7 @@ public function noStandardNotes() */ public function showSignature() { - $this->processBuilder->add('--show-signature'); + $this->arguments[] = '--show-signature'; return $this; } @@ -183,7 +188,7 @@ public function showSignature() */ public function noPatch() { - $this->processBuilder->add('--no-patch'); + $this->arguments[] = '--no-patch'; return $this; } @@ -200,7 +205,7 @@ public function noPatch() */ public function execute($object) { - $this->processBuilder->add($object); - return parent::run(); + $this->arguments[] = $object; + return $this->run(); } } diff --git a/src/Command/StashCommandBuilder.php b/src/Command/StashCommandBuilder.php new file mode 100644 index 0000000..480a832 --- /dev/null +++ b/src/Command/StashCommandBuilder.php @@ -0,0 +1,244 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * This project is provided in good faith and hope to be usable by anyone. + * + * @package bit3/git-php + * @author Ahmad Marzouq + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins + * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php + * @filesource + */ + +namespace Bit3\GitPhp\Command; + +/** + * Stash command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ +class StashCommandBuilder implements CommandBuilderInterface +{ + use CommandBuilderTrait; + + /** + * {@inheritDoc} + */ + protected function initializeProcessBuilder() + { + $this->arguments[] = 'stash'; + } + + /** + * Adds a message to StashCommandBuilder + * + * @param string $message The stash message. + * + * @return StashCommandBuilder + */ + public function message($message) + { + $this->arguments[] = $message; + return $this; + } + + /** + * List stashes and return the results + * + * @param string $options Takes options applicable to the git log command. + * + * @return mixed + */ + public function listStash($options = null) + { + $this->arguments[] = 'list'; + if ($options) { + $this->arguments[] = $options; + } + return $this->run(); + } + + /** + * Show the changes recorded in the stash as a diff + * between the stashed state and its original parent. + * When no $stash is given, shows the latest one. + * + * @param int|null $stash Takes the stash number. + * + * @return mixed + */ + public function show($stash = null) + { + $this->arguments[] = 'show'; + if ($stash) { + $this->arguments[] = 'stash@{' . $stash . '}'; + } + return $this->run(); + } + + /** + * Remove a single stashed state from the stash list. + * When no $stash is given, it removes the latest one. + * + * @param int|null $stash Takes the stash number. + * + * @return mixed + */ + public function drop($stash = null) + { + $this->arguments[] = 'show'; + if ($stash) { + $this->arguments[] = 'stash@{' . $stash . '}'; + } + return $this->run(); + } + + /** + * Remove a single stashed state from the stash list + * and apply it on top of the current working tree state. + * + * @param int|null $stash Takes the stash number. + * + * @return mixed + */ + public function pop($stash = null) + { + $this->arguments[] = 'pop'; + if ($stash) { + $this->arguments[] = 'stash@{' . $stash . '}'; + } + return $this->run(); + } + + /** + * Like pop, but do not remove the state from the stash list. + * Unlike pop, $stash may be any commit that looks like a commit + * created by stash save or stash create. + * + * @param int|null $stash Takes the stash number. + * + * @return mixed + */ + public function apply($stash = null) + { + $this->arguments[] = 'pop'; + if ($stash) { + $this->arguments[] = 'stash@{' . $stash . '}'; + } + return $this->run(); + } + + + /** + * Creates and checks out a new branch named $branchname starting from the commit at + * which the $stash was originally created, + * applies the changes recorded in $stash to the new working tree and index. + * + * @param string $branchname The branch name. + * + * @param int|null $stash Takes the stash number. + * + * @return mixed + */ + public function branch($branchname, $stash = null) + { + $this->arguments[] = 'branch'; + $this->arguments[] = $branchname; + if ($stash) { + $this->arguments[] = 'stash@{' . $stash . '}'; + } + return $this->run(); + } + + + /** + * Remove all the stashed states. + * + * @return mixed + */ + public function clear() + { + $this->arguments[] = 'clear'; + return $this->run(); + } + + + /** + * Save your local modifications to a new stash, + * and run git reset --hard to revert them. + * The part is optional and gives + * the description along with the stashed state. + * + * @param string $message The stash message. + * + * @return mixed + */ + public function save($message = null) + { + $this->arguments[] = 'branch'; + if ($message) { + $this->arguments[] = $message; + } + return $this->run(); + } + + /** + * Create a stash (which is a regular commit object) + * and return its object name, + * without storing it anywhere in the ref namespace. + * + * @param string $message The stash message. + * + * @return mixed + */ + public function create($message = null) + { + $this->arguments[] = 'create'; + if ($message) { + $this->arguments[] = $message; + } + return $this->run(); + } + + /** + * Store a given stash created via git stash create + * (which is a dangling merge commit) in the stash ref, + * updating the stash reflog. + * + * @param string $message The stash message. + * + * @param null|string $commit The commit hash. + * + * @return mixed + */ + public function store($message = null, $commit = null) + { + $this->arguments[] = 'store'; + if ($message) { + $this->arguments[] = '--message '.$message; + } + if ($commit) { + $this->arguments[] = $commit; + } + return $this->run(); + } + /** + * Execute the command and return the result. + * to use with message function . + * + * @return mixed + */ + public function execute() + { + return $this->run(); + } +} diff --git a/src/Command/StatusCommandBuilder.php b/src/Command/StatusCommandBuilder.php index f954879..1f348c0 100644 --- a/src/Command/StatusCommandBuilder.php +++ b/src/Command/StatusCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Status command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class StatusCommandBuilder extends AbstractCommandBuilder +class StatusCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const UNTRACKED_FILES_NO = 'no'; const UNTRACKED_FILES_NORMAL = 'normal'; @@ -45,7 +50,7 @@ class StatusCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('status'); + $this->arguments[] = 'status'; } /** @@ -55,7 +60,7 @@ protected function initializeProcessBuilder() */ public function short() { - $this->processBuilder->add('--short'); + $this->arguments[] = '--short'; return $this; } @@ -66,7 +71,7 @@ public function short() */ public function branch() { - $this->processBuilder->add('--branch'); + $this->arguments[] = '--branch'; return $this; } @@ -77,7 +82,7 @@ public function branch() */ public function porcelain() { - $this->processBuilder->add('--porcelain'); + $this->arguments[] = '--porcelain'; return $this; } @@ -88,7 +93,7 @@ public function porcelain() */ public function long() { - $this->processBuilder->add('--long'); + $this->arguments[] = '--long'; return $this; } @@ -101,7 +106,7 @@ public function long() */ public function untrackedFiles($mode = null) { - $this->processBuilder->add('--untracked-files' . ($mode ? '=' . $mode : '')); + $this->arguments[] = '--untracked-files' . ($mode ? '=' . $mode : ''); return $this; } @@ -114,7 +119,7 @@ public function untrackedFiles($mode = null) */ public function ignoreSubmodules($when = null) { - $this->processBuilder->add('--ignore-submodules' . ($when ? '=' . $when : '')); + $this->arguments[] = '--ignore-submodules' . ($when ? '=' . $when : ''); return $this; } @@ -125,7 +130,7 @@ public function ignoreSubmodules($when = null) */ public function ignored() { - $this->processBuilder->add('--ignored'); + $this->arguments[] = '--ignored'; return $this; } @@ -138,7 +143,7 @@ public function ignored() */ public function z() { - $this->processBuilder->add('-z'); + $this->arguments[] = '-z'; return $this; } @@ -151,7 +156,7 @@ public function z() */ public function column($options = null) { - $this->processBuilder->add('--column' . ($options ? '=' . $options : '')); + $this->arguments[] = '--column' . ($options ? '=' . $options : ''); return $this; } @@ -162,7 +167,7 @@ public function column($options = null) */ public function noColumn() { - $this->processBuilder->add('--no-column'); + $this->arguments[] = '--no-column'; return $this; } @@ -193,22 +198,22 @@ public function getStatus($pathspec = null, $_ = null) { $this->porcelain(); - $status = call_user_func_array(array($this, 'execute'), func_get_args()); - $status = explode("\n", $status); + $status = \call_user_func_array([$this, 'execute'], \func_get_args()); + $status = \explode("\n", $status); - $files = array(); + $files = []; foreach ($status as $line) { - if (trim($line)) { - $index = trim(substr($line, 0, 1)); - $worktree = trim(substr($line, 1, 1)); + if (\trim($line)) { + $index = \trim(\substr($line, 0, 1)); + $worktree = \trim(\substr($line, 1, 1)); if ($index && $worktree) { - $file = trim(substr($line, 2)); - $files[$file] = array( + $file = \trim(\substr($line, 2)); + $files[$file] = [ 'index' => $index ?: false, 'worktree' => $worktree ?: false, - ); + ]; } } } @@ -240,17 +245,17 @@ public function getIndexStatus($pathspec = null, $_ = null) { $this->porcelain(); - $status = call_user_func_array(array($this, 'execute'), func_get_args()); - $status = explode("\n", $status); + $status = \call_user_func_array([$this, 'execute'], \func_get_args()); + $status = \explode("\n", $status); - $files = array(); + $files = []; foreach ($status as $line) { - if (trim($line)) { - $index = trim(substr($line, 0, 1)); + if ($line = \trim($line)) { + $index = \substr($line, 0, 1); if ($index) { - $file = trim(substr($line, 2)); + $file = \trim(\substr($line, 2)); $files[$file] = $index; } } @@ -283,17 +288,17 @@ public function getWorkTreeStatus($pathspec = null, $_ = null) { $this->porcelain(); - $status = call_user_func_array(array($this, 'execute'), func_get_args()); - $status = explode("\n", $status); + $status = \call_user_func_array([$this, 'execute'], \func_get_args()); + $status = \explode("\n", $status); - $files = array(); + $files = []; foreach ($status as $line) { - if (trim($line)) { - $worktree = trim(substr($line, 1, 1)); + if ($line = \trim($line)) { + $worktree = \trim(\substr($line, 1, 1)); if ($worktree) { - $file = trim(substr($line, 2)); + $file = \trim(\substr($line, 2)); $files[$file] = $worktree; } } @@ -317,13 +322,13 @@ public function getWorkTreeStatus($pathspec = null, $_ = null) */ public function execute($pathspec = null, $_ = null) { - $args = func_get_args(); - if (count($args)) { - $this->processBuilder->add('--'); + $args = \func_get_args(); + if (\count($args)) { + $this->arguments[] = '--'; foreach ($args as $pathspec) { - $this->processBuilder->add($pathspec); + $this->arguments[] = $pathspec; } } - return parent::run(); + return $this->run(); } } diff --git a/src/Command/TagCommandBuilder.php b/src/Command/TagCommandBuilder.php index 26e2bad..c089b99 100644 --- a/src/Command/TagCommandBuilder.php +++ b/src/Command/TagCommandBuilder.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -23,9 +24,13 @@ /** * Tag command builder. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class TagCommandBuilder extends AbstractCommandBuilder +class TagCommandBuilder implements CommandBuilderInterface { + use CommandBuilderTrait; + const CLEANUP_VERBATIM = 'verbatim'; const CLEANUP_WHITESPACE = 'whitespace'; @@ -51,7 +56,7 @@ class TagCommandBuilder extends AbstractCommandBuilder */ protected function initializeProcessBuilder() { - $this->processBuilder->add('tag'); + $this->arguments[] = 'tag'; } /** @@ -61,7 +66,7 @@ protected function initializeProcessBuilder() */ public function annotate() { - $this->processBuilder->add('--annotate'); + $this->arguments[] = '--annotate'; return $this; } @@ -72,8 +77,8 @@ public function annotate() */ public function sign() { - $this->signIsset = true; - $this->processBuilder->add('--sign'); + $this->signIsset = true; + $this->arguments[] = '--sign'; return $this; } @@ -87,7 +92,7 @@ public function sign() public function localUser($keyId) { $this->localUserIsset = true; - $this->processBuilder->add('--local-user=' . $keyId); + $this->arguments[] = '--local-user=' . $keyId; return $this; } @@ -98,7 +103,7 @@ public function localUser($keyId) */ public function force() { - $this->processBuilder->add('--force'); + $this->arguments[] = '--force'; return $this; } @@ -109,7 +114,7 @@ public function force() */ public function delete() { - $this->processBuilder->add('--delete'); + $this->arguments[] = '--delete'; return $this; } @@ -120,7 +125,7 @@ public function delete() */ public function verify() { - $this->processBuilder->add('--verify'); + $this->arguments[] = '--verify'; return $this; } @@ -135,7 +140,7 @@ public function verify() */ public function n($num) { - $this->processBuilder->add('-n' . $num); + $this->arguments[] = '-n' . $num; return $this; } @@ -150,7 +155,8 @@ public function n($num) */ public function l($pattern) { - $this->processBuilder->add('--list')->add($pattern); + $this->arguments[] = '--list'; + $this->arguments[] = $pattern; return $this; } @@ -163,7 +169,7 @@ public function l($pattern) */ public function column($options = null) { - $this->processBuilder->add('--column' . ($options ? '=' . $options : '')); + $this->arguments[] = '--column' . ($options ? '=' . $options : ''); return $this; } @@ -174,7 +180,7 @@ public function column($options = null) */ public function noColumn() { - $this->processBuilder->add('--no-column'); + $this->arguments[] = '--no-column'; return $this; } @@ -187,7 +193,8 @@ public function noColumn() */ public function contains($commit) { - $this->processBuilder->add('--contains')->add($commit); + $this->arguments[] = '--contains'; + $this->arguments[] = $commit; return $this; } @@ -200,7 +207,8 @@ public function contains($commit) */ public function pointsAt($object) { - $this->processBuilder->add('--points-at')->add($object); + $this->arguments[] = '--points-at'; + $this->arguments[] = $object; return $this; } @@ -213,7 +221,7 @@ public function pointsAt($object) */ public function message($message) { - $this->processBuilder->add('--message=' . $message); + $this->arguments[] = '--message=' . $message; return $this; } @@ -226,7 +234,7 @@ public function message($message) */ public function file($file) { - $this->processBuilder->add('--file=' . $file); + $this->arguments[] = '--file=' . $file; return $this; } @@ -239,7 +247,7 @@ public function file($file) */ public function cleanup($mode) { - $this->processBuilder->add('--cleanup=' . $mode); + $this->arguments[] = '--cleanup=' . $mode; return $this; } @@ -256,7 +264,7 @@ public function cleanup($mode) * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.CamelCaseParameterName) */ - public function execute($tagName, $commit = null) + public function execute($tagName = null, $commit = null) { if (!$this->signIsset && $this->repository->getConfig()->isSignTagsEnabled()) { $this->sign()->localUser($this->repository->getConfig()->getSignCommitUser()); @@ -266,12 +274,29 @@ public function execute($tagName, $commit = null) } } - $this->processBuilder->add($tagName); + if ($tagName) { + $this->arguments[] = $tagName; + } if ($commit) { - $this->processBuilder->add($commit); + $this->arguments[] = $commit; } - return parent::run(); + return $this->run(); + } + + /** + * Retrieve the tag names. + * + * @return string[] + */ + public function getNames() + { + $tags = $this->execute(); + $tags = \explode("\n", $tags); + $tags = \array_map('trim', $tags); + $tags = \array_filter($tags); + + return $tags; } } diff --git a/src/GitConfig.php b/src/GitConfig.php index 8d87916..9f5e183 100644 --- a/src/GitConfig.php +++ b/src/GitConfig.php @@ -13,16 +13,17 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ namespace Bit3\GitPhp; -use Bit3\NoOpLogger\NoOpLogger; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; /** * Shareable configuration for git repositories. @@ -41,14 +42,14 @@ class GitConfig * * @var string|null */ - protected $signCommitUser = null; + protected $signCommitUser; /** * ID of the GPG certificate to sign tags. * * @var string|null */ - protected $signTagUser = null; + protected $signTagUser; /** * Logger facility. @@ -62,7 +63,7 @@ class GitConfig */ public function __construct() { - $this->logger = new NoOpLogger(); + $this->logger = new NullLogger(); } /** diff --git a/src/GitException.php b/src/GitException.php index adb83a1..2dedd91 100644 --- a/src/GitException.php +++ b/src/GitException.php @@ -13,9 +13,10 @@ * @package bit3/git-php * @author Tristan Lins * @author Christian Schiffler - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -130,8 +131,8 @@ public function getErrorOutput() public static function createFromProcess($message, Process $process) { return new static( - sprintf('%s [%s]', $message, $process->getCommandLine()) . - PHP_EOL . sprintf('work dir: %s', $process->getWorkingDirectory()) . + \sprintf('%s [%s]', $message, $process->getCommandLine()) . + PHP_EOL . \sprintf('work dir: %s', $process->getWorkingDirectory()) . PHP_EOL . $process->getErrorOutput(), $process->getWorkingDirectory(), $process->getCommandLine(), diff --git a/src/GitRepository.php b/src/GitRepository.php index fcd235f..20804cc 100644 --- a/src/GitRepository.php +++ b/src/GitRepository.php @@ -15,9 +15,12 @@ * @author Christian Schiffler * @author David Molineus * @author Aaron Rubin - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Matthew Gamble + * @author Ahmad Marzouq + * @author Sven Baumann + * @copyright 2014-2018 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ @@ -26,6 +29,7 @@ use Bit3\GitPhp\Command\AddCommandBuilder; use Bit3\GitPhp\Command\BranchCommandBuilder; use Bit3\GitPhp\Command\CheckoutCommandBuilder; +use Bit3\GitPhp\Command\ConfigCommandBuilder; use Bit3\GitPhp\Command\MergeCommandBuilder; use Bit3\GitPhp\Command\CloneCommandBuilder; use Bit3\GitPhp\Command\CommitCommandBuilder; @@ -43,9 +47,13 @@ use Bit3\GitPhp\Command\ShowCommandBuilder; use Bit3\GitPhp\Command\StatusCommandBuilder; use Bit3\GitPhp\Command\TagCommandBuilder; +use Bit3\GitPhp\Command\PullCommandBuilder; +use Bit3\GitPhp\Command\StashCommandBuilder; /** * GIT repository adapter. + * + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class GitRepository { @@ -103,7 +111,7 @@ public function getConfig() */ public function isInitialized() { - return is_dir($this->repositoryPath . DIRECTORY_SEPARATOR . '.git'); + return \is_dir($this->repositoryPath . DIRECTORY_SEPARATOR . '.git'); } /** @@ -126,6 +134,16 @@ public function cloneRepository() return new CloneCommandBuilder($this); } + /** + * Create a config command. + * + * @return ConfigCommandBuilder + */ + public function config() + { + return new ConfigCommandBuilder($this); + } + /** * Create a remote command. * @@ -307,4 +325,24 @@ public function merge() { return new MergeCommandBuilder($this); } + + /** + * Create Pull command. + * + * @return PullCommandBuilder + */ + public function pull() + { + return new PullCommandBuilder($this); + } + + /** + * Create stash command. + * + * @return StashCommandBuilder + */ + public function stash() + { + return new StashCommandBuilder($this); + } } diff --git a/tests/GitRepositoryTest.php b/tests/GitRepositoryTest.php index 9ec66cd..ec1268f 100644 --- a/tests/GitRepositoryTest.php +++ b/tests/GitRepositoryTest.php @@ -12,22 +12,26 @@ * * @package bit3/git-php * @author Tristan Lins - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php + * @author Christian Schiffler + * @author Matthew Gamble + * @author Sven Baumann + * @copyright 2014-2022 Tristan Lins * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT + * @link https://github.com/bit3/git-php * @filesource */ namespace Bit3\GitPhp\Test; use Bit3\GitPhp\GitRepository; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * GIT repository unit tests. */ -class GitRepositoryTest extends \PHPUnit_Framework_TestCase +class GitRepositoryTest extends TestCase { /** * @var string @@ -51,13 +55,13 @@ class GitRepositoryTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->initializedRepositoryPath = tempnam(sys_get_temp_dir(), 'git_'); - unlink($this->initializedRepositoryPath); - mkdir($this->initializedRepositoryPath); + $this->initializedRepositoryPath = \tempnam(\sys_get_temp_dir(), 'git_'); + \unlink($this->initializedRepositoryPath); + \mkdir($this->initializedRepositoryPath); - $this->uninitializedRepositoryPath = tempnam(sys_get_temp_dir(), 'git_'); - unlink($this->uninitializedRepositoryPath); - mkdir($this->uninitializedRepositoryPath); + $this->uninitializedRepositoryPath = \tempnam(\sys_get_temp_dir(), 'git_'); + \unlink($this->uninitializedRepositoryPath); + \mkdir($this->uninitializedRepositoryPath); $zip = new \ZipArchive(); $zip->open(__DIR__ . DIRECTORY_SEPARATOR . 'git.zip'); @@ -116,7 +120,97 @@ public function testInit() $this->uninitializedGitRepository->init()->execute(); $this->assertTrue( - is_dir($this->uninitializedRepositoryPath . DIRECTORY_SEPARATOR . '.git') + \is_dir($this->uninitializedRepositoryPath . DIRECTORY_SEPARATOR . '.git') + ); + } + + /** + * @covers \Bit3\GitPhp\GitRepository::config + * @covers \Bit3\GitPhp\Command\ConfigCommandBuilder::execute + * @covers \Bit3\GitPhp\Command\ConfigCommandBuilder::get + */ + public function testConfigGetOnInitializedRepository() + { + $this->assertEquals( + 'false', + $this->initializedGitRepository->config()->file('local')->execute('core.bare') + ); + $this->assertEquals( + 'CCA unittest', + $this->initializedGitRepository->config()->file('local')->get('user.name')->execute() + ); + } + + /** + * @covers \Bit3\GitPhp\GitRepository::config + * @covers \Bit3\GitPhp\Command\ConfigCommandBuilder + */ + public function testConfigGetOnUnitializedRepository() + { + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + + $this->uninitializedGitRepository->config()->file('local')->execute('core.bare'); + $this->uninitializedGitRepository->config()->file('local')->get('user.name')->execute(); + } + + public function testConfigSetOnInitializedRepository() + { + $this->initializedGitRepository->config()->file('local')->execute('user.name', 'CCA unittest 2'); + + $process = new Process(['git', 'config', '--local', 'user.name'], $this->initializedRepositoryPath); + $process->run(); + + $this->assertEquals( + 'CCA unittest 2', + trim($process->getOutput()) + ); + } + + public function testConfigAddOnInitializedRepository() + { + $this->initializedGitRepository->config()->file('local')->add('user.name', 'CCA unittest 2')->execute(); + + $process = new Process( + ['git', 'config', '--local', '--get-all', 'user.name'], $this->initializedRepositoryPath + ); + $process->run(); + + $names = \explode("\n", $process->getOutput()); + $names = \array_map('trim', $names); + $names = \array_filter($names); + + $this->assertEquals( + ['CCA unittest', 'CCA unittest 2'], + $names + ); + } + + public function testConfigGetAllOnInitializedRepository() + { + $values = $this->initializedGitRepository->config()->file('local')->getAll('gitphp.test2')->execute(); + + $values = \explode("\n", $values); + $values = \array_map('trim', $values); + $values = \array_filter($values); + + $this->assertEquals( + ['aa123', 'ab234', 'ac345', 'bb234'], + $values + ); + + $values = $this->initializedGitRepository->config()->file('local')->getAll('gitphp.test2', '^a.+3.+$')->execute(); + + $values = \explode("\n", $values); + $values = \array_map('trim', $values); + $values = \array_filter($values); + + $this->assertEquals( + ['ab234', 'ac345'], + $values ); } @@ -127,7 +221,7 @@ public function testInit() public function testListRemotesOnInitializedRepository() { $this->assertEquals( - array('local'), + ['local'], $this->initializedGitRepository->remote()->getNames() ); } @@ -138,7 +232,12 @@ public function testListRemotesOnInitializedRepository() */ public function testListRemotesOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->remote()->getNames(); } @@ -150,11 +249,11 @@ public function testListRemotesOnUninitializedRepository() public function testListBranchesOnInitializedRepository() { $this->assertEquals( - array('master'), + ['master'], $this->initializedGitRepository->branch()->getNames() ); $this->assertEquals( - array('master', 'remotes/local/master'), + ['master', 'remotes/local/master'], $this->initializedGitRepository->branch()->all()->getNames() ); } @@ -165,7 +264,12 @@ public function testListBranchesOnInitializedRepository() */ public function testListBranchesOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->branch()->getNames(); } @@ -197,7 +301,12 @@ public function testDescribeOnInitializedRepository() */ public function testDescribeOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->describe()->execute(); } @@ -210,13 +319,11 @@ public function testRemoteSetUrlOnInitializedRepository() { $this->initializedGitRepository->remote()->setUrl('local', $this->uninitializedRepositoryPath)->execute(); - $process = ProcessBuilder::create(array('git', 'config', 'remote.local.url')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'config', 'remote.local.url'], $this->initializedRepositoryPath); $process->run(); $this->assertEquals( - trim($process->getOutput()), + \trim($process->getOutput()), $this->uninitializedRepositoryPath ); } @@ -228,7 +335,12 @@ public function testRemoteSetUrlOnInitializedRepository() */ public function testRemoteSetUrlOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->remote()->setUrl('local', $this->initializedRepositoryPath)->execute(); } @@ -241,23 +353,19 @@ public function testRemoteSetPushUrlOnInitializedRepository() { $this->initializedGitRepository->remote()->setPushUrl('local', $this->uninitializedRepositoryPath)->execute(); - $process = ProcessBuilder::create(array('git', 'config', 'remote.local.url')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'config', 'remote.local.url'], $this->initializedRepositoryPath); $process->run(); $this->assertEquals( - trim($process->getOutput()), + \trim($process->getOutput()), '/tmp/git' ); - $process = ProcessBuilder::create(array('git', 'config', 'remote.local.pushurl')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'config', 'remote.local.pushurl'], $this->initializedRepositoryPath); $process->run(); $this->assertEquals( - trim($process->getOutput()), + \trim($process->getOutput()), $this->uninitializedRepositoryPath ); } @@ -269,7 +377,12 @@ public function testRemoteSetPushUrlOnInitializedRepository() */ public function testRemoteSetPushUrlOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->remote()->setPushUrl('local', $this->initializedRepositoryPath)->execute(); } @@ -282,9 +395,7 @@ public function testRemoteAddOnInitializedRepository() { $this->initializedGitRepository->remote()->add('origin', $this->uninitializedRepositoryPath)->execute(); - $process = ProcessBuilder::create(array('git', 'config', 'remote.origin.url')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'config', 'remote.origin.url'], $this->initializedRepositoryPath); $process->run(); $this->assertEquals( @@ -300,7 +411,12 @@ public function testRemoteAddOnInitializedRepository() */ public function testRemoteAddOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->remote()->add('origin', $this->initializedRepositoryPath)->execute(); } @@ -310,16 +426,14 @@ public function testRemoteAddOnUninitializedRepository() */ public function testRemoteFetchOnInitializedRepository() { - $process = ProcessBuilder::create(array('git', 'remote', 'add', 'origin', $this->initializedRepositoryPath)) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process( + ['git', 'remote', 'add', 'origin', $this->initializedRepositoryPath], $this->initializedRepositoryPath + ); $process->run(); $this->initializedGitRepository->fetch()->execute(); - $process = ProcessBuilder::create(array('git', 'branch', '-a')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'branch', '-a'], $this->initializedRepositoryPath); $process->run(); $branches = explode("\n", $process->getOutput()); @@ -327,7 +441,7 @@ public function testRemoteFetchOnInitializedRepository() $branches = array_filter($branches); $this->assertTrue( - in_array('remotes/origin/master', $branches) + \in_array('remotes/origin/master', $branches) ); } @@ -337,7 +451,12 @@ public function testRemoteFetchOnInitializedRepository() */ public function testRemoteFetchOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->fetch()->execute(); } @@ -347,20 +466,18 @@ public function testRemoteFetchOnUninitializedRepository() */ public function testCheckoutOnInitializedRepository() { - $process = ProcessBuilder::create(array('git', 'remote', 'add', 'origin', $this->initializedRepositoryPath)) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process( + ['git', 'remote', 'add', 'origin', $this->initializedRepositoryPath], $this->initializedRepositoryPath + ); $process->run(); $this->initializedGitRepository->checkout()->execute('6c42d7ba78e0e956bd4e25661a6c13d826ef590a'); - $process = ProcessBuilder::create(array('git', 'describe')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'describe'], $this->initializedRepositoryPath); $process->run(); $this->assertEquals( - trim($process->getOutput()), + \trim($process->getOutput()), 'annotated-tag' ); } @@ -371,7 +488,12 @@ public function testCheckoutOnInitializedRepository() */ public function testCheckoutOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->checkout()->execute('foo'); } @@ -386,7 +508,12 @@ public function testPushOnInitializedRepository() */ public function testPushOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->push()->execute('foo'); } @@ -399,10 +526,10 @@ public function testStatusOnInitializedRepository() $status = $this->initializedGitRepository->status()->getStatus(); $this->assertEquals( - array( - 'removed-but-staged.txt' => array('index' => 'A', 'worktree' => 'D'), - 'unknown-file.txt' => array('index' => '?', 'worktree' => '?'), - ), + [ + 'removed-but-staged.txt' => ['index' => 'A', 'worktree' => 'D'], + 'unknown-file.txt' => ['index' => '?', 'worktree' => '?'], + ], $status ); } @@ -413,7 +540,12 @@ public function testStatusOnInitializedRepository() */ public function testStatusOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->status()->getStatus(); } @@ -425,16 +557,14 @@ public function testAddOnInitializedRepository() { $this->initializedGitRepository->add()->execute('unknown-file.txt'); - $process = ProcessBuilder::create(array('git', 'status', '-s')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'status', '-s'], $this->initializedRepositoryPath); $process->run(); - $status = explode("\n", $process->getOutput()); - $status = array_map('trim', $status); + $status = \explode("\n", $process->getOutput()); + $status = \array_map('trim', $status); $this->assertTrue( - in_array('A unknown-file.txt', $status) + \in_array('A unknown-file.txt', $status) ); } @@ -444,7 +574,12 @@ public function testAddOnInitializedRepository() */ public function testAddOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->add()->execute('unknown-file.txt'); } @@ -456,16 +591,14 @@ public function testRmOnInitializedRepository() { $this->initializedGitRepository->rm()->execute('existing-file.txt'); - $process = ProcessBuilder::create(array('git', 'status', '-s')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'status', '-s'], $this->initializedRepositoryPath); $process->run(); - $status = explode("\n", $process->getOutput()); - $status = array_map('trim', $status); + $status = \explode("\n", $process->getOutput()); + $status = \array_map('trim', $status); $this->assertTrue( - in_array('D existing-file.txt', $status) + \in_array('D existing-file.txt', $status) ); } @@ -475,7 +608,12 @@ public function testRmOnInitializedRepository() */ public function testRmOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->rm()->execute('existing-file.txt'); } @@ -488,21 +626,19 @@ public function testCommitOnInitializedRepository() { $this->initializedGitRepository->commit()->message('Commit changes')->execute(); - $process = ProcessBuilder::create(array('git', 'status', '-s')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'status', '-s'], $this->initializedRepositoryPath); $process->run(); - $status = explode("\n", $process->getOutput()); - $status = array_map('trim', $status); - $status = array_filter($status); + $status = \explode("\n", $process->getOutput()); + $status = \array_map('trim', $status); + $status = \array_filter($status); $this->assertEquals( - array( + [ 'D existing-file.txt', 'D removed-but-staged.txt', '?? unknown-file.txt', - ), + ], $status ); } @@ -514,7 +650,12 @@ public function testCommitOnInitializedRepository() */ public function testCommitOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->commit()->message('Commit changes')->execute(); } @@ -526,17 +667,15 @@ public function testTagOnInitializedRepository() { $this->initializedGitRepository->tag()->execute('unit-test'); - $process = ProcessBuilder::create(array('git', 'tag')) - ->setWorkingDirectory($this->initializedRepositoryPath) - ->getProcess(); + $process = new Process(['git', 'tag'], $this->initializedRepositoryPath); $process->run(); - $tags = explode("\n", $process->getOutput()); - $tags = array_map('trim', $tags); - $tags = array_filter($tags); + $tags = \explode("\n", $process->getOutput()); + $tags = \array_map('trim', $tags); + $tags = \array_filter($tags); $this->assertTrue( - in_array('unit-test', $tags) + \in_array('unit-test', $tags) ); } @@ -546,7 +685,12 @@ public function testTagOnInitializedRepository() */ public function testTagOnUninitializedRepository() { - $this->setExpectedException('Bit3\GitPhp\GitException'); + if (\method_exists($this, 'setExpectedException')) { + $this->setExpectedException('Bit3\GitPhp\GitException'); + } else { + $this->expectException('Bit3\GitPhp\GitException'); + } + $this->uninitializedGitRepository->tag()->execute('unit-test'); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 598d394..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * This project is provided in good faith and hope to be usable by anyone. - * - * @package bit3/git-php - * @author Tristan Lins - * @copyright 2014 Tristan Lins - * @link https://github.com/bit3/git-php - * @license https://github.com/bit3/git-php/blob/master/LICENSE MIT - * @filesource - */ - -error_reporting(E_ALL); - -function includeIfExists($file) -{ - return file_exists($file) ? include $file : false; -} - -if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) { - echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL. - 'curl -sS https://getcomposer.org/installer | php'.PHP_EOL. - 'php composer.phar install'.PHP_EOL; - exit(1); -} diff --git a/tests/git.zip b/tests/git.zip index 151da0f..a820367 100644 Binary files a/tests/git.zip and b/tests/git.zip differ