From 208acd6886e0b717c52c15bd4e4311a1a5fea8a3 Mon Sep 17 00:00:00 2001 From: Zain Mehdi Date: Tue, 26 Jul 2022 10:30:41 -0700 Subject: [PATCH 1/5] Add support for PHP 8.x --- .github/workflows/test.yaml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8125ef6..c64bc3c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: - php: [7.2, 7.3, 7.4, 8.0] + php: [7.2, 7.3, 7.4, 8.0, 8.1] laravel: [6.*, 7.*, 8.*] include: - laravel: 6.* diff --git a/composer.json b/composer.json index 573d990..6e59aa9 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "BSD-2-Clause", "keywords": ["laravel", "eloquent", "uuid", "encrypt", "database"], "require": { - "php": ">=7.2", + "php": ">=7.2 || ^8.0", "ramsey/uuid": "~3.0 || ~4.0", "illuminate/database": "^6.0 || ^7.0 || ^8.0", "illuminate/support": "^6.0 || ^7.0 || ^8.0", From 31f8d98a1576d4d930c77109e418d938776b635a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 26 Jul 2022 17:30:57 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- .../Eloquent/Relations/BelongsToMany.php | 4 +-- src/Database/EloquentBuilder.php | 2 +- src/Database/Model.php | 2 +- src/Database/Traits/HasMutators.php | 14 ++++---- src/MutatorProvider.php | 33 ++++++++++--------- src/Mutators/EncryptStringMutator.php | 2 +- src/Mutators/IpBinaryMutator.php | 4 +-- src/Mutators/MutatorContract.php | 4 +-- .../Integration/BelongsToManyMutatedTest.php | 2 +- tests/Integration/MutatorTest.php | 2 +- tests/Integration/PivotTest.php | 2 +- tests/Unit/Mutators/HexBinaryMutatorTest.php | 10 +++--- tests/Unit/Mutators/IpBinaryMutatorTest.php | 8 ++--- .../Mutators/UnixTimestampMutatorTest.php | 8 ++--- .../Unit/Mutators/UuidV1BinaryMutatorTest.php | 14 ++++---- 15 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/Database/Eloquent/Relations/BelongsToMany.php b/src/Database/Eloquent/Relations/BelongsToMany.php index f2ec716..6aa1460 100644 --- a/src/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Database/Eloquent/Relations/BelongsToMany.php @@ -94,7 +94,7 @@ protected function buildDictionary(Collection $results) /** * Create a new pivot attachment record. * - * @param int $id + * @param int $id * @param bool $timed * @return array */ @@ -198,7 +198,7 @@ protected function parseIds($value) * Sync the intermediate tables with a list of IDs or collection of models. * * @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|array $ids - * @param bool $detaching + * @param bool $detaching * @return array */ public function sync($ids, $detaching = true) diff --git a/src/Database/EloquentBuilder.php b/src/Database/EloquentBuilder.php index 198ee26..10034f1 100644 --- a/src/Database/EloquentBuilder.php +++ b/src/Database/EloquentBuilder.php @@ -195,7 +195,7 @@ public function pluck($column, $key = null) /** * Get the column name without any table prefix. * - * @param string $column + * @param string $column * @return string */ protected function getUnqualifiedColumnName($column) diff --git a/src/Database/Model.php b/src/Database/Model.php index 4b6fc58..d896a4e 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -11,7 +11,7 @@ abstract class Model extends Eloquent use HasMutators; /** - * @param string $key + * @param string $key * @return \Illuminate\Foundation\Application|mixed */ public function getAttribute($key) diff --git a/src/Database/Traits/HasMutators.php b/src/Database/Traits/HasMutators.php index 9bc97ac..a3dabf5 100644 --- a/src/Database/Traits/HasMutators.php +++ b/src/Database/Traits/HasMutators.php @@ -17,8 +17,8 @@ trait HasMutators protected $mutatedCache = []; /** - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * @return \Illuminate\Foundation\Application|mixed */ public function serializeAttribute($attribute, $value) @@ -39,9 +39,9 @@ public function serializeAttribute($attribute, $value) } /** - * @param string $attribute - * @param mixed $value - * @param bool $force + * @param string $attribute + * @param mixed $value + * @param bool $force * @return mixed */ public function unserializeAttribute($attribute, $value, $force = false) @@ -73,7 +73,7 @@ public function getMutators() } /** - * @param string $attribute + * @param string $attribute * @return mixed|null */ public function getMutator($attribute) @@ -84,7 +84,7 @@ public function getMutator($attribute) } /** - * @param mixed $attribute + * @param mixed $attribute * @return bool */ public function hasMutator($attribute) diff --git a/src/MutatorProvider.php b/src/MutatorProvider.php index 5dead9b..a3790ee 100644 --- a/src/MutatorProvider.php +++ b/src/MutatorProvider.php @@ -14,8 +14,9 @@ class MutatorProvider implements ArrayAccess protected $mutators = []; /** - * @param string $mutator + * @param string $mutator * @return \Weebly\Mutate\Mutators\MutatorContract + * * @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException */ public function get($mutator) @@ -31,8 +32,8 @@ public function get($mutator) } /** - * @param string $name - * @param mixed $mutator + * @param string $name + * @param mixed $mutator * @return $this */ public function set($name, $mutator) @@ -43,7 +44,7 @@ public function set($name, $mutator) } /** - * @param string $mutator + * @param string $mutator * @return bool */ public function exists($mutator) @@ -52,7 +53,7 @@ public function exists($mutator) } /** - * @param array $mutators + * @param array $mutators */ public function registerMutators(array $mutators) { @@ -63,7 +64,7 @@ public function registerMutators(array $mutators) } /** - * @param string $offset + * @param string $offset * @return bool */ public function offsetExists($offset) @@ -72,8 +73,9 @@ public function offsetExists($offset) } /** - * @param string $offset + * @param string $offset * @return \Weebly\Mutate\Mutators\MutatorContract + * * @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException */ public function offsetGet($offset) @@ -82,8 +84,8 @@ public function offsetGet($offset) } /** - * @param string $offset - * @param mixed $value + * @param string $offset + * @param mixed $value * @return \Weebly\Mutate\MutatorProvider */ public function offsetSet($offset, $value) @@ -92,7 +94,7 @@ public function offsetSet($offset, $value) } /** - * @param string $offset + * @param string $offset */ public function offsetUnset($offset) { @@ -100,8 +102,9 @@ public function offsetUnset($offset) } /** - * @param string $name + * @param string $name * @return \Weebly\Mutate\Mutators\MutatorContract + * * @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException */ public function __get($name) @@ -110,8 +113,8 @@ public function __get($name) } /** - * @param string $name - * @param mixed $value + * @param string $name + * @param mixed $value */ public function __set($name, $value) { @@ -119,7 +122,7 @@ public function __set($name, $value) } /** - * @param string $key + * @param string $key * @return bool */ public function __isset($key) @@ -128,7 +131,7 @@ public function __isset($key) } /** - * @param string $key + * @param string $key * @return void */ public function __unset($key) diff --git a/src/Mutators/EncryptStringMutator.php b/src/Mutators/EncryptStringMutator.php index e8d22e8..79d023b 100644 --- a/src/Mutators/EncryptStringMutator.php +++ b/src/Mutators/EncryptStringMutator.php @@ -13,7 +13,7 @@ class EncryptStringMutator implements MutatorContract protected $encrypt; /** - * @param \Illuminate\Contracts\Encryption\Encrypter $encrypt + * @param \Illuminate\Contracts\Encryption\Encrypter $encrypt */ public function __construct(Encrypter $encrypt) { diff --git a/src/Mutators/IpBinaryMutator.php b/src/Mutators/IpBinaryMutator.php index d60e315..2ce672a 100644 --- a/src/Mutators/IpBinaryMutator.php +++ b/src/Mutators/IpBinaryMutator.php @@ -5,7 +5,7 @@ class IpBinaryMutator implements MutatorContract { /** - * @param mixed $value + * @param mixed $value * @return string */ public function serializeAttribute($value) @@ -14,7 +14,7 @@ public function serializeAttribute($value) } /** - * @param mixed $value + * @param mixed $value * @return bool|string */ public function unserializeAttribute($value) diff --git a/src/Mutators/MutatorContract.php b/src/Mutators/MutatorContract.php index ad64d3a..d4117be 100644 --- a/src/Mutators/MutatorContract.php +++ b/src/Mutators/MutatorContract.php @@ -5,12 +5,12 @@ interface MutatorContract { /** - * @param mixed $value + * @param mixed $value */ public function serializeAttribute($value); /** - * @param mixed $value + * @param mixed $value * @return mixed */ public function unserializeAttribute($value); diff --git a/tests/Integration/BelongsToManyMutatedTest.php b/tests/Integration/BelongsToManyMutatedTest.php index 39022a2..f290259 100644 --- a/tests/Integration/BelongsToManyMutatedTest.php +++ b/tests/Integration/BelongsToManyMutatedTest.php @@ -16,7 +16,7 @@ class BelongsToManyMutatedTest extends TestCase { /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ protected function getEnvironmentSetUp($app) { diff --git a/tests/Integration/MutatorTest.php b/tests/Integration/MutatorTest.php index 9160796..621c6ce 100644 --- a/tests/Integration/MutatorTest.php +++ b/tests/Integration/MutatorTest.php @@ -15,7 +15,7 @@ class MutatorTest extends TestCase { /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ protected function getEnvironmentSetUp($app) { diff --git a/tests/Integration/PivotTest.php b/tests/Integration/PivotTest.php index 119b700..6763f1b 100644 --- a/tests/Integration/PivotTest.php +++ b/tests/Integration/PivotTest.php @@ -13,7 +13,7 @@ class PivotTest extends TestCase { /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ protected function getEnvironmentSetUp($app) { diff --git a/tests/Unit/Mutators/HexBinaryMutatorTest.php b/tests/Unit/Mutators/HexBinaryMutatorTest.php index c7a75f1..963a5b7 100644 --- a/tests/Unit/Mutators/HexBinaryMutatorTest.php +++ b/tests/Unit/Mutators/HexBinaryMutatorTest.php @@ -8,8 +8,8 @@ class HexBinaryMutatorTest extends TestCase { /** - * @param string $hex - * @param string $expected + * @param string $hex + * @param string $expected * @dataProvider hexProvider */ public function testSerialize($hex, $expected) @@ -18,8 +18,8 @@ public function testSerialize($hex, $expected) } /** - * @param string $expected - * @param string $binary + * @param string $expected + * @param string $binary * @dataProvider hexProvider */ public function testUnserialize($expected, $binary) @@ -49,7 +49,7 @@ public function hexProvider() } /** - * @param mixed $value + * @param mixed $value * @dataProvider notHexProvider */ public function testWrongFormat($value) diff --git a/tests/Unit/Mutators/IpBinaryMutatorTest.php b/tests/Unit/Mutators/IpBinaryMutatorTest.php index 2be0ef9..b197e59 100644 --- a/tests/Unit/Mutators/IpBinaryMutatorTest.php +++ b/tests/Unit/Mutators/IpBinaryMutatorTest.php @@ -7,8 +7,8 @@ class IpBinaryMutatorTest extends TestCase { /** - * @param string $ip - * @param string $expected + * @param string $ip + * @param string $expected * @dataProvider readableIpDataProvider */ public function testSerializeAttribute($ip, $expected) @@ -17,8 +17,8 @@ public function testSerializeAttribute($ip, $expected) } /** - * @param string $ip - * @param string $expected + * @param string $ip + * @param string $expected * @dataProvider packedIpDataProvider */ public function testUnserializeAttribute($ip, $expected) diff --git a/tests/Unit/Mutators/UnixTimestampMutatorTest.php b/tests/Unit/Mutators/UnixTimestampMutatorTest.php index 5c8498b..f2a5f83 100644 --- a/tests/Unit/Mutators/UnixTimestampMutatorTest.php +++ b/tests/Unit/Mutators/UnixTimestampMutatorTest.php @@ -8,8 +8,8 @@ class UnixTimestampMutatorTest extends TestCase { /** - * @param string $carbon - * @param string $expected + * @param string $carbon + * @param string $expected * @dataProvider carbonProvider */ public function testSerialize($carbon, $expected) @@ -18,8 +18,8 @@ public function testSerialize($carbon, $expected) } /** - * @param string $expected - * @param string $binary + * @param string $expected + * @param string $binary * @dataProvider carbonProvider */ public function testUnserialize($expected, $timestamp) diff --git a/tests/Unit/Mutators/UuidV1BinaryMutatorTest.php b/tests/Unit/Mutators/UuidV1BinaryMutatorTest.php index 365cb8e..78f4e97 100644 --- a/tests/Unit/Mutators/UuidV1BinaryMutatorTest.php +++ b/tests/Unit/Mutators/UuidV1BinaryMutatorTest.php @@ -8,8 +8,8 @@ class UuidV1BinaryMutatorTest extends TestCase { /** - * @param string $uuid - * @param string $expected + * @param string $uuid + * @param string $expected * @dataProvider validUuidDataProvider */ public function testSerializeValidUuid($uuid, $expected) @@ -18,9 +18,9 @@ public function testSerializeValidUuid($uuid, $expected) } /** - * @param string $uuid - * @param string $exception - * @param string $exceptionMessage + * @param string $uuid + * @param string $exception + * @param string $exceptionMessage * @dataProvider invalidUuidDataProvider */ public function testSerializeInvalidUuid($uuid, $exception, $exceptionMessage) @@ -32,8 +32,8 @@ public function testSerializeInvalidUuid($uuid, $exception, $exceptionMessage) } /** - * @param string $value - * @param mixed $expected + * @param string $value + * @param mixed $expected * @dataProvider validOrderedUuidDataProvider */ public function testUnserializeAttribute($value, $expected) From dbc83d3ab5b2b5bad444884a267a12df1fcf7f26 Mon Sep 17 00:00:00 2001 From: Zain Mehdi Date: Tue, 26 Jul 2022 10:48:25 -0700 Subject: [PATCH 3/5] Fix PHP 8.1 compatibility and run PHPStan. --- .github/workflows/test.yaml | 3 +++ composer.json | 7 +++---- phpstan.neon | 5 +++++ src/Database/EloquentBuilder.php | 1 + src/MutatorProvider.php | 4 ++++ 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c64bc3c..0d79c14 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -65,3 +65,6 @@ jobs: run: vendor/bin/phpunit --testsuite Integration env: DB_PORT: ${{ job.services.mysql.ports[3306] }} + + - name: Run PHPStan + run: vendor/bin/phpstan analyze diff --git a/composer.json b/composer.json index 6e59aa9..ff0b4e4 100644 --- a/composer.json +++ b/composer.json @@ -7,15 +7,14 @@ "require": { "php": ">=7.2 || ^8.0", "ramsey/uuid": "~3.0 || ~4.0", - "illuminate/database": "^6.0 || ^7.0 || ^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "illuminate/encryption": "^6.0 || ^7.0 || ^8.0" + "laravel/framework": "^6.0 || ^7.0 || ^8.0" }, "require-dev": { "mockery/mockery": "^1.0", "phpunit/phpunit": "^8.0", "laravel/framework": "8.*", - "orchestra/testbench": "^6.0" + "orchestra/testbench": "^6.0", + "phpstan/phpstan": "^1.8" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..3a115e3 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 1 + paths: + - src + - config diff --git a/src/Database/EloquentBuilder.php b/src/Database/EloquentBuilder.php index 10034f1..925bf68 100644 --- a/src/Database/EloquentBuilder.php +++ b/src/Database/EloquentBuilder.php @@ -3,6 +3,7 @@ namespace Weebly\Mutate\Database; use Closure; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder as BaseEloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression; diff --git a/src/MutatorProvider.php b/src/MutatorProvider.php index a3790ee..1fa793c 100644 --- a/src/MutatorProvider.php +++ b/src/MutatorProvider.php @@ -67,6 +67,7 @@ public function registerMutators(array $mutators) * @param string $offset * @return bool */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return $this->exists($offset); @@ -78,6 +79,7 @@ public function offsetExists($offset) * * @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); @@ -88,6 +90,7 @@ public function offsetGet($offset) * @param mixed $value * @return \Weebly\Mutate\MutatorProvider */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { return $this->set($offset, $value); @@ -96,6 +99,7 @@ public function offsetSet($offset, $value) /** * @param string $offset */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->mutators[$offset]); From ee873c3678a4a300710f5e03b154d42d3dbfc383 Mon Sep 17 00:00:00 2001 From: Zain Mehdi Date: Tue, 26 Jul 2022 10:57:45 -0700 Subject: [PATCH 4/5] Remove incompatible PHP / Laravel combinations from test matrix --- .github/workflows/test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0d79c14..c53800d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,6 +37,12 @@ jobs: php: 7.1 - laravel: 8.* php: 7.2 + # Laravel 6 only support PHP <=8.0 + - laravel: 6.* + php: 8.1 + # Laravel 7 only support PHP <=8.0 + - laravel: 7.* + php: 8.1 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} From aab32b1d37919f76aefb30337e171e7da666fd9b Mon Sep 17 00:00:00 2001 From: Zain Mehdi Date: Tue, 26 Jul 2022 10:59:22 -0700 Subject: [PATCH 5/5] Fix workflow yaml --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c53800d..a4a14ce 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,10 +39,10 @@ jobs: php: 7.2 # Laravel 6 only support PHP <=8.0 - laravel: 6.* - php: 8.1 + php: 8.1 # Laravel 7 only support PHP <=8.0 - laravel: 7.* - php: 8.1 + php: 8.1 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}