Skip to content

Commit

Permalink
CS: various minor fixes
Browse files Browse the repository at this point in the history
Fix up the issues which will be flagged by PHP-Code-Style 2.0 and explicitly ignore a couple of (non-)issues.

Includes no longer allowing warnings in the GH Actions build.
  • Loading branch information
jrfnl authored and grogy committed Dec 20, 2021
1 parent 9fe669b commit 0d14a2d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
run: vendor/bin/phpcs --report-full --report-checkstyle=./checkstyle.xml

- name: Show PHPCS results in PR
run: cs2pr ./checkstyle.xml --graceful-warnings
run: cs2pr ./checkstyle.xml
1 change: 1 addition & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$loader = require_once __DIR__ . '/vendor/autoload.php';

$consoleColor = new PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor();
Expand Down
6 changes: 5 additions & 1 deletion src/ConsoleColor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpConsoleColor;

class ConsoleColor
Expand Down Expand Up @@ -99,7 +100,7 @@ public function apply($style, $text)
foreach ($style as $s) {
if (isset($this->themes[$s])) {
$sequences = array_merge($sequences, $this->themeSequence($s));
} else if ($this->isValidStyle($s)) {
} elseif ($this->isValidStyle($s)) {
$sequences[] = $this->styleSequence($s);
} else {
throw new InvalidStyleException($s);
Expand Down Expand Up @@ -203,13 +204,15 @@ public function removeTheme($name)
public function isSupported()
{
if (DIRECTORY_SEPARATOR === '\\') {
// phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
if (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) {
return true;
} elseif (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON') {
return true;
}
return false;
} else {
// phpcs:ignore Generic.PHP.NoSilencedErrors
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
}
}
Expand All @@ -222,6 +225,7 @@ public function isSupported()
public function are256ColorsSupported()
{
if (DIRECTORY_SEPARATOR === '\\') {
// phpcs:ignore Generic.PHP.NoSilencedErrors,PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
return function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT);
} else {
return strpos(getenv('TERM'), '256color') !== false;
Expand Down
3 changes: 2 additions & 1 deletion src/InvalidStyleException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpConsoleColor;

class InvalidStyleException extends \Exception
Expand All @@ -7,4 +8,4 @@ public function __construct($styleName)
{
parent::__construct("Invalid style $styleName.");
}
}
}
2 changes: 1 addition & 1 deletion tests/ConsoleColorTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpConsoleColor\Test;

use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor;
Expand Down Expand Up @@ -309,4 +310,3 @@ public function exceptionHelper($exception, $msg = null)
}
}
}

1 change: 1 addition & 0 deletions tests/Fixtures/ConsoleColorWithForceSupport.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PHP_Parallel_Lint\PhpConsoleColor\Test\Fixtures;

use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor;
Expand Down

0 comments on commit 0d14a2d

Please sign in to comment.