-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
prolic
commented
Oct 6, 2016
•
edited
Loading
edited
- 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
*/ | ||
public static function nameNew($username) | ||
public static function nameNew(string $username): User | ||
{ | ||
//Perform assertions before raising a event | ||
\Assert\that($username)->notEmpty()->string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary "string" assert
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary string assert
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary string assert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codeliner your thoughts?
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
\Assert\that($newName)->notEmpty()->string(); | ||
Assertion::notEmpty($newName); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
@codeliner finished! puh |
/** | ||
* @param object $aggregateRoot | ||
* | ||
* @return int |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
*/ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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
There was a problem hiding this 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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?callable
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?callable