Skip to content

Commit

Permalink
Update for PHP 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-redfern committed Jan 21, 2021
1 parent bac4f79 commit 19a7791
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Change Log
==========

2020-12-18
2021-01-21
----------

* require PHP 8
* update to collection 5.0, domain 4.0

2020-12-18 - 2.2.0
------------------

* add bound parameter count check on relationships to prevent running queries without bound args

2020-10-22
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ active-record projects including GranadaORM (IdiORM), PHP ActiveRecord and other

## Requirements

* PHP 7.4+
* PHP 8.0+
* mb_string
* doctrine/dbal
* somnambulist/collection
Expand Down Expand Up @@ -192,6 +192,7 @@ somnambulist/collection project and must have `extract()` and `add()` methods.
## More Reading

* [Upgrading from 1.X to 2.0](docs/upgrading_1.X_to_2.0.md)
* [Upgrading from 2.X to 3.0](docs/upgrading_2.X_to_3.0.md)
* [Setting up Symfony](docs/setup_symfony.md)
* [Querying Data](docs/querying.md)
* [Casting Attributes](docs/casting.md)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-json": "*",
"doctrine/dbal": "~2.11",
"pagerfanta/pagerfanta": "~2.4",
"pragmarx/ia-str": "^7.0",
"somnambulist/attribute-model": "~1.0",
"somnambulist/collection": "~4.0"
"somnambulist/attribute-model": "~2.0",
"somnambulist/collection": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~9",
"phpunit/phpunit": "~9.5",
"creof/doctrine2-spatial": "~1.2",
"doctrine/doctrine-bundle": "~2.0",
"doctrine/orm": "^2.7",
"fzaninotto/faker": "~1.8",
"somnambulist/domain": "~3.0",
"fakerphp/faker": "^1.13",
"somnambulist/domain": "~4.0",
"symfony/dotenv": "^5.0",
"symfony/framework-bundle": "^5.0",
"symfony/messenger": "^5.0",
Expand Down
10 changes: 10 additions & 0 deletions docs/upgrading_2.X_to_3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

## Upgrading from 2.X to 3.0

The biggest change in 3.0 is the requirement for PHP 8. There are some minor type-hint related
changes, however the main APIs are the same as 2.X.

In addition note the following:

* `somnambulist/domain` has been updated and is now namespaced `Somnambulist\Components\Domain`
* `somnambulist/collection` has been updated and is now namespaced `Somnambulist\Components\Collection`
2 changes: 1 addition & 1 deletion src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(array $connections)
$this->forAll($connections);
}

