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

Support for PHP 7.1 #31

Merged
merged 24 commits into from
Oct 27, 2016
Merged

Support for PHP 7.1 #31

merged 24 commits into from
Oct 27, 2016

Conversation

prolic
Copy link
Member

@prolic prolic commented Oct 6, 2016

  • Support for PHP 7.1
  • uses develop branch of prooph/common branch ("prooph/common" : "dev-develop as 4.0")
  • uses develop branch of prooph/event-store branch ("prooph/event-store" : "dev-develop as 7.0")
  • add snapshot namespace (moved from event-store)
  • add aggregate namespace (moved from event-store)
  • add docheader
  • update copyright

@prolic prolic added this to the 5.0 Release milestone Oct 6, 2016
@prolic prolic changed the base branch from master to develop October 6, 2016 14:26
*/
public static function nameNew($username)
public static function nameNew(string $username): User
{
//Perform assertions before raising a event
\Assert\that($username)->notEmpty()->string();
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary "string" assert

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

{
return $this->name;
}

/**
* @param $newName
*/
public function changeName($newName)
public function changeName(string $newName): void
{
\Assert\that($newName)->notEmpty()->string();
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary string assert

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

* @param string $aggregateId
*/
protected function setAggregateId($aggregateId)
protected function setAggregateId(string $aggregateId): void
{
Assertion::string($aggregateId);
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary string assert

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@prolic prolic added the BC break label Oct 7, 2016
Copy link
Member

@oqq oqq left a comment

Choose a reason for hiding this comment

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

I prefer to remove "beberlei/assert" as dependency, since it is used only to determine if a value is empty. Require a package for that is much overload.

{
//Perform assertions before raising a event
\Assert\that($username)->notEmpty()->string();
Assertion::notEmpty($username);
Copy link
Member

Choose a reason for hiding this comment

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

This line should be replaced, since the "beberlei/assert" dependency is not available in composer anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's part of prooph/common, so it's still a dependency

Copy link
Member

Choose a reason for hiding this comment

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

You are right.. I did not thought about that.
But then beberlei/assert should stay in composer.json as dependecy, when it is used src/AggregateChanged.php, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not want to repeat all requirements from prooph/common in all components, since it's already a dependency there. This also helps updating dependencies, as we only have to do it at one place.

Copy link
Member

Choose a reason for hiding this comment

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

Ok it seems to be a question of philosophy.
I disagree, but thats your decision. ☺️

Copy link
Member Author

Choose a reason for hiding this comment

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

@codeliner your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

oh, that's a good question ... both PoVs are valid.
When you rely on a dependency from another package and someone in the future decides to remove the dependency then you won't recognize it until hopefully a unit test or integration test will fail. So in general I would do it like suggested by @oqq but prooph/common is our "things we need in every package" package, so in this case @prolic 's argument is also a good one.

Let's go for the save version and handle all dependencies of a package in its composer.json. I already see the PR made by someone who think that we just forgot to add the dependency....

Copy link
Member

Choose a reason for hiding this comment

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

If prooph/common was third party I'd agree with @oqq but prooph/common is maintained by us so @prolic's idea with this is best suited imo.

{
\Assert\that($newName)->notEmpty()->string();
Assertion::notEmpty($newName);
Copy link
Member

Choose a reason for hiding this comment

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

This line should be replaced, since the "beberlei/assert" dependency is not available in composer anymore.

{
Assertion::string($aggregateId);
Assertion::notEmpty($aggregateId);
Copy link
Member

Choose a reason for hiding this comment

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

This line should be replaced, since the "beberlei/assert" dependency is not available in composer anymore.

@prolic
Copy link
Member Author

prolic commented Oct 26, 2016

@codeliner finished! puh

/**
* @param object $aggregateRoot
*
* @return int
Copy link
Member

Choose a reason for hiding this comment

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

duplicate return type hint

}

/**
* @param string $aggregateId
Copy link
Member

Choose a reason for hiding this comment

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

duplicate argument type hint

/**
* @param object $eventSourcedAggregateRoot
*
* @throws Exception\AggregateTypeException
Copy link
Member

Choose a reason for hiding this comment

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

This is exception is not throw in this method

/**
* Returns null if no stream events can be found for aggregate root otherwise the reconstituted aggregate root
*
* @param string $aggregateId
Copy link
Member

Choose a reason for hiding this comment

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

argument type hint duplicate

/**
* @param object $eventSourcedAggregateRoot
*
* @return int
Copy link
Member

Choose a reason for hiding this comment

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

return type hint duplicate

* @param object $eventSourcedAggregateRoot
*
* @return int
*/
Copy link
Member

Choose a reason for hiding this comment

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

missing 'throws' annotation


/**
* @param AggregateType $aggregateType
* @param Iterator $historyEvents
Copy link
Member

Choose a reason for hiding this comment

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

argument type hint duplicates


$recordedEvents = $eventSourcedAggregateRoot->{$this->popRecordedEventsMethodName}();

if (! is_array($recordedEvents) && ! $recordedEvents instanceof \Traversable) {
Copy link
Member

Choose a reason for hiding this comment

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

How about to use the new is_iterable function?

* @param string $aggregateId
* @param object $aggregateRoot
* @param int $lastVersion
* @param DateTimeImmutable $createdAt
Copy link
Member

Choose a reason for hiding this comment

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

Some duplicate parameter type hints

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but only some... waiting for object type hints :)

return $this->aggregateTranslator;
}

public function accessDeterminedStreamName(?string $aggregateId = null): StreamName
Copy link
Member

Choose a reason for hiding this comment

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

Is this a duplication from 'nullable'? '?string' AND '= null'

Choose a reason for hiding this comment

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

@oqq yes, the ? is optional here but it's perfectly valid and it's is more explicit this way. https://wiki.php.net/rfc/nullable_types

Copy link
Member

@codeliner codeliner left a comment

Choose a reason for hiding this comment

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

2 small things and a note. I'm off again. merge when ready.

@@ -9,7 +9,7 @@ Simple and lightweight event sourcing library with out of the box support for [P

#Installation

You can install ProophEventSourcing via composer by adding `"prooph/event-sourcing": "~4.0"` as requirement to your composer.json.
You can install ProophEventSourcing via composer by adding `"prooph/event-sourcing": "^5.0"` as requirement to your composer.json.
Copy link
Member

Choose a reason for hiding this comment

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

we should promote the composer require command which is available since some time now.
composer require prooph/event-sourcing (true for other prooph packages, too)

{
//Perform assertions before raising a event
\Assert\that($username)->notEmpty()->string();
Assertion::notEmpty($username);
Copy link
Member

Choose a reason for hiding this comment

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

oh, that's a good question ... both PoVs are valid.
When you rely on a dependency from another package and someone in the future decides to remove the dependency then you won't recognize it until hopefully a unit test or integration test will fail. So in general I would do it like suggested by @oqq but prooph/common is our "things we need in every package" package, so in this case @prolic 's argument is also a good one.

Let's go for the save version and handle all dependencies of a package in its composer.json. I already see the PR made by someone who think that we just forgot to add the dependency....

protected function enrichEventMetadata(Message $domainEvent, string $aggregateId): Message
{
$domainEvent = $domainEvent->withAddedMetadata('aggregate_id', $aggregateId);
return $domainEvent->withAddedMetadata('aggregate_type', $this->aggregateType->toString());
Copy link
Member

Choose a reason for hiding this comment

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

only a note, nothing required for this PR but it came to my mind when reading these lines:

when we add the aggregate version to event metadata we should also prefix it like:
$domainEvent = $domainEvent->withAddedMetadata('aggregate_version', $version);

@bweston92 this is what I meant in the prooph chat regarding version vs. position. Now the concept is really clear IMHO.

Version is no longer part of the Message interface, because only domain events have one. And the event store does not rely on the version, because it does not even know that it exists.

* @param object $eventSourcedAggregateRoot
* @param Iterator $events
*
* @return void

Choose a reason for hiding this comment

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

duplicated return type hint

/**
* Class AggregateRepository
*
* @package Prooph\EventSourcing\Aggregate

Choose a reason for hiding this comment

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

what's the point of duplicating the name and the namespace in the class comment? It doesn't add any value and it forces contributors to maintain these comments over time.

Copy link
Member

@oqq oqq Oct 26, 2016

Choose a reason for hiding this comment

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

I am with @lucascourot here. Since every 'package' annotation is equal to the namespace it should be omitted at all. https://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html

Also true for "Class WhatEver" comments. TBH i am using this also 2 years ago but removed it 1 year later. ;)

*
* @throws Exception\AggregateTypeException
*/
public function addAggregateRoot($eventSourcedAggregateRoot): void

Choose a reason for hiding this comment

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

Why can't we type these AggregateRoot arguments with the Prooph\EventSourcing\AggregateRoot type?

Copy link
Member

Choose a reason for hiding this comment

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

@lucascourot it is not necessary to implement this interface to get working with event sourcing. That is intentional and documented.. somewhere ;)

Choose a reason for hiding this comment

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

@oqq ok, got it!

private $staticReconstituteFromHistoryMethodName = 'reconstituteFromHistory';

/**
* @var null|callable

Choose a reason for hiding this comment

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

?callable

Copy link
Member

@oqq oqq Oct 26, 2016

Choose a reason for hiding this comment

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

?callable is not a valid type for that tag and would not work how expected in IDEs.

Choose a reason for hiding this comment

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

@oqq why not? It's valid in php for argument types.

Copy link
Member

Choose a reason for hiding this comment

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

Valid since PHP 7.1 as type hint. But I am not sure if it is supported by phpDocumentor, PhpStorm and doctrines annotation reader (as examples).

private $eventToMessageCallback = null;

/**
* @var null|callable

Choose a reason for hiding this comment

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

?callable

@prolic prolic merged commit 1023f48 into develop Oct 27, 2016
@prolic prolic deleted the php_7_1 branch October 27, 2016 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants