Skip to content
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

PHP 8.x Support #33

Merged
merged 5 commits into from
Aug 26, 2022
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
11 changes: 10 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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 }}
Expand Down Expand Up @@ -65,3 +71,6 @@ jobs:
run: vendor/bin/phpunit --testsuite Integration
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}

- name: Run PHPStan
run: vendor/bin/phpstan analyze
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
"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",
"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": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 1
paths:
- src
- config
4 changes: 2 additions & 2 deletions src/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Database/EloquentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Weebly\Mutate\Database;

use Closure;
use Illuminate\Contracts\Support\Arrayable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use statement got added, but this doesn't seem to be used anywhere in the file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually used here

public function whereKey($id)
{
if (is_array($id) || $id instanceof Arrayable) {
$this->whereIn($this->model->getQualifiedKeyName(), $id);

This is technically a bugfix ;)

use Illuminate\Database\Eloquent\Builder as BaseEloquentBuilder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression;
Expand Down Expand Up @@ -195,7 +196,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)
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/Database/Traits/HasMutators.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getMutators()
}

/**
* @param string $attribute
* @param string $attribute
* @return mixed|null
*/
public function getMutator($attribute)
Expand All @@ -84,7 +84,7 @@ public function getMutator($attribute)
}

/**
* @param mixed $attribute
* @param mixed $attribute
* @return bool
*/
public function hasMutator($attribute)
Expand Down
37 changes: 22 additions & 15 deletions src/MutatorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -43,7 +44,7 @@ public function set($name, $mutator)
}

/**
* @param string $mutator
* @param string $mutator
* @return bool
*/
public function exists($mutator)
Expand All @@ -52,7 +53,7 @@ public function exists($mutator)
}

/**
* @param array $mutators
* @param array $mutators
*/
public function registerMutators(array $mutators)
{
Expand All @@ -63,45 +64,51 @@ public function registerMutators(array $mutators)
}

/**
* @param string $offset
* @param string $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->exists($offset);
}

/**
* @param string $offset
* @param string $offset
* @return \Weebly\Mutate\Mutators\MutatorContract
*
* @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
}

/**
* @param string $offset
* @param mixed $value
* @param string $offset
* @param mixed $value
* @return \Weebly\Mutate\MutatorProvider
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
return $this->set($offset, $value);
}

/**
* @param string $offset
* @param string $offset
*/
#[\ReturnTypeWillChange]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What behavior are we driving from this? The composer.json still says php 7.x is OK. On 7, this will be a comment does that cause a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this attribute is necessary to prevent these errors in PHPStan (also, PHP will throw an error when executing this code in PHP 8.1 if this attribute is not added or the return type is not set correctly.

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/MutatorProvider.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
  69     Return type mixed of method Weebly\Mutate\MutatorProvider::offsetExists() is not covariant with tentative return type bool of method ArrayAccess::offsetExists().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
  89     Return type mixed of method Weebly\Mutate\MutatorProvider::offsetSet() is not covariant with tentative return type void of method ArrayAccess::offsetSet().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
  97     Return type mixed of method Weebly\Mutate\MutatorProvider::offsetUnset() is not covariant with tentative return type void of method ArrayAccess::offsetUnset().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------

In older PHP versions, since it is # prefixed, it will be ignored as a comment and will be perfectly fine, since it doesn't apply anyway.

public function offsetUnset($offset)
{
unset($this->mutators[$offset]);
}

/**
* @param string $name
* @param string $name
* @return \Weebly\Mutate\Mutators\MutatorContract
*
* @throws \Weebly\Mutate\Exceptions\MutatorNotFoundException
*/
public function __get($name)
Expand All @@ -110,16 +117,16 @@ public function __get($name)
}

/**
* @param string $name
* @param mixed $value
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
$this->set($name, $value);
}

/**
* @param string $key
* @param string $key
* @return bool
*/
public function __isset($key)
Expand All @@ -128,7 +135,7 @@ public function __isset($key)
}

/**
* @param string $key
* @param string $key
* @return void
*/
public function __unset($key)
Expand Down
2 changes: 1 addition & 1 deletion src/Mutators/EncryptStringMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mutators/IpBinaryMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class IpBinaryMutator implements MutatorContract
{
/**
* @param mixed $value
* @param mixed $value
* @return string
*/
public function serializeAttribute($value)
Expand All @@ -14,7 +14,7 @@ public function serializeAttribute($value)
}

/**
* @param mixed $value
* @param mixed $value
* @return bool|string
*/
public function unserializeAttribute($value)
Expand Down
4 changes: 2 additions & 2 deletions src/Mutators/MutatorContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/BelongsToManyMutatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class BelongsToManyMutatedTest extends TestCase
{
/**
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/MutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class MutatorTest extends TestCase
{
/**
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/PivotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class PivotTest extends TestCase
{
/**
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Mutators/HexBinaryMutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -49,7 +49,7 @@ public function hexProvider()
}

/**
* @param mixed $value
* @param mixed $value
* @dataProvider notHexProvider
*/
public function testWrongFormat($value)
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Mutators/IpBinaryMutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading