From 6364360287c12baf159db0a14ae342686c9064ce Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Thu, 16 May 2024 18:19:51 -0700 Subject: [PATCH] ci: create an initial linting CI This was copied for the most part from https://github.com/phpmyadmin/phpmyadmin/blob/b094f337466a1188ad755b33be5a7b7b25a70916/.github/workflows/lint-and-analyse-php.yml --- .github/workflows/lint-and-analyse-php.yml | 91 +++++++++++++++++++ ci/ci-phplint | 16 ++++ lib/external/FeedWriter/FeedWriter.php | 5 +- .../pear/Config/Container/IniCommented.php | 2 +- lib/external/pear/Config/Container/XML.php | 2 +- lib/external/pear/Event/Dispatcher.php | 4 +- lib/external/pear/System.php | 4 +- 7 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/lint-and-analyse-php.yml create mode 100755 ci/ci-phplint diff --git a/.github/workflows/lint-and-analyse-php.yml b/.github/workflows/lint-and-analyse-php.yml new file mode 100644 index 000000000..673b21e94 --- /dev/null +++ b/.github/workflows/lint-and-analyse-php.yml @@ -0,0 +1,91 @@ +name: Lint and analyse php files + +# If a pull-request is pushed then cancel all previously running jobs related +# to that pull-request +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +on: + # push: + pull_request: + types: [opened, synchronize, reopened] + branches: + - develop + +permissions: + contents: read + +jobs: + lint-php-files: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ["8.1"] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + # TODO: Enable this after resolving issues + # - name: Validate composer.json and composer.lock + # run: composer validate --strict + + - name: Install Composer dependencies + # Allow the previous check to fail but not abort + if: always() + uses: ramsey/composer-install@v2 + with: + # Ignore zip for php-webdriver/webdriver + composer-options: "--ignore-platform-req=ext-zip" + + # TODO: Enable this after resolving issues + # - name: Cache coding-standard + # # Allow the previous check to fail but not abort + # if: always() + # uses: actions/cache@v4 + # with: + # path: .phpcs-cache + # key: phpcs-cache + + - name: Lint PHP files + # Allow the previous check to fail but not abort + if: always() + run: ./ci/ci-phplint + + # TODO: Enable this after resolving issues + # - name: Check coding-standard + # # Allow the previous check to fail but not abort + # if: always() + # run: composer phpcs + +# TODO: Enable this after resolving issues +# analyse-php: +# runs-on: ubuntu-latest +# strategy: +# matrix: +# php-version: ["8.1"] +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 +# +# - name: Set up PHP ${{ matrix.php-version }} +# uses: shivammathur/setup-php@v2 +# with: +# php-version: ${{ matrix.php-version }} +# extensions: mbstring, iconv, mysqli, zip, gd, bz2 +# +# - name: Install Composer dependencies +# uses: ramsey/composer-install@v2 +# +# - name: Analyse files with PHPStan +# run: composer phpstan -- --memory-limit 2G +# +# - name: Analyse files with Psalm +# # Allow the previous check to fail but not abort +# if: always() +# run: composer psalm -- --shepherd diff --git a/ci/ci-phplint b/ci/ci-phplint new file mode 100755 index 000000000..5f8a47cf4 --- /dev/null +++ b/ci/ci-phplint @@ -0,0 +1,16 @@ +#!/bin/sh + +FILES=$(find . -name '*.php' -not -path './vendor/*' -not -path './tmp/*' -not -path './node_modules/*') + +result=0 +for FILE in $FILES ; do + if [ -f "$FILE" ] ; then + php -l "$FILE" + ret=$? + if [ $ret != 0 ] ; then + result=$ret + fi + fi +done + +exit $result diff --git a/lib/external/FeedWriter/FeedWriter.php b/lib/external/FeedWriter/FeedWriter.php index 167626058..d51270968 100644 --- a/lib/external/FeedWriter/FeedWriter.php +++ b/lib/external/FeedWriter/FeedWriter.php @@ -429,7 +429,6 @@ private function endItem() } // end of class FeedWriter // autoload classes -function __autoload($class_name) -{ +spl_autoload_register(function ($class_name) { require_once $class_name . '.php'; -} \ No newline at end of file +}); diff --git a/lib/external/pear/Config/Container/IniCommented.php b/lib/external/pear/Config/Container/IniCommented.php index 3b4175018..e1fe07464 100644 --- a/lib/external/pear/Config/Container/IniCommented.php +++ b/lib/external/pear/Config/Container/IniCommented.php @@ -164,7 +164,7 @@ function _quoteAndCommaParser($text) $pos = 0; // position in $text do { - $char = $text{$pos}; + $char = $text[$pos]; $state = $this->_getQACEvent($stack); if ($tokens[$state]) { diff --git a/lib/external/pear/Config/Container/XML.php b/lib/external/pear/Config/Container/XML.php index f56aaa13d..3867e747b 100644 --- a/lib/external/pear/Config/Container/XML.php +++ b/lib/external/pear/Config/Container/XML.php @@ -131,7 +131,7 @@ function &parseDatasrc($datasrc, &$obj) */ function startHandler($xp, $elem, &$attribs) { - $container =& new Config_Container('section', $elem, null, $attribs); + $container = new Config_Container('section', $elem, null, $attribs); $this->containers[] =& $container; return null; } // end func startHandler diff --git a/lib/external/pear/Event/Dispatcher.php b/lib/external/pear/Event/Dispatcher.php index 455f386f2..2bb8534c7 100644 --- a/lib/external/pear/Event/Dispatcher.php +++ b/lib/external/pear/Event/Dispatcher.php @@ -246,7 +246,7 @@ function addObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null) */ function &post(&$object, $nName, $info = array(), $pending = true, $bubble = true) { - $notification =& new $this->_notificationClass($object, $nName, $info); + $notification =& $this->_notificationClass($object, $nName, $info); return $this->postNotification($notification, $pending, $bubble); } @@ -475,4 +475,4 @@ function setNotificationClass($class) } } -?> \ No newline at end of file +?> diff --git a/lib/external/pear/System.php b/lib/external/pear/System.php index a2b99166f..4e09aacb6 100644 --- a/lib/external/pear/System.php +++ b/lib/external/pear/System.php @@ -235,7 +235,7 @@ function mkDir($args) } elseif($opt[0] == 'm') { // if the mode is clearly an octal number (starts with 0) // convert it to decimal - if (strlen($opt[1]) && $opt[1]{0} == '0') { + if (strlen($opt[1]) && $opt[1][0] == '0') { $opt[1] = octdec($opt[1]); } else { // convert to int @@ -584,4 +584,4 @@ function find($args) return $files; } } -?> \ No newline at end of file +?>