Skip to content

Upgrades, min PHP 7.4 #3

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 13 commits into from
Mar 15, 2025
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
use nix
watch_file flake.nix flake.lock
14 changes: 7 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ env:

jobs:
tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
matrix:
php:
- '8.4'
- '8.3'
- '8.2'
- '8.1'
- '8.0'
- '7.4'
- '7.3'
- '7.2'
include:
- php: '7.4'
cs_fixer: true
- php: '8.0'
phpstan: true
name: 'Check with PHP ${{ matrix.php }}'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v20
uses: cachix/install-nix-action@v31

- name: Set up Nix cache
uses: cachix/cachix-action@v12
uses: cachix/cachix-action@v16
with:
# Use cache from https://github.com/fossar/nix-phps
name: fossar
Expand All @@ -46,7 +46,7 @@ jobs:
run: |
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
composer.lock
vendor
vendor/
.direnv/
.php-cs-fixer.cache
.phpunit.result.cache
phpstan.neon
7 changes: 4 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

$rules = [
'@Symfony' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'phpdoc_to_param_type' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'phpdoc_to_property_type' => true,
// 'phpdoc_to_param_type' => true, // requires PHP 8.0
'phpdoc_to_return_type' => true,
// overwrite some Symfony rules
'concat_space' => ['spacing' => 'one'],
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [3.0.0] – unreleased

- Mb: Make encoding detection stricter.
- Raise minimum PHP version to 7.4.0.


## [2.0.0] – 2023-03-07
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"ddeboer/transcoder": "self.version"
},
"require": {
"php": ">=7.2.5"
"php": ">=7.4.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.2"
"symfony/phpunit-bridge": "^6.2 || ^7.0",
"phpstan/phpstan": "^2.1",
"friendsofphp/php-cs-fixer": "^3.4"
},
"suggest": {
"ext-mbstring": "For using the MbTranscoder",
Expand All @@ -34,7 +36,7 @@
},
"config": {
"platform": {
"php": "7.2.5"
"php": "7.4.0"
}
},
"scripts": {
Expand Down
42 changes: 30 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
# Composer and PHP.
php
phpBase.packages.composer

phpBase.packages.php-cs-fixer
phpBase.packages.phpstan
pkgs.phpactor
];

env = pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
};
};
}
File renamed without changes.
8 changes: 1 addition & 7 deletions src/IconvTranscoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class IconvTranscoder implements TranscoderInterface
{
/**
* @var string
*/
private $defaultEncoding;
private string $defaultEncoding;

/**
* Create an Iconv-based transcoder.
Expand All @@ -29,9 +26,6 @@ public function __construct(string $defaultEncoding = 'UTF-8')
$this->defaultEncoding = $defaultEncoding;
}

/**
* {@inheritdoc}
*/
public function transcode(string $string, ?string $from = null, ?string $to = null): string
{
set_error_handler(
Expand Down
14 changes: 3 additions & 11 deletions src/MbTranscoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ class MbTranscoder implements TranscoderInterface
/**
* @var array<string, int>
*/
private static $encodings;
private static array $encodings;

/**
* @var string
*/
private $defaultEncoding;
private string $defaultEncoding;

/**
* Create a Mb-based transcoder.
Expand All @@ -31,7 +28,7 @@ public function __construct(string $defaultEncoding = 'UTF-8')
throw new ExtensionMissingException('mb');
}

if (null === self::$encodings) {
if (!isset(self::$encodings)) {
self::$encodings = array_change_key_case(
array_flip(mb_list_encodings()),
CASE_LOWER
Expand All @@ -43,8 +40,6 @@ public function __construct(string $defaultEncoding = 'UTF-8')
}

/**
* {@inheritdoc}
*
* @param array<string>|string|null $from
*/
public function transcode(string $string, $from = null, ?string $to = null): string
Expand Down Expand Up @@ -77,9 +72,6 @@ public function transcode(string $string, $from = null, ?string $to = null): str
$from
);

// For PHPStan: We check the encoding is valid.
assert($result !== false);

return $result;
}

Expand Down
7 changes: 2 additions & 5 deletions src/Transcoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Transcoder implements TranscoderInterface
/**
* @var array<string, TranscoderInterface>
*/
private static $chain;
private static array $chain;

/**
* @var TranscoderInterface[]
*/
private $transcoders = [];
private array $transcoders = [];

/**
* @param TranscoderInterface[] $transcoders
Expand All @@ -27,9 +27,6 @@ public function __construct(array $transcoders)
$this->transcoders = $transcoders;
}

/**
* {@inheritdoc}
*/
public function transcode(string $string, ?string $from = null, ?string $to = null): string
{
foreach ($this->transcoders as $transcoder) {
Expand Down
5 changes: 1 addition & 4 deletions tests/IconvTranscoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class IconvTranscoderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var IconvTranscoder
*/
private $transcoder;
private IconvTranscoder $transcoder;

/**
* @before
Expand Down
5 changes: 1 addition & 4 deletions tests/MbTranscoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class MbTranscoderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var MbTranscoder
*/
private $transcoder;
private MbTranscoder $transcoder;

/**
* @before
Expand Down
5 changes: 1 addition & 4 deletions tests/TranscoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

class TranscoderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var TranscoderInterface
*/
private $transcoder;
private TranscoderInterface $transcoder;

/**
* @before
Expand Down