From 022da5191762ff9e6b5bdcbff5effd990c23e671 Mon Sep 17 00:00:00 2001
From: Petri Haikonen <petri.haikonen@ecxol.net>
Date: Thu, 6 Jan 2022 08:00:09 +0200
Subject: [PATCH] GitHub actions improvements and fixes

- Run actions on pull request
- Run actions with PHP 8.1 as well
- Fixes for Psalm failures
- Use Psalm provided by tools
- Run PHPUnit on correct PHP and PHPUnit versions
---
 .github/workflows/ci.yml | 36 +++++++++++++-----------------------
 src/Base32.php           |  6 +++---
 src/Base64.php           |  6 +++---
 src/Binary.php           |  2 ++
 4 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6d03527..ad1a48d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,6 +1,6 @@
 name: CI
 
-on: [push]
+on: [push, pull_request]
 
 jobs:
   old:
@@ -8,7 +8,7 @@ jobs:
     runs-on: ${{ matrix.operating-system }}
     strategy:
       matrix:
-        operating-system: ['ubuntu-16.04']
+        operating-system: ['ubuntu-latest']
         php-versions: ['7.0']
         phpunit-versions: ['6.5.14']
     steps:
@@ -21,15 +21,13 @@ jobs:
           php-version: ${{ matrix.php-versions }}
           extensions: mbstring, intl
           ini-values: post_max_size=256M, max_execution_time=180
-          tools: psalm, phpunit:${{ matrix.phpunit-versions }}
+          tools: phpunit:${{ matrix.phpunit-versions }}
 
       - name: Install dependencies
         run: composer self-update --1; composer install
 
       - name: PHPUnit tests
-        uses: php-actions/phpunit@v2
-        with:
-          memory_limit: 256M
+        run: phpunit
 
   moderate:
     name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
@@ -38,7 +36,7 @@ jobs:
       matrix:
         operating-system: ['ubuntu-latest']
         php-versions: ['7.1', '7.2', '7.3']
-        phpunit-versions: ['latest']
+        phpunit-versions: ['7.5.20']
     steps:
       - name: Checkout
         uses: actions/checkout@v2
@@ -49,22 +47,16 @@ jobs:
           php-version: ${{ matrix.php-versions }}
           extensions: mbstring, intl, sodium
           ini-values: post_max_size=256M, max_execution_time=180
-          tools: psalm, phpunit:${{ matrix.phpunit-versions }}
+          tools: psalm:4, phpunit:${{ matrix.phpunit-versions }}
 
       - name: Install dependencies
         run: composer install
 
-      - name: Modernize dependencies
-        run: composer require --dev "phpunit/phpunit:>=4"
-
       - name: PHPUnit tests
-        uses: php-actions/phpunit@v2
-        timeout-minutes: 30
-        with:
-          memory_limit: 256M
+        run: phpunit
 
       - name: Static Analysis
-        run: vendor/bin/psalm
+        run: psalm --output-format=github
 
   modern:
     name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
@@ -72,7 +64,7 @@ jobs:
     strategy:
       matrix:
         operating-system: ['ubuntu-latest']
-        php-versions: ['7.4', '8.0']
+        php-versions: ['7.4', '8.0', '8.1']
         phpunit-versions: ['latest']
     steps:
       - name: Checkout
@@ -84,15 +76,13 @@ jobs:
           php-version: ${{ matrix.php-versions }}
           extensions: mbstring, intl, sodium
           ini-values: post_max_size=256M, max_execution_time=180
-          tools: psalm, phpunit:${{ matrix.phpunit-versions }}
+          tools: psalm:4, phpunit:${{ matrix.phpunit-versions }}
 
       - name: Install dependencies
         run: composer install
+
       - name: PHPUnit tests
-        uses: php-actions/phpunit@v2
-        timeout-minutes: 30
-        with:
-          memory_limit: 256M
+        run: phpunit
 
       - name: Static Analysis
-        run: vendor/bin/psalm
+        run: psalm --output-format=github
diff --git a/src/Base32.php b/src/Base32.php
index 7784baf..9d61a60 100644
--- a/src/Base32.php
+++ b/src/Base32.php
@@ -60,13 +60,13 @@ abstract class Base32 implements EncoderInterface
     /**
      * Encode into Base32 (RFC 4648)
      *
-     * @param string $src
+     * @param string $binString
      * @return string
      * @throws \TypeError
      */
-    public static function encode(string $src): string
+    public static function encode(string $binString): string
     {
-        return static::doEncode($src, false, true);
+        return static::doEncode($binString, false, true);
     }
     /**
      * Encode into Base32 (RFC 4648)
diff --git a/src/Base64.php b/src/Base64.php
index 4739e48..637bed5 100644
--- a/src/Base64.php
+++ b/src/Base64.php
@@ -38,13 +38,13 @@ abstract class Base64 implements EncoderInterface
      *
      * Base64 character set "[A-Z][a-z][0-9]+/"
      *
-     * @param string $src
+     * @param string $binString
      * @return string
      * @throws \TypeError
      */
-    public static function encode(string $src): string
+    public static function encode(string $binString): string
     {
-        return static::doEncode($src, true);
+        return static::doEncode($binString, true);
     }
 
     /**
diff --git a/src/Binary.php b/src/Binary.php
index 38dbc4e..97fc268 100644
--- a/src/Binary.php
+++ b/src/Binary.php
@@ -46,6 +46,8 @@ abstract class Binary
     public static function safeStrlen(string $str): int
     {
         if (\function_exists('mb_strlen')) {
+            // mb_strlen in PHP 7.x can return false.
+            /** @psalm-suppress RedundantCast */
             return (int) \mb_strlen($str, '8bit');
         } else {
             return \strlen($str);
-- 
GitLab