From 952d8f6ba643a64ca8791eaad1ac69b176b8e27c Mon Sep 17 00:00:00 2001 From: Gitea Date: Wed, 27 Oct 2021 14:30:13 +0200 Subject: [PATCH] Update language level to 7.2 --- LICENSE | 2 +- README.md | 2 +- composer.json | 2 +- src/jblond/cli/Cli.php | 23 +++++++++++++---------- src/jblond/cli/CliColors.php | 10 ++++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/LICENSE b/LICENSE index 4d10a94..70d79ad 100644 --- a/LICENSE +++ b/LICENSE @@ -14,7 +14,7 @@ copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE diff --git a/README.md b/README.md index 0305a3c..aa9faad 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Code Climate](https://codeclimate.com/github/JBlond/php-cli/badges/gpa.svg)](https://codeclimate.com/github/JBlond/php-cli) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/438eaa51c0464a689229709cfeb583bb)](https://www.codacy.com/app/leet31337/php-cli?utm_source=github.com&utm_medium=referral&utm_content=JBlond/php-cli&utm_campaign=Badge_Grade) -## php command line / cli scritping classes +## php command line / cli scripting classes ### Example diff --git a/composer.json b/composer.json index 467c953..b19915c 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.6" + "php": ">=7.2" }, "autoload": { "psr-4": { diff --git a/src/jblond/cli/Cli.php b/src/jblond/cli/Cli.php index a146610..3a632df 100644 --- a/src/jblond/cli/Cli.php +++ b/src/jblond/cli/Cli.php @@ -14,22 +14,23 @@ class Cli { * @param string $default * @return string */ - public function input($prompt, $validInputs, $default = ''){ + public function input(string $prompt, $validInputs, string $default = ''): string + { echo $prompt; - $input = trim(fgets(fopen('php://stdin', 'r'))); + $input = trim(fgets(fopen('php://stdin', 'rb'))); while( !isset($input) || ( is_array($validInputs) && - !in_array($input, $validInputs) + !in_array($input, $validInputs, true) ) || ( - $validInputs == 'is_file' && + $validInputs === 'is_file' && !is_file($input) ) ){ echo $prompt; - $input = trim(fgets(fopen('php://stdin', 'r'))); + $input = trim(fgets(fopen('php://stdin', 'rb'))); if(empty($input) && !empty($default)) { $input = $default; } @@ -40,17 +41,19 @@ public function input($prompt, $validInputs, $default = ''){ /** * @param string $output */ - public function output($output){ - $out = fopen('php://output', 'w'); - fputs($out, $output); + public function output(string $output): void + { + $out = fopen('php://output', 'wb'); + fwrite($out, $output); fclose($out); } /** * @param string $string */ - public function error($string){ - $stdError = fopen('php://stderr', 'w'); + public function error(string $string): void + { + $stdError = fopen('php://stderr', 'wb'); fwrite($stdError, $string); fclose($stdError); } diff --git a/src/jblond/cli/CliColors.php b/src/jblond/cli/CliColors.php index 23c8f07..921afc8 100644 --- a/src/jblond/cli/CliColors.php +++ b/src/jblond/cli/CliColors.php @@ -58,12 +58,12 @@ class CliColors { public function getColoredString($string, $foregroundColor = null, $backgroundColor = null){ $coloredString = ''; - if(!isset($this->foregroundColors["$foregroundColor"])){ + if(!isset($this->foregroundColors[(string) $foregroundColor])){ throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s).', $foregroundColor, implode(', ', array_keys($this->foregroundColors)))); } $coloredString .= "\033[" . $this->foregroundColors[$foregroundColor] . "m"; - if(isset($this->backgroundColors["$backgroundColor"])) { + if(isset($this->backgroundColors[(string) $backgroundColor])) { $coloredString .= "\033[" . $this->backgroundColors[$backgroundColor] . "m"; } $coloredString .= $string . "\033[0m"; @@ -75,7 +75,8 @@ public function getColoredString($string, $foregroundColor = null, $backgroundCo * * @return array */ - public function getForegroundColors() { + public function getForegroundColors(): array + { return array_keys($this->foregroundColors); } @@ -84,7 +85,8 @@ public function getForegroundColors() { * * @return array */ - public function getBackgroundColors() { + public function getBackgroundColors(): array + { return array_keys($this->backgroundColors); } }