diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 7462b7b..31b617c 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -8,12 +8,12 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [7.4, 8.0, 8.2, 8.3] + php-versions: [7.4, 8.0, 8.2, 8.3, 8.4] name: PHP ${{ matrix.php-versions }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -33,7 +33,7 @@ jobs: - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} diff --git a/.github/workflows/phpunit_php5.yml b/.github/workflows/phpunit_php5.yml index e8b353e..8d6eb04 100644 --- a/.github/workflows/phpunit_php5.yml +++ b/.github/workflows/phpunit_php5.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 diff --git a/src/AbstractJsonSerializeObjData.php b/src/AbstractJsonSerializeObjData.php index b82801c..7b4ad87 100644 --- a/src/AbstractJsonSerializeObjData.php +++ b/src/AbstractJsonSerializeObjData.php @@ -69,7 +69,9 @@ final protected static function objectToJsonData($obj, $flags = 0, $objParents = if ($includeProps !== true && !in_array($propName, $includeProps)) { continue; } - $prop->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $prop->setAccessible(true); + } $propValue = $prop->getValue($obj); $result[$propName] = self::valueToJsonData($propValue, $flags, $objParents); } @@ -237,7 +239,9 @@ final protected static function fillObjFromValue($value, $obj, $flags = 0, $map } else { $reflect = new ReflectionObject($obj); foreach ($reflect->getProperties() as $prop) { - $prop->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $prop->setAccessible(true); + } $propName = $prop->getName(); if ($map !== null) { $map->setCurrent($propName, $current); diff --git a/src/JsonSerialize.php b/src/JsonSerialize.php index 67428bb..8da562f 100644 --- a/src/JsonSerialize.php +++ b/src/JsonSerialize.php @@ -114,7 +114,7 @@ public static function unserializeWithMap($json, JsonUnserializeMap $map, $depth public static function unserializeToObj($json, $obj, $depth = 512, $flags = 0) { if (is_object($obj)) { - } elseif (is_string($obj) && class_exists($obj)) { + } elseif (is_string($obj) && class_exists($obj)) { // @phpstan-ignore function.alreadyNarrowedType $obj = self::getObjFromClass($obj); } else { throw new Exception('invalid obj param'); @@ -210,7 +210,7 @@ protected static function convertString($string) if ($use_mb) { $encoding = mb_detect_encoding($string, null, true); if ($encoding) { - return mb_convert_encoding($string, 'UTF-8', $encoding); + return (string) mb_convert_encoding($string, 'UTF-8', $encoding); } else { return mb_convert_encoding($string, 'UTF-8', 'UTF-8'); } diff --git a/src/JsonUnserializeMap.php b/src/JsonUnserializeMap.php index 6b162a5..09b5fec 100644 --- a/src/JsonUnserializeMap.php +++ b/src/JsonUnserializeMap.php @@ -46,11 +46,11 @@ class JsonUnserializeMap /** * Class constructor * - * @param array $map values map + * @param array $map values map */ public function __construct($map = []) { - if (!is_array($map)) { + if (!is_array($map)) { // @phpstan-ignore function.alreadyNarrowedType throw new Exception('map must be an array'); } $this->map = new MapItem(); diff --git a/tests/StdClassTest.php b/tests/StdClassTest.php index 9ef38c4..8295ea1 100644 --- a/tests/StdClassTest.php +++ b/tests/StdClassTest.php @@ -51,7 +51,7 @@ public function testStdClass() $serializedValue = JsonSerialize::serialize($value); $this->assertTrue(is_string($serializedValue), 'Value is string'); $unserializedValue = JsonSerialize::unserialize($serializedValue); - $this->assertSame($unserializedValue->c->e, null, 'Test stdClass object recursion'); /** @phpstan-ignore-line */ + $this->assertSame($unserializedValue->c->e, null, 'Test stdClass object recursion'); $obj = new stdClass(); $obj->a = 1; diff --git a/tests/phpstan.neon b/tests/phpstan.neon index e27cfd9..20d7634 100644 --- a/tests/phpstan.neon +++ b/tests/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 9 + level: 8 paths: - .. excludePaths: