From b9a3034788e0083afe66c85d6d1978798799964e Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Thu, 29 Jul 2021 14:37:32 +1000 Subject: [PATCH] chore: Update README, LICENCE, and add code linting --- .gitattributes | 2 + .php-commitizen.php | 41 +++++++++++++ .php-cs-fixer.dist.php | 59 +++++++++++++++++++ CHANGELOG.md | 7 +++ LICENCE | 2 +- README.md | 9 ++- composer.json | 22 +++++-- .../Exceptions/RunCommandFailedException.php | 10 ++++ 8 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 .gitattributes create mode 100644 .php-commitizen.php create mode 100644 .php-cs-fixer.dist.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a3aa700 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Force LF +* text eol=lf diff --git a/.php-commitizen.php b/.php-commitizen.php new file mode 100644 index 0000000..8c77023 --- /dev/null +++ b/.php-commitizen.php @@ -0,0 +1,41 @@ + [ + 'lengthMin' => 3, + 'lengthMax' => 8, + 'acceptExtra' => false, + 'values' => [ + 'feat', + 'fix', + 'docs', + 'chore', + 'test', + 'refactor', + 'revert', + 'ci', + ] + ], + 'scope' => [ + 'lengthMin' => 0, + 'lengthMax' => 10, + 'acceptExtra' => true, + 'values' => [], + ], + 'description' => [ + 'lengthMin' => 1, + 'lengthMax' => 47, + ], + 'subject' => [ + 'lengthMin' => 1, + 'lengthMax' => 69, + ], + 'body' => [ + 'wrap' => 72, + ], + 'footer' => [ + 'wrap' => 72, + ], +]; diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..563c415 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,59 @@ + + +For the full copyright and license information, please view the LICENCE +file that was distributed with this source code. +EOF; + +return (new PhpCsFixer\Config()) + ->setUsingCache(true) + ->setRiskyAllowed(true) + ->setFinder( + (new PhpCsFixer\Finder()) + ->files() + ->name('*.php') + ->in(__DIR__) + ->exclude(__DIR__.'/vendor') + ) + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + 'is_null' => true, + 'blank_line_before_statement' => ['statements' => ['continue', 'declare', 'return', 'throw', 'try']], + 'cast_spaces' => ['space' => 'single'], + 'header_comment' => ['header' => $header], + 'include' => true, + 'class_attributes_separation' => ['elements' => ['const' => 'one', 'method' => 'one', 'property' => 'one']], + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'phpdoc_align' => true, + 'phpdoc_indent' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + 'phpdoc_scalar' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'psr_autoloading' => true, + 'array_syntax' => ['syntax' => 'short'], + 'declare_strict_types' => true, + 'single_blank_line_before_namespace' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline' => true, + ]) +; diff --git a/CHANGELOG.md b/CHANGELOG.md index 12fd545..07d8b3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.1.10][] +#### Added +- Added `which()` function + +#### Changed +- Refactor of `run_command()` function to return an exit code + ## [1.1.9][] #### Added - Added `run_command()` function diff --git a/LICENCE b/LICENCE index cb582d5..d91ed67 100644 --- a/LICENCE +++ b/LICENCE @@ -3,7 +3,7 @@ unless otherwise specified, released under the MIT licence as follows: ----- begin license block ----- -Copyright 2019-2020 Alannah Kearney +Copyright 2019-2021 Alannah Kearney Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bf596c6..5de4990 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PHP Helpers: Command-line Functions -- Version: v1.1.9 -- Date: April 06 2020 +- Version: v1.1.10 +- Date: July 29 2021 - [Release notes](https://github.com/pointybeard/helpers-functions-cli/blob/master/CHANGELOG.md) - [GitHub repository](https://github.com/pointybeard/helpers-functions-cli) @@ -28,6 +28,8 @@ This library is a collection convenience function for command-line tasks. They a The following functions are provided: +- `run_command()` +- `which()` - `can_invoke_bash()` - `is_su()` - `run_command()` @@ -48,6 +50,9 @@ use pointybeard\Helpers\Cli\Input; use pointybeard\Helpers\Cli\Colour\Colour; use pointybeard\Helpers\Functions\Cli; +var_dump(Cli\which("ls")); +// string(11) "/usr/bin/ls" + var_dump(Cli\can_invoke_bash()); // bool(true) diff --git a/composer.json b/composer.json index e61fcd0..87779c7 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,11 @@ "description": "A collection of functions relating to the command-line", "homepage": "https://github.com/pointybeard/helpers-functions-cli", "license": "MIT", + "minimum-stability": "stable", + "support": { + "issues": "https://github.com/pointybeard/helpers-functions-cli/issues", + "wiki": "https://github.com/pointybeard/helpers-functions-cli/wiki" + }, "authors": [ { "name": "Alannah Kearney", @@ -21,11 +26,13 @@ "pointybeard/helpers-functions-debug": "~1.0", "pointybeard/helpers-exceptions-readabletrace": "~1.0.0" }, - "support": { - "issues": "https://github.com/pointybeard/helpers-functions-cli/issues", - "wiki": "https://github.com/pointybeard/helpers-functions-cli/wiki" + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "squizlabs/php_codesniffer": "^3.0", + "damianopetrungaro/php-commitizen": "^0.1.0", + "php-parallel-lint/php-parallel-lint": "^1.0", + "php-parallel-lint/php-console-highlighter": "^0.5.0" }, - "minimum-stability": "stable", "autoload": { "psr-4": { "pointybeard\\Helpers\\Functions\\": "src/" @@ -33,5 +40,12 @@ "files": [ "src/Cli/Cli.php" ] + }, + "scripts": { + "tidy": "php-cs-fixer fix -v --using-cache=no", + "tidyDry": "@tidy --dry-run", + "test": [ + "parallel-lint . --exclude vendor" + ] } } diff --git a/src/Cli/Exceptions/RunCommandFailedException.php b/src/Cli/Exceptions/RunCommandFailedException.php index 492900f..3665808 100644 --- a/src/Cli/Exceptions/RunCommandFailedException.php +++ b/src/Cli/Exceptions/RunCommandFailedException.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the "PHP Helpers: Command-line Functions" repository. + * + * Copyright 2019-2021 Alannah Kearney + * + * For the full copyright and license information, please view the LICENCE + * file that was distributed with this source code. + */ + namespace pointybeard\Helpers\Functions\Cli\Exceptions; use pointybeard\Helpers\Exceptions\ReadableTrace; @@ -9,6 +18,7 @@ use pointybeard\Helpers\Exceptions\ReadableTrace; class RunCommandFailedException extends ReadableTrace\ReadableTraceException { private $command; + private $error; public function __construct(string $command, string $error, int $code = 0, \Exception $previous = null)