Skip to content

Commit 3dc9a2b

Browse files
Olivier DolbeauNyholm
authored andcommitted
PHP7.2 & strict type hinting (#22)
1 parent ceac357 commit 3dc9a2b

File tree

13 files changed

+94
-139
lines changed

13 files changed

+94
-139
lines changed

.github/workflows/static.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on: [push, pull_request]
2+
name: Static analysis
3+
jobs:
4+
phpstan:
5+
name: PHPStan
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@master
9+
- name: PHPStan
10+
uses: docker://oskarstark/phpstan-ga
11+
with:
12+
args: analyze --no-progress
13+
14+
php-cs-fixer:
15+
name: PHP-CS-Fixer
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@master
19+
- name: PHP-CS-Fixer
20+
uses: docker://oskarstark/php-cs-fixer-ga
21+
with:
22+
args: --dry-run --diff-format udiff

.php_cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?php
22

3-
/*
4-
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
5-
* with composer.
6-
*
7-
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
8-
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
9-
*/
3+
$config = PhpCsFixer\Config::create()
4+
->setRiskyAllowed(true)
5+
->setRules([
6+
'@Symfony' => true,
7+
'@Symfony:risky' => true,
8+
'array_syntax' => ['syntax' => 'short'],
9+
])
10+
->setFinder(
11+
PhpCsFixer\Finder::create()
12+
->in(__DIR__)
13+
->exclude(__DIR__.'/vendor')
14+
->name('*.php')
15+
)
16+
;
1017

11-
use SLLH\StyleCIBridge\ConfigBridge;
12-
13-
return ConfigBridge::create();
18+
return $config;

.styleci.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.travis.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,21 @@ matrix:
1717
fast_finish: true
1818
include:
1919
# Test with lowest dependencies
20-
- php: 7.1
21-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
22-
- php: 5.5
20+
- php: 7.2
2321
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
2422

2523
# Test the latest stable release
26-
- php: 5.4
27-
- php: 5.5
28-
- php: 5.6
29-
- php: 7.0
30-
- php: 7.1
31-
- php: 7.2
24+
- php: 7.3
3225
env: COVERAGE=true TEST_COMMAND="composer test-ci"
3326

3427
# Force some major versions of Symfony
35-
- php: 7.2
36-
env: DEPENDENCIES="dunglas/symfony-lock:^2"
37-
- php: 7.2
28+
- php: 7.3
3829
env: DEPENDENCIES="dunglas/symfony-lock:^3"
39-
- php: 7.2
30+
- php: 7.3
4031
env: DEPENDENCIES="dunglas/symfony-lock:^4"
4132

4233
# Latest commit to master
43-
- php: 7.2
34+
- php: 7.4snapshot
4435
env: STABILITY="dev"
4536

4637
allow_failures:
@@ -56,7 +47,6 @@ install:
5647
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
5748
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
5849
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
59-
- vendor/bin/simple-phpunit install
6050

6151
script:
6252
- composer validate --strict --no-check-lock

Changelog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22

3-
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
3+
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
4+
5+
## 2.0.0
6+
7+
Drop support og php < 7.2
8+
Add strict I/O type hinting
49

510
## 1.0.0
611

@@ -27,7 +32,7 @@ No changes since 0.3.0.
2732

2833
### Changed
2934

30-
- Documentation change on interface.
35+
- Documentation change on interface.
3136

3237
## 0.2.1
3338

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
}
1010
],
1111
"require": {
12-
"php": "^5.4 || ^7.0"
12+
"php": "^7.2",
13+
"symfony/translation": " ^3.4 || ^4.3 || ^5.0"
1314
},
1415
"require-dev": {
15-
"symfony/phpunit-bridge": "^3.4 || ^4.0"
16+
"symfony/phpunit-bridge": "^4.3 || ^5.0",
17+
"phpunit/phpunit": "^8.4"
1618
},
1719
"autoload": {
1820
"psr-4": {
@@ -25,7 +27,7 @@
2527
}
2628
},
2729
"scripts": {
28-
"test": "vendor/bin/simple-phpunit",
29-
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
30+
"test": "vendor/bin/phpunit",
31+
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
3032
}
3133
}

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src

