Skip to content

Commit

Permalink
Update language level to 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitea committed Oct 27, 2021
1 parent 0dd876b commit 952d8f6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=7.2"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 13 additions & 10 deletions src/jblond/cli/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions src/jblond/cli/CliColors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}

Expand All @@ -84,7 +85,8 @@ public function getForegroundColors() {
*
* @return array
*/
public function getBackgroundColors() {
public function getBackgroundColors(): array
{
return array_keys($this->backgroundColors);
}
}

0 comments on commit 952d8f6

Please sign in to comment.