diff --git a/.gitignore b/.gitignore index 1931d4b..4f2c66a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ composer.phar /vendor/ +.php_cs.cache # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..63943ef --- /dev/null +++ b/.php_cs @@ -0,0 +1,13 @@ +setRiskyAllowed(true) + ->setRules(array( + '@PSR2' => true, + 'blank_line_after_opening_tag' => true, + 'function_typehint_space' => true, + 'no_extra_consecutive_blank_lines' => true, + 'single_quote' => true, + 'binary_operator_spaces' => true, + 'concat_space' => array('spacing' => 'one') + )); diff --git a/composer.json b/composer.json index 0e1c603..c1a63a9 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ ], "require": {}, "require-dev": { - "phpunit/phpunit": "4.3.*" + "phpunit/phpunit": "4.3.*", + "friendsofphp/php-cs-fixer": "^2.1" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index 3d5fd54..d024d68 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8222205617000441fa13b808ed69797d", - "content-hash": "6cfca6ea614d7af94ad0483e843f8492", + "content-hash": "db91b573364a7d00fda9417353722657", "packages": [], "packages-dev": [ { @@ -60,7 +59,110 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" + }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v2.1.0", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "2c69f4d424f85062fe40f7689797d6d32c76b711" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/2c69f4d424f85062fe40f7689797d6d32c76b711", + "reference": "2c69f4d424f85062fe40f7689797d6d32c76b711", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^5.3.6 || >=7.0 <7.2", + "sebastian/diff": "^1.1", + "symfony/console": "^2.3 || ^3.0", + "symfony/event-dispatcher": "^2.1 || ^3.0", + "symfony/filesystem": "^2.4 || ^3.0", + "symfony/finder": "^2.2 || ^3.0", + "symfony/polyfill-php54": "^1.0", + "symfony/polyfill-php55": "^1.3", + "symfony/process": "^2.3 || ^3.0", + "symfony/stopwatch": "^2.5 || ^3.0" + }, + "conflict": { + "hhvm": "<3.9" + }, + "require-dev": { + "gecko-packages/gecko-php-unit": "^2.0", + "phpunit/phpunit": "^4.5|^5", + "satooshi/php-coveralls": "^1.0" + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "time": "2017-02-10T15:37:50+00:00" + }, + { + "name": "ircmaxell/password-compat", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/password_compat.git", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/5c5cde8822a69545767f7c7f3058cb15ff84614c", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "files": [ + "lib/password.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@php.net", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash", + "homepage": "https://github.com/ircmaxell/password_compat", + "keywords": [ + "hashing", + "password" + ], + "time": "2014-11-20T16:49:30+00:00" }, { "name": "phpunit/php-code-coverage", @@ -122,7 +224,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2015-10-06T15:47:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -167,7 +269,7 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2013-10-10T15:34:57+00:00" }, { "name": "phpunit/php-text-template", @@ -208,7 +310,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -249,7 +351,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2015-06-21T08:01:12+00:00" }, { "name": "phpunit/php-token-stream", @@ -298,7 +400,7 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15 10:49:45" + "time": "2015-09-15T10:49:45+00:00" }, { "name": "phpunit/phpunit", @@ -372,7 +474,7 @@ "testing", "xunit" ], - "time": "2014-11-11 10:11:09" + "time": "2014-11-11T10:11:09+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -428,7 +530,54 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2015-10-02T06:51:40+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "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", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" }, { "name": "sebastian/comparator", @@ -492,7 +641,7 @@ "compare", "equality" ], - "time": "2015-07-26 15:48:44" + "time": "2015-07-26T15:48:44+00:00" }, { "name": "sebastian/diff", @@ -544,7 +693,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", @@ -594,7 +743,7 @@ "environment", "hhvm" ], - "time": "2016-02-26 18:40:46" + "time": "2016-02-26T18:40:46+00:00" }, { "name": "sebastian/exporter", @@ -660,7 +809,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2015-06-21T07:55:53+00:00" }, { "name": "sebastian/recursion-context", @@ -713,7 +862,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2015-11-11T19:50:13+00:00" }, { "name": "sebastian/version", @@ -748,7 +897,556 @@ ], "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" + "time": "2015-06-21T13:59:46+00:00" + }, + { + "name": "symfony/console", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "0e5e6899f82230fcb1153bcaf0e106ffaa44b870" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/0e5e6899f82230fcb1153bcaf0e106ffaa44b870", + "reference": "0e5e6899f82230fcb1153bcaf0e106ffaa44b870", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/filesystem": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/filesystem": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-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": "2017-02-16T14:07:22+00:00" + }, + { + "name": "symfony/debug", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "9b98854cb45bc59d100b7d4cc4cf9e05f21026b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/9b98854cb45bc59d100b7d4cc4cf9e05f21026b9", + "reference": "9b98854cb45bc59d100b7d4cc4cf9e05f21026b9", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/class-loader": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "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 Debug Component", + "homepage": "https://symfony.com", + "time": "2017-02-16T16:34:18+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9137eb3a3328e413212826d63eeeb0217836e2b6", + "reference": "9137eb3a3328e413212826d63eeeb0217836e2b6", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/dependency-injection": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/stopwatch": "~2.8|~3.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "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 EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2017-01-02T20:32:22+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "a0c6ef2dc78d33b58d91d3a49f49797a184d06f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/a0c6ef2dc78d33b58d91d3a49f49797a184d06f4", + "reference": "a0c6ef2dc78d33b58d91d3a49f49797a184d06f4", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-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": "2017-01-08T20:47:33+00:00" + }, + { + "name": "symfony/finder", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "8c71141cae8e2957946b403cc71a67213c0380d6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/8c71141cae8e2957946b403cc71a67213c0380d6", + "reference": "8c71141cae8e2957946b403cc71a67213c0380d6", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-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": "2017-01-02T20:32:22+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", + "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-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": "2016-11-14T01:06:16+00:00" + }, + { + "name": "symfony/polyfill-php54", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php54.git", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php54/zipball/90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php54\\": "" + }, + "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 5.4+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14T01:06:16+00:00" + }, + { + "name": "symfony/polyfill-php55", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php55.git", + "reference": "03e3f0350bca2220e3623a0e340eef194405fc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/03e3f0350bca2220e3623a0e340eef194405fc67", + "reference": "03e3f0350bca2220e3623a0e340eef194405fc67", + "shasum": "" + }, + "require": { + "ircmaxell/password-compat": "~1.0", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php55\\": "" + }, + "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 backporting some PHP 5.5+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14T01:06:16+00:00" + }, + { + "name": "symfony/process", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856", + "reference": "0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "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 Process Component", + "homepage": "https://symfony.com", + "time": "2017-02-16T14:07:22+00:00" + }, + { + "name": "symfony/stopwatch", + "version": "v3.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "9aa0b51889c01bca474853ef76e9394b02264464" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/9aa0b51889c01bca474853ef76e9394b02264464", + "reference": "9aa0b51889c01bca474853ef76e9394b02264464", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "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 Stopwatch Component", + "homepage": "https://symfony.com", + "time": "2017-01-02T20:32:22+00:00" }, { "name": "symfony/yaml", @@ -797,7 +1495,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:54:35" + "time": "2016-03-04T07:54:35+00:00" } ], "aliases": [], diff --git a/copyAsMarkdown.spBundle/command.plist b/copyAsMarkdown.spBundle/command.plist index d426cb5..ccfec8c 100644 --- a/copyAsMarkdown.spBundle/command.plist +++ b/copyAsMarkdown.spBundle/command.plist @@ -9,82 +9,82 @@ <?php if (!isset($_ENV['TEST_ENV'])) { - $c = new CopyAsMarkdown(); - $c->exec(fopen("php://stdin", "r")); + $c = new CopyAsMarkdown(); + $c->exec(fopen('php://stdin', 'r')); } class CopyAsMarkdown { - protected $_output; - protected $_columnCount; + protected $output; + protected $columnCount; - public function exec($stdin) - { - $cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) .' | __CF_USER_TEXT_ENCODING='.posix_getuid().':0x8000100:0x8000100 pbcopy'; - exec($cmd); - } - - protected function read($stdin) - { - $result = []; - while($row = fgetcsv($stdin, 0)) { - array_push($result, $row); + public function exec($stdin) + { + $cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) . ' | __CF_USER_TEXT_ENCODING=' . posix_getuid() . ':0x8000100:0x8000100 pbcopy'; + exec($cmd); } - return $result; - } - - protected function convert(array $rows) - { - $this->_columnCount = $this->_calculateColumnCount($rows); - $columns = array_shift($rows); - $result = []; - $result[] =$this->_createHeaderRows($columns); - $result[] = $this->_createDataRows($rows); - return implode("\n", $result); - } - protected function _createHeaderRows(array $columns) - { - $result = []; - $str = ''; - foreach ($columns as $column) { - $str .= "|" . $column; + protected function read($stdin) + { + $result = []; + while ($row = fgetcsv($stdin, 0)) { + array_push($result, $row); + } + return $result; } - $result[] = $str; - $str = ''; - for($i=0; $i<count($columns); $i++) { - $str .= "|---"; + protected function convert(array $rows) + { + $this->columnCount = $this->calculateColumnCount($rows); + $columns = array_shift($rows); + $result = []; + $result[] = $this->createHeaderRows($columns); + $result[] = $this->createDataRows($rows); + return implode("\n", $result); } - $result[] = $str; - return implode("\n", $result); - } + protected function createHeaderRows(array $columns) + { + $result = []; + $str = ''; + foreach ($columns as $column) { + $str .= '|' . $column; + } + $result[] = $str; + + $str = ''; + for ($i = 0; $i < count($columns); $i++) { + $str .= '|---'; + } + $result[] = $str; + + return implode("\n", $result); + } - protected function _calculateColumnCount(array $rows) - { - $count = 0; - foreach ($rows as $row) { - $c = count($row); - if ($c > $count) { - $count = $c; - } + protected function calculateColumnCount(array $rows) + { + $count = 0; + foreach ($rows as $row) { + $c = count($row); + if ($c > $count) { + $count = $c; + } + } + return $count; } - return $count; - } - protected function _createDataRows(array $rows) - { - $result = []; - foreach ($rows as $row) { - $str = ''; - foreach ($row as $val) { - $str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val)); - } - $result[] = $str; + protected function createDataRows(array $rows) + { + $result = []; + foreach ($rows as $row) { + $str = ''; + foreach ($row as $val) { + $str .= '|' . str_replace(array("\n", "\r"), '', nl2br($val)); + } + $result[] = $str; + } + return implode("\n", $result); } - return implode("\n", $result); - } } input selectedtablerowsascsv diff --git a/lib/CopyAsMarkdown/CopyAsMarkdown.php b/lib/CopyAsMarkdown/CopyAsMarkdown.php index e400b50..719c4e4 100644 --- a/lib/CopyAsMarkdown/CopyAsMarkdown.php +++ b/lib/CopyAsMarkdown/CopyAsMarkdown.php @@ -2,80 +2,80 @@ exec(fopen("php://stdin", "r")); + $c = new CopyAsMarkdown(); + $c->exec(fopen('php://stdin', 'r')); } class CopyAsMarkdown { - protected $_output; - protected $_columnCount; + protected $output; + protected $columnCount; - public function exec($stdin) - { - $cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) .' | __CF_USER_TEXT_ENCODING='.posix_getuid().':0x8000100:0x8000100 pbcopy'; - exec($cmd); - } - - protected function read($stdin) - { - $result = []; - while($row = fgetcsv($stdin, 0)) { - array_push($result, $row); + public function exec($stdin) + { + $cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) . ' | __CF_USER_TEXT_ENCODING=' . posix_getuid() . ':0x8000100:0x8000100 pbcopy'; + exec($cmd); } - return $result; - } - - protected function convert(array $rows) - { - $this->_columnCount = $this->_calculateColumnCount($rows); - $columns = array_shift($rows); - $result = []; - $result[] =$this->_createHeaderRows($columns); - $result[] = $this->_createDataRows($rows); - return implode("\n", $result); - } - protected function _createHeaderRows(array $columns) - { - $result = []; - $str = ''; - foreach ($columns as $column) { - $str .= "|" . $column; + protected function read($stdin) + { + $result = []; + while ($row = fgetcsv($stdin, 0)) { + array_push($result, $row); + } + return $result; } - $result[] = $str; - $str = ''; - for($i=0; $icolumnCount = $this->calculateColumnCount($rows); + $columns = array_shift($rows); + $result = []; + $result[] = $this->createHeaderRows($columns); + $result[] = $this->createDataRows($rows); + return implode("\n", $result); } - $result[] = $str; - return implode("\n", $result); - } + protected function createHeaderRows(array $columns) + { + $result = []; + $str = ''; + foreach ($columns as $column) { + $str .= '|' . $column; + } + $result[] = $str; + + $str = ''; + for ($i = 0; $i < count($columns); $i++) { + $str .= '|---'; + } + $result[] = $str; + + return implode("\n", $result); + } - protected function _calculateColumnCount(array $rows) - { - $count = 0; - foreach ($rows as $row) { - $c = count($row); - if ($c > $count) { - $count = $c; - } + protected function calculateColumnCount(array $rows) + { + $count = 0; + foreach ($rows as $row) { + $c = count($row); + if ($c > $count) { + $count = $c; + } + } + return $count; } - return $count; - } - protected function _createDataRows(array $rows) - { - $result = []; - foreach ($rows as $row) { - $str = ''; - foreach ($row as $val) { - $str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val)); - } - $result[] = $str; + protected function createDataRows(array $rows) + { + $result = []; + foreach ($rows as $row) { + $str = ''; + foreach ($row as $val) { + $str .= '|' . str_replace(array("\n", "\r"), '', nl2br($val)); + } + $result[] = $str; + } + return implode("\n", $result); } - return implode("\n", $result); - } } diff --git a/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php b/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php index 134c6e6..411614e 100644 --- a/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php +++ b/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php @@ -4,75 +4,75 @@ class CopyAsMarkdownTest extends PHPUnit_Framework_TestCase { - protected $copyAsMarkdown; + protected $copyAsMarkdown; - public function setUp() - { - $this->copyAsMarkdown = new CopyAsMarkdownExtended('hoge'); - } + public function setUp() + { + $this->copyAsMarkdown = new CopyAsMarkdownExtended('hoge'); + } - public function testCreateHeaderRows() - { - $expected = '|hoge|fuga + public function testCreateHeaderRows() + { + $expected = '|hoge|fuga |---|---'; - $this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge', 'fuga'))); - } + $this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge', 'fuga'))); + } - public function testCreateHeaderRows_WhenHasOneColumn() - { - $expected = '|hoge + public function testCreateHeaderRows_WhenHasOneColumn() + { + $expected = '|hoge |---'; - $this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge'))); - } + $this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge'))); + } - public function testCalculateColumnCount() - { - $this->assertEquals(3, $this->copyAsMarkdown->calculateColumnCount(array(array('a', 'b', 'c')))); - } + public function testCalculateColumnCount() + { + $this->assertEquals(3, $this->copyAsMarkdown->calculateColumnCount(array(array('a', 'b', 'c')))); + } - public function testCreateDataRows() - { - $expected = '|a|b|c + public function testCreateDataRows() + { + $expected = '|a|b|c |d|e|f'; - $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( + $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( array('a', 'b', 'c'), array('d', 'e', 'f'), ))); - } + } - public function testCreateDataRows_WhenHasOneColumn() - { - $expected = '|a'; - $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( + public function testCreateDataRows_WhenHasOneColumn() + { + $expected = '|a'; + $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( array('a'), ))); - } + } - public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData() - { - $expected = '|a|b1
b2
b3|c'; - $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( + public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData() + { + $expected = '|a|b1
b2
b3|c'; + $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( array('a', 'b1 b2 b3', 'c'), ))); - } + } } class CopyAsMarkdownExtended extends CopyAsMarkdown { - public function createHeaderRows(array $rows) - { - return $this->_createHeaderRows($rows); - } + public function createHeaderRows(array $rows) + { + return parent::createHeaderRows($rows); + } - public function calculateColumnCount(array $rows) - { - return $this->_calculateColumnCount($rows); - } + public function calculateColumnCount(array $rows) + { + return parent::calculateColumnCount($rows); + } - public function createDataRows(array $rows) - { - return $this->_createDataRows($rows); - } + public function createDataRows(array $rows) + { + return parent::createDataRows($rows); + } }