phpunit.xml.dist

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
12-
codecoverage="true"
1311
bootstrap="./vendor/autoload.php"
1412
>
1513

16-
<formatter type="clover" usefile="false"/>
14+
<listeners>
15+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
16+
</listeners>
17+
1718
<testsuites>
1819
<testsuite name="Tests">
1920
<directory>./tests</directory>

src/Exception/StorageException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class StorageException extends \RuntimeException implements Exception
2222
{
23-
public static function translationExists($key, $domain)
23+
public static function translationExists(string $key, string $domain): self
2424
{
2525
return new self(sprintf('You cannot create a new translation with key "%s". That key does already exist in domain "%s".', $key, $domain));
2626
}

src/Model/Message.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ final class Message implements MessageInterface
4848
*/
4949
private $meta = [];
5050

51-
/**
52-
* @param string $key
53-
* @param string $domain
54-
* @param string $locale
55-
* @param string $translation
56-
* @param array $meta
57-
*/
58-
public function __construct($key, $domain = '', $locale = '', $translation = '', array $meta = [])
51+
public function __construct(string $key, string $domain = '', string $locale = '', string $translation = '', array $meta = [])
5952
{
6053
$this->key = $key;
6154
$this->domain = $domain;
@@ -67,15 +60,15 @@ public function __construct($key, $domain = '', $locale = '', $translation = '',
6760
/**
6861
* {@inheritdoc}
6962
*/
70-
public function getDomain()
63+
public function getDomain(): string
7164
{
7265
return $this->domain;
7366
}
7467

7568
/**
7669
* {@inheritdoc}
7770
*/
78-
public function withDomain($domain)
71+
public function withDomain(string $domain): MessageInterface
7972
{
8073
$new = clone $this;
8174
$new->domain = $domain;
@@ -86,23 +79,23 @@ public function withDomain($domain)
8679
/**
8780
* {@inheritdoc}
8881
*/
89-
public function getKey()
82+
public function getKey(): string
9083
{
9184
return $this->key;
9285
}
9386

9487
/**
9588
* {@inheritdoc}
9689
*/
97-
public function getLocale()
90+
public function getLocale(): string
9891
{
9992
return $this->locale;
10093
}
10194

10295
/**
10396
* {@inheritdoc}
10497
*/
105-
public function withLocale($locale)
98+
public function withLocale(string $locale): MessageInterface
10699
{
107100
$new = clone $this;
108101
$new->locale = $locale;
@@ -113,15 +106,15 @@ public function withLocale($locale)
113106
/**
114107
* {@inheritdoc}
115108
*/
116-
public function getTranslation()
109+
public function getTranslation(): string
117110
{
118111
return $this->translation;
119112
}
120113

121114
/**
122115
* {@inheritdoc}
123116
*/
124-
public function withTranslation($translation)
117+
public function withTranslation(string $translation): MessageInterface
125118
{
126119
$new = clone $this;
127120
$new->translation = $translation;
@@ -132,15 +125,15 @@ public function withTranslation($translation)
132125
/**
133126
* {@inheritdoc}
134127
*/
135-
public function getAllMeta()
128+
public function getAllMeta(): array
136129
{
137130
return $this->meta;
138131
}
139132

140133
/**
141134
* {@inheritdoc}
142135
*/
143-
public function withMeta(array $meta)
136+
public function withMeta(array $meta): MessageInterface
144137
{
145138
$new = clone $this;
146139
$new->meta = $meta;
@@ -151,7 +144,7 @@ public function withMeta(array $meta)
151144
/**
152145
* {@inheritdoc}
153146
*/
154-
public function withAddedMeta($key, $value)
147+
public function withAddedMeta(string $key, $value): MessageInterface
155148
{
156149
$new = clone $this;
157150
$new->meta[$key] = $value;
@@ -162,9 +155,9 @@ public function withAddedMeta($key, $value)
162155
/**
163156
* {@inheritdoc}
164157
*/
165-
public function getMeta($key, $default = null)
158+
public function getMeta(string $key, $default = null)
166159
{
167-
if (array_key_exists($key, $this->meta)) {
160+
if (\array_key_exists($key, $this->meta)) {
168161
return $this->meta[$key];
169162
}
170163

0 commit comments

Comments
 (0)