From 128a0c1ea295e68d4de196afe59cc4fc60e9422a Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 24 Jun 2023 17:16:35 -0700 Subject: [PATCH] Add PHP-CS-Fixer to check for unused imports --- composer.json | 1 + examples/flickr_upload_photo.php | 1 - examples/multi_curl_add_curl_from_url_list.php | 1 - src/Curl/ArrayUtil.php | 2 -- src/Curl/Curl.php | 4 ---- src/Curl/MultiCurl.php | 4 ---- src/Curl/Url.php | 2 -- tests/.php-cs-fixer.php | 13 +++++++++++++ tests/PHPCurlClass/PHPCurlClassTest.php | 2 +- tests/check_coding_standards.sh | 16 ++++++++++++++-- 10 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 tests/.php-cs-fixer.php diff --git a/composer.json b/composer.json index 389876e..6183bdd 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "*", "ext-gd": "*", + "friendsofphp/php-cs-fixer": "*", "phpcompatibility/php-compatibility": "dev-develop", "phpcsstandards/phpcsutils": "@alpha", "phpunit/phpunit": "*", diff --git a/examples/flickr_upload_photo.php b/examples/flickr_upload_photo.php index b32baec..543a591 100644 --- a/examples/flickr_upload_photo.php +++ b/examples/flickr_upload_photo.php @@ -2,7 +2,6 @@ require __DIR__ . '/../vendor/autoload.php'; require 'flickr.class.php'; -use Curl\Curl; use Flickr\Flickr; $flickr = new Flickr(); diff --git a/examples/multi_curl_add_curl_from_url_list.php b/examples/multi_curl_add_curl_from_url_list.php index 5515526..1ae433b 100644 --- a/examples/multi_curl_add_curl_from_url_list.php +++ b/examples/multi_curl_add_curl_from_url_list.php @@ -1,7 +1,6 @@ in(dirname(__DIR__)); + +$config = new PhpCsFixer\Config(); +$config + ->setRules([ + 'no_unused_imports' => true, + ]) + ->setFinder($finder); + +return $config; diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index e3fb38f..02f03da 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -4008,7 +4008,7 @@ class PHPCurlClassTest extends \PHPUnit\Framework\TestCase $expected_response = '{"name":"Alice","email":"alice@example.com"}'; - $user = new \Helper\User('Alice', 'alice@example.com'); + $user = new User('Alice', 'alice@example.com'); $this->assertEquals($expected_response, json_encode($user)); $test = new Test(); diff --git a/tests/check_coding_standards.sh b/tests/check_coding_standards.sh index 37fee06..3a8346b 100755 --- a/tests/check_coding_standards.sh +++ b/tests/check_coding_standards.sh @@ -132,6 +132,7 @@ if [[ ! -z "${is_null}" ]]; then errors+=("${result}") fi +# Run PHP_CodeSniffer. if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then : elif [[ "${CI_PHP_VERSION}" == "7.1" ]]; then : else @@ -153,8 +154,19 @@ else -s \ . if [[ "${?}" -ne 0 ]]; then - echo "Error: found coding standard violation(s)" - errors+=("found coding standard violation(s)") + echo "Error: found PHP_CodeSniffer coding standard violation(s)" + errors+=("found PHP_CodeSniffer coding standard violation(s)") fi fi + +# Run PHP-CS-Fixer. +if [[ "${CI_PHP_VERSION}" == "7.0" ]]; then : +else + vendor/bin/php-cs-fixer --version + vendor/bin/php-cs-fixer fix --ansi --config="tests/.php-cs-fixer.php" --diff --dry-run + if [[ "${?}" -ne 0 ]]; then + echo "Error: found PHP-CS-Fixer coding standard violation(s)" + errors+=("found PHP-CS-Fixer coding standard violation(s)") + fi +fi