Skip to content

Commit

Permalink
PHP7.2 & strict type hinting (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Dolbeau authored and Nyholm committed Dec 6, 2019
1 parent ceac357 commit 3dc9a2b
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 139 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [push, pull_request]
name: Static analysis
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --dry-run --diff-format udiff
25 changes: 15 additions & 10 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

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

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create();
return $config;
12 changes: 0 additions & 12 deletions .styleci.yml

This file was deleted.

20 changes: 5 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,21 @@ matrix:
fast_finish: true
include:
# Test with lowest dependencies
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
- php: 5.5
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"

# Test the latest stable release
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
env: COVERAGE=true TEST_COMMAND="composer test-ci"

# Force some major versions of Symfony
- php: 7.2
env: DEPENDENCIES="dunglas/symfony-lock:^2"
- php: 7.2
- php: 7.3
env: DEPENDENCIES="dunglas/symfony-lock:^3"
- php: 7.2
- php: 7.3
env: DEPENDENCIES="dunglas/symfony-lock:^4"

# Latest commit to master
- php: 7.2
- php: 7.4snapshot
env: STABILITY="dev"

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

script:
- composer validate --strict --no-check-lock
Expand Down
9 changes: 7 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## 2.0.0

Drop support og php < 7.2
Add strict I/O type hinting

## 1.0.0

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

### Changed

- Documentation change on interface.
- Documentation change on interface.

## 0.2.1

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
}
],
"require": {
"php": "^5.4 || ^7.0"
"php": "^7.2",
"symfony/translation": " ^3.4 || ^4.3 || ^5.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.4 || ^4.0"
"symfony/phpunit-bridge": "^4.3 || ^5.0",
"phpunit/phpunit": "^8.4"
},
"autoload": {
"psr-4": {
Expand All @@ -25,7 +27,7 @@
}
},
"scripts": {
"test": "vendor/bin/simple-phpunit",
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
}
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 5
paths:
- src
7 changes: 4 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
codecoverage="true"
bootstrap="./vendor/autoload.php"
>

<formatter type="clover" usefile="false"/>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

<testsuites>
<testsuite name="Tests">
<directory>./tests</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/StorageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class StorageException extends \RuntimeException implements Exception
{
public static function translationExists($key, $domain)
public static function translationExists(string $key, string $domain): self
{
return new self(sprintf('You cannot create a new translation with key "%s". That key does already exist in domain "%s".', $key, $domain));
}
Expand Down
33 changes: 13 additions & 20 deletions src/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ final class Message implements MessageInterface
*/
private $meta = [];

/**
* @param string $key
* @param string $domain
* @param string $locale
* @param string $translation
* @param array $meta
*/
public function __construct($key, $domain = '', $locale = '', $translation = '', array $meta = [])
public function __construct(string $key, string $domain = '', string $locale = '', string $translation = '', array $meta = [])
{
$this->key = $key;
$this->domain = $domain;
Expand All @@ -67,15 +60,15 @@ public function __construct($key, $domain = '', $locale = '', $translation = '',
/**
* {@inheritdoc}
*/
public function getDomain()
public function getDomain(): string
{
return $this->domain;
}

/**
* {@inheritdoc}
*/
public function withDomain($domain)
public function withDomain(string $domain): MessageInterface
{
$new = clone $this;
$new->domain = $domain;
Expand All @@ -86,23 +79,23 @@ public function withDomain($domain)
/**
* {@inheritdoc}
*/
public function getKey()
public function getKey(): string
{
return $this->key;
}

/**
* {@inheritdoc}
*/
public function getLocale()
public function getLocale(): string
{
return $this->locale;
}

/**
* {@inheritdoc}
*/
public function withLocale($locale)
public function withLocale(string $locale): MessageInterface
{
$new = clone $this;
$new->locale = $locale;
Expand All @@ -113,15 +106,15 @@ public function withLocale($locale)
/**
* {@inheritdoc}
*/
public function getTranslation()
public function getTranslation(): string
{
return $this->translation;
}

/**
* {@inheritdoc}
*/
public function withTranslation($translation)
public function withTranslation(string $translation): MessageInterface
{
$new = clone $this;
$new->translation = $translation;
Expand All @@ -132,15 +125,15 @@ public function withTranslation($translation)
/**
* {@inheritdoc}
*/
public function getAllMeta()
public function getAllMeta(): array
{
return $this->meta;
}

/**
* {@inheritdoc}
*/
public function withMeta(array $meta)
public function withMeta(array $meta): MessageInterface
{
$new = clone $this;
$new->meta = $meta;
Expand All @@ -151,7 +144,7 @@ public function withMeta(array $meta)
/**
* {@inheritdoc}
*/
public function withAddedMeta($key, $value)
public function withAddedMeta(string $key, $value): MessageInterface
{
$new = clone $this;
$new->meta[$key] = $value;
Expand All @@ -162,9 +155,9 @@ public function withAddedMeta($key, $value)
/**
* {@inheritdoc}
*/
public function getMeta($key, $default = null)
public function getMeta(string $key, $default = null)
{
if (array_key_exists($key, $this->meta)) {
if (\array_key_exists($key, $this->meta)) {
return $this->meta[$key];
}

Expand Down
Loading

0 comments on commit 3dc9a2b

Please sign in to comment.