Skip to content

Use PHP-Code-Style 2.0 #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
coverage: none
tools: cs2pr

# Remove PHPCS as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
# Remove the PHPCS standard as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
- name: 'Composer: remove PHPCS'
if: ${{ matrix.php < 5.4 }}
run: composer remove --dev squizlabs/php_codesniffer --no-update
run: composer remove --dev php-parallel-lint/php-code-style --no-update

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"php-parallel-lint/php-parallel-lint": "^1.0",
"php-parallel-lint/php-var-dump-check": "0.*",
"squizlabs/php_codesniffer": "3.*",
"php-parallel-lint/php-code-style": "1.0"
"php-parallel-lint/php-code-style": "^2.0"
},
"replace": {
"jakub-onderka/php-console-color": "*"
Expand Down
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
31 changes: 28 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?xml version="1.0"?>
<ruleset name="Jakub Onderka Coding Standard">
<ruleset name="PHP-Console-Color">
<description>A coding standard for Jakub Onderka's projects.</description>

<file>./src/</file>
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<!-- Scan all files. -->
<file>.</file>

<!-- Exclude dependencies and auto-generated files. -->
<exclude-pattern>*/build/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
Expand All @@ -13,6 +25,19 @@
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<rule ref="./vendor/php-parallel-lint/php-code-style/ruleset.xml"/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>


<!--
#############################################################################
USE THE PHPParallelLint RULESET
#############################################################################
-->

<!-- Set the supported PHP versions for PHPCompatibility (included in PHPParallelLint). -->
<config name="testVersion" value="5.3-"/>

<rule ref="PHPParallelLint"/>

</ruleset>
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