public function forAll(array $connections)
public function forAll(array $connections): void
{
foreach ($connections as $model => $connection) {
$this->add($connection, $model);
Expand Down
8 changes: 4 additions & 4 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use IlluminateAgnostic\Str\Support\Str;
use JsonSerializable;
use LogicException;
use Somnambulist\Collection\Contracts\Arrayable;
use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Collection\Contracts\Jsonable;
use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\AttributeModel\AbstractModel;
use Somnambulist\Components\Collection\Contracts\Arrayable;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Jsonable;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\Exceptions\EntityNotFoundException;
use Somnambulist\Components\ReadModels\Relationships\AbstractRelationship;
use Somnambulist\Components\ReadModels\Relationships\BelongsTo;
Expand Down
22 changes: 11 additions & 11 deletions src/ModelBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use InvalidArgumentException;
use Pagerfanta\Pagerfanta;
use RuntimeException;
use Somnambulist\Collection\Contracts\Arrayable;
use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\Collection\Contracts\Arrayable;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\Contracts\Queryable;
use Somnambulist\Components\ReadModels\Exceptions\EntityNotFoundException;
use Somnambulist\Components\ReadModels\Exceptions\NoResultsException;
Expand All @@ -28,9 +28,9 @@
use function is_callable;
use function method_exists;
use function sprintf;
use function str_contains;
use function str_replace;
use function strlen;
use function strpos;
use function substr;
use function ucfirst;

Expand Down Expand Up @@ -277,7 +277,7 @@ public function with(...$relations): self
private function eagerLoadRelationships(Collection $models): void
{
foreach ($this->eagerLoad as $name => $constraints) {
if (false === strpos($name, '.')) {
if (false === str_contains($name, '.')) {
/** @var AbstractRelationship $load */
$rel = $this->model->new()->getRelationship($name);
$rel
Expand Down Expand Up @@ -546,7 +546,7 @@ public function orWhereNotIn(string $column, $values): self
*
* @return ModelBuilder
*/
public function whereColumn(string $column, string $operator, $value, string $andOr = 'and'): self
public function whereColumn(string $column, string $operator, mixed $value, string $andOr = 'and'): self
{
$key = $this->createParameterPlaceholderKey($column);
$method = $this->getAndOrWhereMethodName($andOr);
Expand All @@ -568,7 +568,7 @@ public function whereColumn(string $column, string $operator, $value, string $an
*
* @return ModelBuilder
*/
public function orWhereColumn(string $column, string $operator, $value): self
public function orWhereColumn(string $column, string $operator, mixed $value): self
{
return $this->whereColumn($column, $operator, $value, 'or');
}
Expand Down Expand Up @@ -621,7 +621,7 @@ public function orWhereNotNull(string $column): self
*
* @return ModelBuilder
*/
public function whereBetween(string $column, $start, $end, string $andOr = 'and', bool $not = false): self
public function whereBetween(string $column, mixed $start, mixed $end, string $andOr = 'and', bool $not = false): self
{
$method = $this->getAndOrWhereMethodName($andOr);
$expr = ($not ? 'NOT' : '') . ' BETWEEN';
Expand All @@ -635,17 +635,17 @@ public function whereBetween(string $column, $start, $end, string $andOr = 'and'
return $this;
}

public function whereNotBetween(string $column, $start, $end): self
public function whereNotBetween(string $column, mixed $start, mixed $end): self
{
return $this->whereBetween($column, $start, $end, 'and', true);
}

public function orWhereBetween(string $column, $start, $end): self
public function orWhereBetween(string $column, mixed $start, mixed $end): self
{
return $this->whereBetween($column, $start, $end, 'or');
}

public function orWhereNotBetween(string $column, $start, $end): self
public function orWhereNotBetween(string $column, mixed $start, mixed $end): self
{
return $this->whereBetween($column, $start, $end, 'or', true);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ModelExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Closure;
use IlluminateAgnostic\Str\Support\Str;
use Somnambulist\Collection\Contracts\Jsonable;
use Somnambulist\Collection\MutableCollection as Collection;
use Somnambulist\Components\Collection\Contracts\Jsonable;
use Somnambulist\Components\Collection\MutableCollection as Collection;
use Somnambulist\Components\ReadModels\Exceptions\JsonEncodingException;
use function count;
use function explode;
Expand Down Expand Up @@ -130,7 +130,7 @@ private function extractAttributes(array $attributes): array

foreach ($attributes as $key => $value) {
if ($this->shouldExtractAttribute($key)) {
$key = Str::snake($this->getAttributeExtractionKey($key), '_');
$key = Str::snake($this->getAttributeExtractionKey($key));

if (is_object($value)) {
$attrs[$key] = $this->extractPropertiesFrom($value);
Expand Down
2 changes: 1 addition & 1 deletion src/ModelIdentityMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function registerAlias(Model $model, ?string $foreignKeyName = null): voi
* @param string $target
* @param mixed $targetId
*/
public function registerRelationship(string $source, $sourceId, string $target, $targetId): void
public function registerRelationship(string $source, mixed $sourceId, string $target, mixed $targetId): void
{
$this->relationships[$source][(string)$sourceId][$target][(string)$targetId] = (string)$targetId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ModelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function externalKeyName(): ?string
*/
public function foreignKey(): string
{
$key = sprintf('%s_%s', Str::snake(ClassHelpers::getObjectShortClassName($this->model), '_'), $this->primaryKeyName());
$key = sprintf('%s_%s', Str::snake(ClassHelpers::getObjectShortClassName($this->model)), $this->primaryKeyName());

return $this->foreignKey ?? $key;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Relationships/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Pagerfanta\Pagerfanta;
use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\Contracts\Queryable;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Relationships;

use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Manager;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Relationships;

use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Manager;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Relationships;

use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Manager;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Relationships;

use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;

Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/HasOneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Relationships;

use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Manager;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/ClassHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function getCallingMethod(): string
*
* @return object
*/
public static function set(object $object, string $property, $value, $scope = null)
public static function set(object $object, string $property, mixed $value, mixed $scope = null)
{
Closure::bind(function () use ($property, $value) {
$this->{$property} = $value;
Expand All @@ -106,7 +106,7 @@ public static function set(object $object, string $property, $value, $scope = nu
*
* @return object
*/
public static function setPropertyArrayKey(object $object, string $property, string $key, $value, $scope = null)
public static function setPropertyArrayKey(object $object, string $property, string $key, mixed $value, mixed $scope = null)
{
Closure::bind(function () use ($property, $key, $value) {
$this->{$property}[$key] = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/FilterGeneratedKeysFromCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Somnambulist\Components\ReadModels\Utils;

use IlluminateAgnostic\Str\Support\Str;
use Somnambulist\Collection\MutableCollection as Collection;
use Somnambulist\Components\Collection\MutableCollection as Collection;
use Somnambulist\Components\ReadModels\Relationships\AbstractRelationship;
use function is_string;

Expand Down
4 changes: 2 additions & 2 deletions tests/ModelBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Pagerfanta\Pagerfanta;
use PHPUnit\Framework\TestCase;
use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Exceptions\EntityNotFoundException;
use Somnambulist\Components\ReadModels\Exceptions\NoResultsException;
use Somnambulist\Components\ReadModels\Model;
Expand All @@ -14,7 +14,7 @@
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\UserAddress;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\UserContact;
use Somnambulist\Components\ReadModels\Tests\Support\Behaviours\GetRandomUserId;
use Somnambulist\Domain\Entities\Types\DateTime\DateTime;
use Somnambulist\Components\Domain\Entities\Types\DateTime\DateTime;

/**
* Class ModelBuilderTest
Expand Down
4 changes: 2 additions & 2 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use BadMethodCallException;
use PHPUnit\Framework\TestCase;
use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\ModelBuilder;
use Somnambulist\Components\ReadModels\ModelExporter;
use Somnambulist\Components\ReadModels\Relationships\HasOneToMany;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\User;
use Somnambulist\Domain\Entities\Types\DateTime\DateTime;
use Somnambulist\Components\Domain\Entities\Types\DateTime\DateTime;
use function date;
use function password_hash;

Expand Down
2 changes: 1 addition & 1 deletion tests/Relationships/BelongsToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\DBAL\Query\QueryBuilder;
use PHPUnit\Framework\TestCase;
use Somnambulist\Collection\Contracts\Collection;
use Somnambulist\Components\Collection\Contracts\Collection;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
use Somnambulist\Components\ReadModels\Relationships\BelongsToMany;
Expand Down
3 changes: 1 addition & 2 deletions tests/Relationships/HasManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use Doctrine\DBAL\Query\QueryBuilder;
use PHPUnit\Framework\TestCase;
use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\ModelBuilder;
use Somnambulist\Components\ReadModels\Relationships\HasOneToMany;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\Address;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\User;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\UserAddress;
use Somnambulist\Components\ReadModels\Tests\Support\Behaviours\GetRandomUserIdWithRelationship;
Expand Down
4 changes: 2 additions & 2 deletions tests/Stubs/Casters/ContactCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Somnambulist\Components\AttributeModel\Contracts\AttributeCasterInterface;
use Somnambulist\Components\ReadModels\Tests\Stubs\Models\Contact;
use Somnambulist\Domain\Entities\Types\Identity\EmailAddress;
use Somnambulist\Domain\Entities\Types\PhoneNumber;
use Somnambulist\Components\Domain\Entities\Types\Identity\EmailAddress;
use Somnambulist\Components\Domain\Entities\Types\PhoneNumber;

/**
* Class ContactCaster
Expand Down
4 changes: 2 additions & 2 deletions tests/Stubs/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Somnambulist\Components\ReadModels\Tests\Stubs\Models;

use Somnambulist\Domain\Entities\Types\Identity\EmailAddress;
use Somnambulist\Domain\Entities\Types\PhoneNumber;
use Somnambulist\Components\Domain\Entities\Types\Identity\EmailAddress;
use Somnambulist\Components\Domain\Entities\Types\PhoneNumber;

/**
* Class Contact
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Somnambulist\Components\ReadModels\Tests\Stubs\Models;

use Somnambulist\Collection\MutableCollection;
use Somnambulist\Components\Collection\MutableCollection;
use Somnambulist\Components\ReadModels\Model;
use Somnambulist\Components\ReadModels\Relationships\BelongsToMany;

Expand Down
Loading

0 comments on commit 19a7791

Please sign in to comment.