diff --git a/.travis.yml b/.travis.yml index a27e266..55a68c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,13 @@ language: php +git: + depth: 5 + quiet: true before_script: - composer install - cd tests php: - - 7.2 - - 7.3 + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 diff --git a/README.md b/README.md index 7d26092..0fc269c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # CommandoX -## PHP 7.2+ CLI Manager +## PHP 5.4-7.1 CLI Manager [![Build Status](https://secure.travis-ci.org/tolidano/commandox.png?branch=master)](http://travis-ci.org/tolidano/commandox) CommandoX is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for command line use. -This is a PHP 7.2+ port of Nate Good's abandoned Commando project available here: (https://www.github.com/nategood/commando) +This is a PHP 5.4-7.1 port of Nate Good's abandoned Commando project available here: (https://www.github.com/nategood/commando) ## Why? @@ -13,7 +13,7 @@ PHP's [`getopt`](http://php.net/manual/en/function.getopt.php) is not a signific ## Installation -*CommandoX requires that you are running PHP 7.2 or higher.* +*CommandoX requires that you are running PHP 5.4 - PHP 7.1.* CommandoX is [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compliant and can be installed using [Composer](http://getcomposer.org/). Add `tolidano/commandox` to your `composer.json` @@ -34,7 +34,7 @@ If you're new to Composer... Here is an example of a PHP CommandoX script that gives a decent tour of CommandoX's features: ``` php - for increment options help text -- Fix non-empty getArgumentValues array -- Allow subclassing of Command -- Make tput OS-aware -- Help now works with -h as well (conflicts with existing -h flags) +### v0.5.0 (Multiple Breaking Changes) + + - Upgrade to PHP 5.4, support up to 7.1 + - remove PHP 5.3 from travis CI yaml / testing + - add didShowHelp method + - remove all die/exit statements, return valid exit codes instead + - Port to new packagist under tolidano/commandox + - Port to new GitHub repository under tolidano/commandox + - Correct dedupeFlags bug (ensures each option/alias is seen exactly once) + - Use title in help and error messages when defined for anonymous arguments + - Constant refactoring + - Omit `` for increment options help text + - Fix non-empty getArgumentValues array + - Allow subclassing of Command + - Make tput OS-aware + - Help now works with -h as well (conflicts with existing -h flags) ### v0.2.9 diff --git a/composer.json b/composer.json index 96c306f..0772e2b 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,9 @@ "email": "shawn@tolidano.com" } ], - "require-dev": { - "phpmd/phpmd": "2.*", - "sebastian/phpcpd": "4.*", - "squizlabs/php_codesniffer": "3.*" - }, "require": { - "php": ">=7.2", + "php": ">=5.4", "kevinlebrun/colors.php": "1.0.*" - }, "autoload": { "psr-0": {"CommandoX": "src/"} diff --git a/composer.lock b/composer.lock index 022c8d9..fd65ef5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c533b1a3551f1dd9f67bb61037c01ad2", + "content-hash": "fc74ee83568fac5a40cdb0799a13ea46", "packages": [ { "name": "kevinlebrun/colors.php", @@ -58,987 +58,14 @@ "time": "2018-05-30T08:34:23+00:00" } ], - "packages-dev": [ - { - "name": "pdepend/pdepend", - "version": "2.5.2", - "source": { - "type": "git", - "url": "https://github.com/pdepend/pdepend.git", - "reference": "9daf26d0368d4a12bed1cacae1a9f3a6f0adf239" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/pdepend/pdepend/zipball/9daf26d0368d4a12bed1cacae1a9f3a6f0adf239", - "reference": "9daf26d0368d4a12bed1cacae1a9f3a6f0adf239", - "shasum": "" - }, - "require": { - "php": ">=5.3.7", - "symfony/config": "^2.3.0|^3|^4", - "symfony/dependency-injection": "^2.3.0|^3|^4", - "symfony/filesystem": "^2.3.0|^3|^4" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.7", - "squizlabs/php_codesniffer": "^2.0.0" - }, - "bin": [ - "src/bin/pdepend" - ], - "type": "library", - "autoload": { - "psr-4": { - "PDepend\\": "src/main/php/PDepend" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Official version of pdepend to be handled with Composer", - "time": "2017-12-13T13:21:38+00:00" - }, - { - "name": "phpmd/phpmd", - "version": "2.6.0", - "source": { - "type": "git", - "url": "https://github.com/phpmd/phpmd.git", - "reference": "4e9924b2c157a3eb64395460fcf56b31badc8374" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpmd/phpmd/zipball/4e9924b2c157a3eb64395460fcf56b31badc8374", - "reference": "4e9924b2c157a3eb64395460fcf56b31badc8374", - "shasum": "" - }, - "require": { - "ext-xml": "*", - "pdepend/pdepend": "^2.5", - "php": ">=5.3.9" - }, - "require-dev": { - "phpunit/phpunit": "^4.0", - "squizlabs/php_codesniffer": "^2.0" - }, - "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" - }, - { - "name": "Marc Würth", - "email": "ravage@bluewin.ch", - "homepage": "https://github.com/ravage84", - "role": "Project Maintainer" - } - ], - "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": "2017-01-20T14:41:10+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "2.1.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.0" - }, - "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": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2019-06-07T04:22:29+00:00" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14T16:28:37+00:00" - }, - { - "name": "sebastian/finder-facade", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/finder-facade.git", - "reference": "4a3174709c2dc565fe5fb26fcf827f6a1fc7b09f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/finder-facade/zipball/4a3174709c2dc565fe5fb26fcf827f6a1fc7b09f", - "reference": "4a3174709c2dc565fe5fb26fcf827f6a1fc7b09f", - "shasum": "" - }, - "require": { - "symfony/finder": "~2.3|~3.0|~4.0", - "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": "2017-11-18T17:31:49+00:00" - }, - { - "name": "sebastian/phpcpd", - "version": "4.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpcpd.git", - "reference": "0d9afa762f2400de077b2192f4a9d127de0bb78e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpcpd/zipball/0d9afa762f2400de077b2192f4a9d127de0bb78e", - "reference": "0d9afa762f2400de077b2192f4a9d127de0bb78e", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "php": "^7.1", - "phpunit/php-timer": "^2.0", - "sebastian/finder-facade": "^1.1", - "sebastian/version": "^1.0|^2.0", - "symfony/console": "^2.7|^3.0|^4.0" - }, - "bin": [ - "phpcpd" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-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": "Copy/Paste Detector (CPD) for PHP code.", - "homepage": "https://github.com/sebastianbergmann/phpcpd", - "time": "2018-09-17T17:17:27+00:00" - }, - { - "name": "sebastian/version", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-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": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "3.4.2", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "shasum": "" - }, - "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" - }, - "bin": [ - "bin/phpcs", - "bin/phpcbf" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2019-04-10T23:49:02+00:00" - }, - { - "name": "symfony/config", - "version": "v4.3.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/config.git", - "reference": "6379ee07398643e09e6ed1e87d9c62dfcad7f4eb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/6379ee07398643e09e6ed1e87d9c62dfcad7f4eb", - "reference": "6379ee07398643e09e6ed1e87d9c62dfcad7f4eb", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/filesystem": "~3.4|~4.0", - "symfony/polyfill-ctype": "~1.8" - }, - "conflict": { - "symfony/finder": "<3.4" - }, - "require-dev": { - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", - "symfony/finder": "~3.4|~4.0", - "symfony/messenger": "~4.1", - "symfony/yaml": "~3.4|~4.0" - }, - "suggest": { - "symfony/yaml": "To use the yaml reference dumper" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Config\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "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": "2019-05-30T16:10:05+00:00" - }, - { - "name": "symfony/console", - "version": "v4.3.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "d50bbeeb0e17e6dd4124ea391eff235e932cbf64" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/d50bbeeb0e17e6dd4124ea391eff235e932cbf64", - "reference": "d50bbeeb0e17e6dd4124ea391eff235e932cbf64", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/service-contracts": "^1.1" - }, - "conflict": { - "symfony/dependency-injection": "<3.4", - "symfony/event-dispatcher": "<4.3", - "symfony/process": "<3.3" - }, - "provide": { - "psr/log-implementation": "1.0" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "^4.3", - "symfony/lock": "~3.4|~4.0", - "symfony/process": "~3.4|~4.0", - "symfony/var-dumper": "^4.3" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "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": "2019-06-05T13:25:51+00:00" - }, - { - "name": "symfony/dependency-injection", - "version": "v4.3.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/dependency-injection.git", - "reference": "fea7f73e278ee0337349a5a68b867fc656bb33f3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/fea7f73e278ee0337349a5a68b867fc656bb33f3", - "reference": "fea7f73e278ee0337349a5a68b867fc656bb33f3", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "psr/container": "^1.0", - "symfony/service-contracts": "^1.1.2" - }, - "conflict": { - "symfony/config": "<4.3", - "symfony/finder": "<3.4", - "symfony/proxy-manager-bridge": "<3.4", - "symfony/yaml": "<3.4" - }, - "provide": { - "psr/container-implementation": "1.0", - "symfony/service-implementation": "1.0" - }, - "require-dev": { - "symfony/config": "^4.3", - "symfony/expression-language": "~3.4|~4.0", - "symfony/yaml": "~3.4|~4.0" - }, - "suggest": { - "symfony/config": "", - "symfony/expression-language": "For using expressions in service container configuration", - "symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required", - "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\DependencyInjection\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "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": "2019-05-30T16:10:05+00:00" - }, - { - "name": "symfony/filesystem", - "version": "v4.3.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "bf2af40d738dec5e433faea7b00daa4431d0a4cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/bf2af40d738dec5e433faea7b00daa4431d0a4cf", - "reference": "bf2af40d738dec5e433faea7b00daa4431d0a4cf", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "symfony/polyfill-ctype": "~1.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "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": "2019-06-03T20:27:40+00:00" - }, - { - "name": "symfony/finder", - "version": "v4.3.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "b3d4f4c0e4eadfdd8b296af9ca637cfbf51d8176" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/b3d4f4c0e4eadfdd8b296af9ca637cfbf51d8176", - "reference": "b3d4f4c0e4eadfdd8b296af9ca637cfbf51d8176", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "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": "2019-05-26T20:47:49+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.11.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2019-02-06T07:57:58+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.11.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2019-02-06T07:57:58+00:00" - }, - { - "name": "symfony/polyfill-php73", - "version": "v1.11.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "d1fb4abcc0c47be136208ad9d68bf59f1ee17abd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/d1fb4abcc0c47be136208ad9d68bf59f1ee17abd", - "reference": "d1fb4abcc0c47be136208ad9d68bf59f1ee17abd", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2019-02-06T07:57:58+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v1.1.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "191afdcb5804db960d26d8566b7e9a2843cab3a0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/191afdcb5804db960d26d8566b7e9a2843cab3a0", - "reference": "191afdcb5804db960d26d8566b7e9a2843cab3a0", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "suggest": { - "psr/container": "", - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2019-05-28T07:50:59+00:00" - }, - { - "name": "theseer/fdomdocument", - "version": "1.6.6", - "source": { - "type": "git", - "url": "https://github.com/theseer/fDOMDocument.git", - "reference": "6e8203e40a32a9c770bcb62fe37e68b948da6dca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theseer/fDOMDocument/zipball/6e8203e40a32a9c770bcb62fe37e68b948da6dca", - "reference": "6e8203e40a32a9c770bcb62fe37e68b948da6dca", - "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": "2017-06-30T11:53:12+00:00" - } - ], + "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2" + "php": ">=5.2" }, "platform-dev": [] } diff --git a/src/CommandoX/Command.php b/src/CommandoX/Command.php index b1783ec..1710bec 100755 --- a/src/CommandoX/Command.php +++ b/src/CommandoX/Command.php @@ -1,4 +1,4 @@ - * @author Nate Good @@ -183,7 +183,7 @@ public static function define($tokens = null) * @return Command * @throws \Exception */ - public function __call(string $name, array $arguments): Command + public function __call($name, array $arguments) { if (empty(self::$methods[$name])) { throw new \Exception(sprintf('Unknown function, %s, called', $name)); @@ -210,7 +210,7 @@ public function __call(string $name, array $arguments): Command * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - private function _option(?Option $option, string $name = null) + private function _option($option, $name = null) { // Is this a previously declared option? if (isset($name) && !empty($this->options[$name])) { @@ -235,7 +235,7 @@ private function _option(?Option $option, string $name = null) * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _flag(?Option $option, string $name): Option + private function _flag($option, $name) { if (is_numeric($name)) { throw new \Exception('Attempted to reference flag with a numeric index'); @@ -254,7 +254,7 @@ private function _flag(?Option $option, string $name): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _argument(?Option $option, ?int $index = null): Option + private function _argument($option, $index = null) { if (isset($index) && !is_numeric($index)) { throw new \Exception('Attempted to reference argument with a string name'); @@ -271,7 +271,7 @@ private function _argument(?Option $option, ?int $index = null): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _boolean(Option $option, bool $boolean = true): Option + private function _boolean($option, $boolean = true) { return $option->setBoolean($boolean); } @@ -285,7 +285,7 @@ private function _boolean(Option $option, bool $boolean = true): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _require(Option $option, bool $require = true): Option + private function _require($option, $require = true) { return $option->setRequired($require); } @@ -299,7 +299,7 @@ private function _require(Option $option, bool $require = true): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _needs(Option $option, string $name): Option + private function _needs($option, $name) { return $option->setNeeds($name); } @@ -313,7 +313,7 @@ private function _needs(Option $option, string $name): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _alias(Option $option, string $alias): Option + private function _alias($option, $alias) { $this->options[$alias] = $this->currentOption; return $option->addAlias($alias); @@ -328,7 +328,7 @@ private function _alias(Option $option, string $alias): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _describe(Option $option, string $description): Option + private function _describe($option, $description) { return $option->setDescription($description); } @@ -342,7 +342,7 @@ private function _describe(Option $option, string $description): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _title(Option $option, string $title): Option + private function _title($option, $title) { return $option->setTitle($title); } @@ -356,7 +356,7 @@ private function _title(Option $option, string $title): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _must(Option $option, \Closure $callback): Option + private function _must($option, \Closure $callback) { return $option->setRule($callback); } @@ -370,7 +370,7 @@ private function _must(Option $option, \Closure $callback): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _map(Option $option, \Closure $callback): Option + private function _map($option, \Closure $callback) { return $option->setMap($callback); } @@ -385,7 +385,7 @@ private function _map(Option $option, \Closure $callback): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _increment(Option $option, int $max = 0): Option + private function _increment($option, $max = 0) { return $option->setIncrement($max); } @@ -400,7 +400,7 @@ private function _increment(Option $option, int $max = 0): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _default(Option $option, /* mixed */ $value): Option + private function _default($option, /* mixed */ $value) { return $option->setDefault($value); } @@ -413,7 +413,7 @@ private function _default(Option $option, /* mixed */ $value): Option * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ - private function _file(Option $option, bool $requireExists = true, bool $allowGlobbing = false): Option + private function _file($option, $requireExists = true, $allowGlobbing = false) { return $option->setFileRequirements($requireExists, $allowGlobbing); } @@ -423,7 +423,7 @@ private function _file(Option $option, bool $requireExists = true, bool $allowGl * * @param bool $help */ - public function useDefaultHelp(bool $help = true) + public function useDefaultHelp($help = true) { $this->defaultHelp = $help; } @@ -435,7 +435,7 @@ public function useDefaultHelp(bool $help = true) * @param array $cli_tokens * @return Command */ - public function setTokens(array $cli_tokens): Command + public function setTokens(array $cli_tokens) { $this->tokens = $cli_tokens; return $this; @@ -447,7 +447,7 @@ public function setTokens(array $cli_tokens): Command * @throws \Exception * @return int */ - private function parseIfNotParsed(): int + private function parseIfNotParsed() { if ($this->isParsed()) { return 0; @@ -461,7 +461,7 @@ private function parseIfNotParsed(): int * @throws \Exception * @return int */ - public function parse(): int + public function parse() { $this->parsed = true; $this->attachHelp(); @@ -586,7 +586,7 @@ public function parse(): int * @throws \Exception * @return int exit code */ - public function error(\Exception $exception): int + public function error($exception) { if ($this->errorBeep === true) { Terminal::beep(); @@ -606,7 +606,7 @@ public function error(\Exception $exception): int * @param string $message * @return string */ - public function createTerminalError(string $message) + public function createTerminalError($message) { $color = new \Colors\Color(); $error = sprintf('ERROR: %s ', $message); @@ -618,7 +618,7 @@ public function createTerminalError(string $message) * * @return bool */ - public function isParsed(): bool + public function isParsed() { return $this->parsed; } @@ -629,7 +629,7 @@ public function isParsed(): bool * @throws \Exception * @return array [option name/value, OPTION_TYPE_*] */ - private function _parseOption($token): array + private function _parseOption($token) { $matches = []; if (substr($token, 0, 1) === '-' && !preg_match('/(?P\-{1,2})(?P[a-z][a-z0-9_-]*)/i', $token, $matches)) { @@ -652,7 +652,7 @@ private function _parseOption($token): array * @throws \Exception if $option does not exist * @return Option */ - public function getOption($option): Option + public function getOption($option) { if (!$this->hasOption($option)) { throw new \Exception(sprintf('Unknown option, %s, specified', $option)); @@ -664,7 +664,7 @@ public function getOption($option): Option /** * @return array of `Option`s */ - public function getOptions(): array + public function getOptions() { $this->parseIfNotParsed(); return $this->options; @@ -673,7 +673,7 @@ public function getOptions(): array /** * @return array of argument `Option` only */ - public function getArguments(): array + public function getArguments() { $this->parseIfNotParsed(); return $this->arguments; @@ -682,7 +682,7 @@ public function getArguments(): array /** * @return array of flag `Option` only */ - public function getFlags(): array + public function getFlags() { $this->parseIfNotParsed(); return $this->flags; @@ -694,7 +694,7 @@ public function getFlags(): array * * @return array of argument values only */ - public function getArgumentValues(): array + public function getArgumentValues() { $this->parseIfNotParsed(); @@ -714,7 +714,7 @@ public function getArgumentValues(): array * * @return array of flag values only */ - public function getFlagValues(): array + public function getFlagValues() { $this->parseIfNotParsed(); return array_map(function (Option $flag) { @@ -727,7 +727,7 @@ public function getFlagValues(): array * how the flags are mapped internally to make alias lookup * simpler/faster. */ - private function dedupeFlags(): array + private function dedupeFlags() { $seen = []; foreach ($this->flags as $flag) { @@ -742,7 +742,7 @@ private function dedupeFlags(): array * @param string $option name (named option) or index (anonymous option) * @return boolean */ - public function hasOption($option): bool + public function hasOption($option) { return !empty($this->options[$option]); } @@ -750,7 +750,7 @@ public function hasOption($option): bool /** * @return string dump values */ - public function __toString(): string + public function __toString() { // TODO return values of set options as map of option name => value return $this->getHelp(); @@ -759,7 +759,7 @@ public function __toString(): string /** * @return int */ - public function getSize(): int + public function getSize() { return count($this->options); } @@ -768,7 +768,7 @@ public function getSize(): int * @param string $help * @return Command */ - public function setHelp(string $help): Command + public function setHelp($help) { $this->help = $help; return $this; @@ -779,7 +779,7 @@ public function setHelp(string $help): Command * printed cleanly to standard error. * @return Command */ - public function trapErrors(bool $trap = true): Command + public function trapErrors($trap = true) { $this->errorTrap = $trap; return $this; @@ -788,7 +788,7 @@ public function trapErrors(bool $trap = true): Command /** * @return Command */ - public function doNotTrapErrors(): Command + public function doNotTrapErrors() { return $this->trapErrors(false); } @@ -798,7 +798,7 @@ public function doNotTrapErrors(): Command * @param bool $beep * @return Command */ - public function beepOnError(bool $beep = true): Command + public function beepOnError($beep = true) { $this->errorBeep = $beep; return $this; @@ -807,7 +807,7 @@ public function beepOnError(bool $beep = true): Command /** * @return string help docs */ - public function getHelp(): string + public function getHelp() { $this->attachHelp(); @@ -849,7 +849,7 @@ public function getHelp(): string * * @return boolean */ - public function didShowHelp(): bool + public function didShowHelp() { return $this->showedHelp; } @@ -967,7 +967,7 @@ public function next() * @see \Iterator * @return bool */ - public function valid(): bool + public function valid() { return isset($this->sorted_keys[$this->position]); } diff --git a/src/CommandoX/Option.php b/src/CommandoX/Option.php index 0b331b6..cc4c984 100755 --- a/src/CommandoX/Option.php +++ b/src/CommandoX/Option.php @@ -1,4 +1,4 @@ - * @author Nate Good @@ -88,7 +88,7 @@ public function __construct($name) * @param string $alias * @return Option */ - public function addAlias(string $alias): Option + public function addAlias($alias) { $this->aliases[] = $alias; return $this; @@ -100,7 +100,7 @@ public function addAlias(string $alias): Option * @param string $description * @return Option */ - public function setDescription(string $description): Option + public function setDescription($description) { $this->description = $description; return $this; @@ -112,7 +112,7 @@ public function setDescription(string $description): Option * @param bool $bool * @return Option */ - public function setBoolean(bool $bool = true): Option + public function setBoolean($bool = true) { // if we didn't define a default already, set false as the default value if ($this->default === null) { @@ -128,7 +128,7 @@ public function setBoolean(bool $bool = true): Option * @param int $max * @return Option */ - public function setIncrement(int $max = 0): Option + public function setIncrement($max = 0) { // if we didn't define a default already, set 0 as the default value if ($this->default === null) { @@ -152,7 +152,7 @@ public function setIncrement(int $max = 0): Option * @throws \Exception if the file does not exists * @return Option */ - public function setFileRequirements(bool $requireExists = true, bool $allowGlobbing = true): Option + public function setFileRequirements($requireExists = true, $allowGlobbing = true) { $this->file = true; $this->fileRequireExists = $requireExists; @@ -166,7 +166,7 @@ public function setFileRequirements(bool $requireExists = true, bool $allowGlobb * @param string $title * @return Option */ - public function setTitle(string $title): Option + public function setTitle($title) { $this->title = $title; return $this; @@ -178,7 +178,7 @@ public function setTitle(string $title): Option * @param bool $bool required? * @return Option */ - public function setRequired(bool $bool = true): Option + public function setRequired($bool = true) { $this->required = $bool; return $this; @@ -190,7 +190,7 @@ public function setRequired(bool $bool = true): Option * @param string $option Option name * @return Option */ - public function setNeeds(string $option): Option + public function setNeeds($option) { if (!is_array($option)) { $option = [$option]; @@ -208,7 +208,7 @@ public function setNeeds(string $option): Option * @param mixed $value default value * @return Option */ - public function setDefault(/* mixed */ $value): Option + public function setDefault(/* mixed */ $value) { $this->default = $value; $this->setValue($value); @@ -227,7 +227,7 @@ public function getDefault() * @param \Closure|string $rule regex, closure * @return Option */ - public function setRule(/* mixed */ $rule): Option + public function setRule(/* mixed */ $rule) { $this->rule = $rule; return $this; @@ -237,7 +237,7 @@ public function setRule(/* mixed */ $rule): Option * @param \Closure $map * @return Option */ - public function setMap(\Closure $map): Option + public function setMap(\Closure $map) { $this->map = $map; return $this; @@ -266,7 +266,7 @@ public function map(/* mixed */ $value) * @param mixed $value * @return bool */ - public function validate(/* mixed */ $value): bool + public function validate(/* mixed */ $value) { if (!is_callable($this->rule)) { return true; @@ -285,7 +285,7 @@ public function validate(/* mixed */ $value): bool * @return array single element array of full file path * or an array of file paths if "globbing" is supported */ - public function parseFilePath(string $filePath): array + public function parseFilePath($filePath) { $path = realpath($filePath); if ($this->fileAllowGlobbing) { @@ -312,12 +312,12 @@ public function getName() /** * @return string description of the option */ - public function getDescription(): string + public function getDescription() { return $this->description; } - public function isNamed(): bool + public function isNamed() { return in_array($this->getType(), [TypeEnum::LONG, TypeEnum::SHORT]); } @@ -325,7 +325,7 @@ public function isNamed(): bool /** * @return int type (see OPTION_TYPE_CONST) */ - public function getType(): int + public function getType() { return $this->type->value; } @@ -341,7 +341,7 @@ public function getValue() /** * @return string[] list of aliases */ - public function getAliases(): array + public function getAliases() { return $this->aliases; } @@ -351,7 +351,7 @@ public function getAliases(): array * * @return string[] List of required options */ - public function getNeeds(): array + public function getNeeds() { return $this->needs; } @@ -359,7 +359,7 @@ public function getNeeds(): array /** * @return bool is this option a boolean */ - public function isBoolean(): bool + public function isBoolean() { return $this->boolean; } @@ -367,7 +367,7 @@ public function isBoolean(): bool /** * @return bool is this option an incremental option */ - public function isIncrement(): bool + public function isIncrement() { return $this->increment; } @@ -375,7 +375,7 @@ public function isIncrement(): bool /** * @return bool is this option a boolean */ - public function isFile(): bool + public function isFile() { return $this->file; } @@ -383,7 +383,7 @@ public function isFile(): bool /** * @return bool is this option required? */ - public function isRequired(): bool + public function isRequired() { return $this->required; } @@ -449,7 +449,7 @@ public function setValue($value) * * @return string */ - public function getHelp(): string + public function getHelp() { $color = new \Colors\Color(); $isNamed = $this->type->isNamed(); @@ -507,7 +507,7 @@ public function getHelp(): string /** * @return string */ - public function __toString(): string + public function __toString() { return $this->getHelp(); } diff --git a/src/CommandoX/Option/TypeEnum.php b/src/CommandoX/Option/TypeEnum.php index 5370284..8ec0805 100644 --- a/src/CommandoX/Option/TypeEnum.php +++ b/src/CommandoX/Option/TypeEnum.php @@ -1,4 +1,4 @@ -value); } @@ -35,7 +35,7 @@ public function isNamed(): bool * @param mixed $value * @return bool */ - public static function isValueNamed(/* mixed */ $value): bool + public static function isValueNamed(/* mixed */ $value) { return ($value === static::SHORT || $value === static::LONG); } diff --git a/src/CommandoX/Util/Enum.php b/src/CommandoX/Util/Enum.php index 8f617ea..f6f6245 100644 --- a/src/CommandoX/Util/Enum.php +++ b/src/CommandoX/Util/Enum.php @@ -1,4 +1,4 @@ - */ @@ -21,7 +21,7 @@ abstract class Enum public function __construct(/* mixed */ $value) { if (!self::isValidValue($value)) { - $name = static::class; + $name = get_called_class(); throw new \Exception("Invalid value $value for enum $name"); } $this->value = $value; @@ -33,7 +33,7 @@ public function __construct(/* mixed */ $value) * @param string $name * @return void */ - public function __get(string $name) + public function __get($name) { if ($name === 'value') { return $this->value; @@ -46,16 +46,17 @@ public function __get(string $name) * * @return array */ - private static function getConstants(): array + private static function getConstants() { if (self::$constCacheArray == null) { self::$constCacheArray = []; } - if (!array_key_exists(static::class, self::$constCacheArray)) { - $reflect = new \ReflectionClass(static::class); - self::$constCacheArray[static::class] = $reflect->getConstants(); + $calledClass = get_called_class(); + if (!array_key_exists($calledClass, self::$constCacheArray)) { + $reflect = new \ReflectionClass($calledClass); + self::$constCacheArray[$calledClass] = $reflect->getConstants(); } - return self::$constCacheArray[static::class]; + return self::$constCacheArray[$calledClass]; } /** @@ -64,7 +65,7 @@ private static function getConstants(): array * @param mixed $value * @return boolean */ - public static function isValidValue(/* mixed */ $value): bool + public static function isValidValue(/* mixed */ $value) { $values = array_values(self::getConstants()); return in_array($value, $values); diff --git a/src/CommandoX/Util/Terminal.php b/src/CommandoX/Util/Terminal.php index 3407959..b5c5ba0 100644 --- a/src/CommandoX/Util/Terminal.php +++ b/src/CommandoX/Util/Terminal.php @@ -1,4 +1,4 @@ - * @author Nate Good @@ -21,7 +21,7 @@ class Terminal * @param int $default * @return int */ - public static function getWidth($default = 80): int + public static function getWidth($default = 80) { return self::tput($default, 'cols'); } @@ -34,7 +34,7 @@ public static function getWidth($default = 80): int * @param int $default * @return int */ - public static function getHeight($default = 32): int + public static function getHeight($default = 32) { return self::tput($default, 'lines'); } @@ -44,7 +44,7 @@ public static function getHeight($default = 32): int * * @return void */ - public static function beep(): void + public static function beep() { print('\x7'); } @@ -56,7 +56,7 @@ public static function beep(): void * * @return void */ - public static function setOsType(string $osType): void + public static function setOsType($osType) { self::$osType = $osType; } @@ -72,24 +72,25 @@ public static function setOsType(string $osType): void * @param string $param * @return int */ - private static function tput($default, $param = 'cols'): int + private static function tput($default, $param = 'cols') { $phpOs = strtolower(substr(PHP_OS, 0, 3)); if (!self::$osType) { self::$osType = getenv('OS'); } $envOs = self::$osType; + $whichTput = shell_exec('which tput'); if ($phpOs === 'win' || ($envOs && strpos(strtolower($envOs), 'windows') !== false) || - empty(trim(shell_exec('which tput')))) { + !trim($whichTput)) { return $default; } $test = exec('tput ' . $param . ' 2>/dev/null'); - if (empty($test)) { + if (!$test) { return $default; } $result = intval(exec('tput ' . $param)); - return empty($result) ? $default : $result; + return !$result ? $default : $result; } /** @@ -101,12 +102,8 @@ private static function tput($default, $param = 'cols'): int * @param ?int $width attempts to use current terminal width by default * @return string */ - public static function wrap( - string $text, - int $leftMargin = 0, - int $rightMargin = 0, - ?int $width = null - ): string { + public static function wrap($text, $leftMargin = 0, $rightMargin = 0, $width = null) + { if (empty($width)) { $width = self::getWidth(); } @@ -122,7 +119,7 @@ public static function wrap( * @param int $width defaults to terminal width * @return string */ - public static function header(string $text, ?int $width = null): string + public static function header($text, $width = null) { if (empty($width)) { $width = self::getWidth(); @@ -140,12 +137,8 @@ public static function header(string $text, ?int $width = null): string * * @return string */ - public static function pad( - string $text, - int $width, - string $pad = ' ', - int $mode = STR_PAD_RIGHT - ): string { + public static function pad($text, $width, $pad = ' ', $mode = STR_PAD_RIGHT) + { $width = strlen($text) - mb_strlen($text, 'UTF-8') + $width; return str_pad($text, $width, $pad, $mode); } diff --git a/tests/CommandoX/CommandTest.php b/tests/CommandoX/CommandTest.php index 4623efc..b15929e 100755 --- a/tests/CommandoX/CommandTest.php +++ b/tests/CommandoX/CommandTest.php @@ -1,4 +1,4 @@ -assertEquals(1, $cmd->getSize()); } + /** + * Must have required arguments + * + * @expectedException \Exception + * @test + */ public function testWhenRequiredArgumentNotPassedThenThrows() { - $this->expectException(\Exception::class); $tokens = ['filename']; $cmd = new Command($tokens); $cmd->doNotTrapErrors(); @@ -230,11 +235,12 @@ public function testRequirementsOnOptionsValid() /** * Test that an exception is thrown when an option isn't set + * + * @expectedException \InvalidArgumentException + * @test */ public function testRequirementsOnOptionsMissing() { - $this->expectException(\InvalidArgumentException::class); - $tokens = ['filename', '-a', 'v1']; $cmd = new Command($tokens); @@ -280,8 +286,8 @@ public function testGetHelp() $cmd->setHelp($extraHelp); $help = $cmd->getHelp(); $testHelp = '--help'; - $this->assertIsInt(strpos($help, $testHelp)); - $this->assertIsInt(strpos($help, $extraHelp)); + $this->assertGreaterThan(0, strpos($help, $testHelp)); + $this->assertGreaterThan(0, strpos($help, $extraHelp)); } /** @@ -321,11 +327,11 @@ public function testWhenUnsetOnArrayThenRemoved() /** * Test for unknown methods * + * @expectedException \Exception * @test */ public function testCommandWhenMethodNotDefinedThenThrows() { - $this->expectException(\Exception::class); $tokens = ['filename']; $cmd = new Command($tokens); $cmd->nonexistentMethod(); @@ -359,15 +365,17 @@ public function testToStringIncludesHelp() $tokens = [$scriptName, 'test']; $cmd = new Command($tokens); $help = 'TO STRING ' . $cmd; - $this->assertIsInt(strpos($help, $scriptName)); + $this->assertGreaterThan(0, strpos($help, $scriptName)); } /** * Test array interface throws on set + * + * @expectedException \Exception + * @test */ public function testWhenSetOnArrayThenThrows() { - $this->expectException(\Exception::class); $tokens = ['filename']; $cmd = new Command($tokens); $cmd[0] = 'test'; @@ -376,11 +384,11 @@ public function testWhenSetOnArrayThenThrows() /** * Test malformed arguments while errors are not trapped * + * @expectedException \Exception * @test */ public function testWhenMalformedArgumentAndTrapFalseThenThrows() { - $this->expectException(\Exception::class); $tokens = ['filename', '-*test']; $cmd = new Command($tokens); $cmd->doNotTrapErrors(); diff --git a/tests/CommandoX/OptionTest.php b/tests/CommandoX/OptionTest.php index e41ce43..dcac761 100644 --- a/tests/CommandoX/OptionTest.php +++ b/tests/CommandoX/OptionTest.php @@ -1,4 +1,4 @@ -expectException(\Exception::class); - $option = new Option('f'); $option->setRule(function ($value) { return is_numeric($value); @@ -169,11 +170,11 @@ public function testFileGlob() /** * Test empty globs throw exception * + * @expectedException \Exception * @test */ public function testFileGlobWhenEmptyThenThrows() { - $this->expectException(\Exception::class); $option = new Option(0); $option->setFileRequirements(true, true); $file = dirname(__FILE__) . '/assets/*.bad'; @@ -254,32 +255,32 @@ public function testGetHelpIncludesAllComponents() ->setDefault($testDefault); $help = 'TO STRING ' . $option; - $this->assertIsInt(strpos($help, $testTitle)); - $this->assertIsInt(strpos($help, $testAlias)); - $this->assertIsInt(strpos($help, $testDescription)); - $this->assertIsInt(strpos($help, $testRequired)); - $this->assertIsInt(strpos($help, $testDefault)); + $this->assertGreaterThan(0, strpos($help, $testTitle)); + $this->assertGreaterThan(0, strpos($help, $testAlias)); + $this->assertGreaterThan(0, strpos($help, $testDescription)); + $this->assertGreaterThan(0, strpos($help, $testRequired)); + $this->assertGreaterThan(0, strpos($help, $testDefault)); } /** * Constructing with no parameter throws * + * @expectedException \Exception * @test */ public function testConstructWhenNoNameThenThrowsException() { - $this->expectException(\Exception::class); new Option(null); } /** * Non-boolean values passed to boolean options should throw * + * @expectedException \Exception * @test */ public function testSetValueWhenBooleanNonBooleanValueThenThrowsException() { - $this->expectException(\Exception::class); $option = new Option('t'); $option->setBoolean(); $option->setValue('x'); @@ -288,11 +289,11 @@ public function testSetValueWhenBooleanNonBooleanValueThenThrowsException() /** * Non-integer values passed to increment options should throw * + * @expectedException \Exception * @test */ public function testSetValueWhenIncrementNonIntegerValueThenThrowsException() { - $this->expectException(\Exception::class); $option = new Option('t'); $option->setIncrement(3); $option->setValue('x'); diff --git a/tests/CommandoX/SubclassCommand.php b/tests/CommandoX/SubclassCommand.php index f260477..21ff13d 100644 --- a/tests/CommandoX/SubclassCommand.php +++ b/tests/CommandoX/SubclassCommand.php @@ -1,4 +1,4 @@ -expectException(\Exception::class); new TestEnum(2); } + /** + * Can only get value + * + * @expectedException \Exception + * @test + */ public function testEnumWhenInvalidGetThenThrows() { - $this->expectException(\Exception::class); $test = new TestEnum(1); $test->notValue; } diff --git a/tests/CommandoX/Util/TerminalTest.php b/tests/CommandoX/Util/TerminalTest.php index a878230..39823bb 100644 --- a/tests/CommandoX/Util/TerminalTest.php +++ b/tests/CommandoX/Util/TerminalTest.php @@ -1,4 +1,4 @@ - + .