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

[2.0] Strict types, native parameter & return types #192

Merged
merged 14 commits into from
Apr 30, 2019
Merged
2 changes: 1 addition & 1 deletion .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"docsSlug": "doctrine-collections",
"versions": [
{
"name": "master",
"name": "2.0",
"branchName": "master",
"slug": "latest",
"upcoming": true
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
environment:
php:
version: 7.1.3
version: 7.2

tools:
external_code_coverage:
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- $HOME/.composer/cache

php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
Expand Down Expand Up @@ -47,7 +46,7 @@ jobs:
- stage: Code Quality
env: STATIC_ANALYSIS
install: travis_retry composer install --prefer-dist
script: vendor/bin/phpstan analyse -l 3 lib
script: vendor/bin/phpstan analyse

- stage: Code Quality
env: STATIC_ANALYSIS
Expand Down
58 changes: 58 additions & 0 deletions UPGRADING-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Upgrading from 1.x to 2.0
=========================

## BC breaking changes

Native parameter and return types were added.
As a consequence, some signatures were changed and will have to be adjusted in sub-classes.

Note that in order to keep compatibility with both 1.x and 2.x versions, extending code would have to omit the added parameter types and add the return types. This would only work in PHP 7.2+ which is the first version featuring [parameter widening](https://wiki.php.net/rfc/parameter-no-type-variance).

You can find a list of major changes to public API below.

#### Doctrine\Common\Collections\Collection

| before | after |
|-------------------------------:|:-----------------------------------------------|
| add($element) | add($element): bool |
| clear() | clear(): void |
| contains($element) | contains($element): bool |
| isEmpty() | isEmpty(): bool |
| removeElement($element) | removeElement($element): bool |
| containsKey($key) | containsKey($key): bool |
| getKeys() | getKeys(): array |
| getValues() | getValues(): array |
| set($key, $value) | set($key, $value): void |
| toArray() | toArray(): array |
| exists(Closure $p) | exists(Closure $p): bool |
| filter(Closure $p) | filter(Closure $p): self |
| forAll(Closure $p) | forAll(Closure $p): bool |
| map(Closure $func) | map(Closure $func): self |
| partition(Closure $p) | partition(Closure $p): array |
| slice($offset, $length = null) | slice(int $offset, ?int $length = null): array |
| count() | count(): int |
| getIterator() | getIterator(): \Traversable |
| offsetSet($offset, $value) | offsetSet($offset, $value): void |
| offsetUnset($offset) | offsetUnset($offset): void |
| offsetExists($offset) | offsetExists($offset): bool |

#### Doctrine\Common\Collections\AbstractLazyCollection

| before | after |
|----------------:|:----------------------|
| isInitialized() | isInitialized(): bool |
| initialize() | initialize(): void |
| doInitialize() | doInitialize(): void |

#### Doctrine\Common\Collections\ArrayCollection

| before | after |
|----------------------------:|:----------------------------------|
| createFrom(array $elements) | createFrom(array $elements): self |
| __toString() | __toString(): string |

#### Doctrine\Common\Collections\Selectable

| before | after |
|-----------------------------:|:-----------------------------------------|
| matching(Criteria $criteria) | matching(Criteria $criteria): Collection |
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
],
"require": {
"php": "^7.1.3"
"php": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"doctrine/coding-standard": "^6.0",
"phpstan/phpstan-shim": "^0.9.2",
"vimeo/psalm": "^3.2.2",
"infection/infection": "^0.12.2"
"infection/infection": "^0.12.2",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpunit/phpunit": "^7.0",
"vimeo/psalm": "^3.2.2"
},
"config": {
"sort-packages": true
jwage marked this conversation as resolved.
Show resolved Hide resolved
},
"autoload": {
"psr-4": { "Doctrine\\Common\\Collections\\": "lib/Doctrine/Common/Collections" }
Expand All @@ -37,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.6.x-dev"
"dev-master": "2.0.x-dev"
}
}
}