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

Upgrade for PHP 7.2 #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
vendor
composer.lock
phpunit.xml
.phpcs-cache
.phpunit.result.cache
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,8 +1,7 @@
language: php
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
before_script:
- composer self-update
- composer install --prefer-source
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -15,7 +15,7 @@
}
},
"require": {
"php": "^7.0",
"php": "^7.2",
"ext-bcmath": "*",
"ext-intl": "*",
"egulias/email-validator": "^2.1",
Expand All @@ -26,14 +26,14 @@
},
"require-dev": {
"doctrine/orm": "2.5.x-dev as 2.5.6",
"myonlinestore/coding-standard": "^1.0",
"phpunit/phpunit": "6.4.*"
"myonlinestore/coding-standard": "^1.1.0",
"phpunit/phpunit": "^8.3.1"
},
"config": {
"vendor-dir": "vendor",
"sort-packages": true,
"platform": {
"php": "7.0.8"
"php": "7.2.19"
}
}
}
11 changes: 8 additions & 3 deletions phpcs.xml.dist
Expand Up @@ -2,10 +2,15 @@
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<file>./</file>

<arg value="sp"/>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg value="sp"/>

<file>src</file>
<file>tests</file>

<rule ref="vendor/myonlinestore/coding-standard/MyOnlineStore/ruleset.xml"/>
</ruleset>
12 changes: 4 additions & 8 deletions phpunit.xml.dist
@@ -1,19 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
>
<testsuites>
<testsuite name="Value Type Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
Expand Down
5 changes: 1 addition & 4 deletions src/Assertion/ArrayContainsClassAssertionTrait.php
Expand Up @@ -9,10 +9,7 @@
trait ArrayContainsClassAssertionTrait
{
/**
* @param array $entries
* @param string $className
*
* @return bool
* @param mixed[] $entries
*/
public function assertArrayContainsOnlyClass(array $entries, string $className): bool
{
Expand Down
16 changes: 8 additions & 8 deletions src/Assertion/EnumValueGuardTrait.php
Expand Up @@ -16,19 +16,19 @@ public function guardIsValidValue($value)
{
$validValues = $this->getValidValues();

if (!is_scalar($value)) {
if (!\is_scalar($value)) {
throw new \InvalidArgumentException(
sprintf('given value is not a scalar value but of type %s', gettype($value))
\sprintf('given value is not a scalar value but of type %s', \gettype($value))
);
}

if (!in_array($value, $validValues, true)) {
if (!\in_array($value, $validValues, true)) {
throw new \InvalidArgumentException(
sprintf(
\sprintf(
'Invalid %s value given: "%s" (valid values: %s)',
__CLASS__,
self::class,
$value,
implode(', ', $validValues)
\implode(', ', $validValues)
)
);
}
Expand All @@ -37,7 +37,7 @@ public function guardIsValidValue($value)
}

/**
* @return array
* @return mixed[]
*/
abstract protected function getValidValues();
abstract protected function getValidValues(): array;
}
7 changes: 3 additions & 4 deletions src/Assertion/NumericAssertionTrait.php
@@ -1,16 +1,15 @@
<?php
declare(strict_types=1);

namespace MyOnlineStore\Common\Domain\Assertion;

trait NumericAssertionTrait
{
/**
* @param mixed $value
*
* @return bool
*/
protected function assertIsNumeric($value)
protected function assertIsNumeric($value): bool
{
return is_numeric($value);
return \is_numeric($value);
}
}
12 changes: 8 additions & 4 deletions src/Collection/ImmutableCollection.php
Expand Up @@ -7,17 +7,21 @@ class ImmutableCollection extends MutableCollection
{
/**
* @inheritDoc
*
* @throws \LogicException
*/
public function add($element)
public function add($element): void
{
throw new \LogicException(sprintf('Method %s is not available on immutable collections', __FUNCTION__));
throw new \LogicException(\sprintf('Method %s is not available on immutable collections', __FUNCTION__));
}

/**
* @inheritDoc
*
* @throws \LogicException
*/
public function offsetSet($index, $newval)
public function offsetSet($index, $newval): void
{
throw new \LogicException(sprintf('Method %s is not available on immutable collections', __FUNCTION__));
throw new \LogicException(\sprintf('Method %s is not available on immutable collections', __FUNCTION__));
}
}
22 changes: 5 additions & 17 deletions src/Collection/ImmutableCollectionInterface.php
Expand Up @@ -7,22 +7,13 @@ interface ImmutableCollectionInterface extends \Countable, \IteratorAggregate, \
{
/**
* @param mixed $element
*
* @return bool
*/
public function contains($element);
public function contains($element): bool;

/**
* @param callable $callback
*/
public function each(callable $callback);
public function each(callable $callback): void;

/**
* Returns if given collection is of the same type and has the same elements
*
* @param ImmutableCollectionInterface $otherCollection
*
* @return bool
*/
public function equals(ImmutableCollectionInterface $otherCollection): bool;

Expand All @@ -38,10 +29,7 @@ public function first();
*/
public function indexOf($element);

/**
* @return bool
*/
public function isEmpty();
public function isEmpty(): bool;

/**
* Sets the internal iterator to the last element in the collection and returns this element.
Expand All @@ -56,7 +44,7 @@ public function last();
public function reindex();

/**
* @return array
* @return mixed[]
*/
public function toArray();
public function toArray(): array;
}
39 changes: 15 additions & 24 deletions src/Collection/LocaleCollection.php
Expand Up @@ -3,37 +3,35 @@

namespace MyOnlineStore\Common\Domain\Collection;

use MyOnlineStore\Common\Domain\Value\CurrencyIso;
use MyOnlineStore\Common\Domain\Value\Locale;

final class LocaleCollection extends MutableCollection implements LocaleCollectionInterface
{
use StringCollectionTrait;

/**
* @inheritdoc
* @param Locale[] $entries
*/
public function __construct(array $entries = [])
{
parent::__construct(
array_filter(
\array_filter(
$entries,
function ($entry) {
static function ($entry): bool {
return $entry instanceof Locale;
}
)
);
}

/**
* @inheritdoc
*/
public function asRegionCodes(): RegionCodeCollectionInterface
{
return new RegionCodeCollection(
array_values(
array_unique(
array_map(
function (Locale $locale) {
\array_values(
\array_unique(
\array_map(
static function (Locale $locale) {
return $locale->regionCode();
},
$this->toArray()
Expand All @@ -49,44 +47,39 @@ function (Locale $locale) {
public function contains($element): bool
{
return $this->containsWith(
function (Locale $locale) use ($element) {
static function (Locale $locale) use ($element) {
return $locale->equals($element);
}
);
}

/**
* @inheritdoc
* @return LocaleCollectionInterface[]
*/
public function groupByCurrencyFormat($currencyIso, $previewAmount): array
public function groupByCurrencyFormat(CurrencyIso $currencyIso, float $previewAmount): array
{
return $this->groupBy(
function (Locale $locale) use ($currencyIso, $previewAmount) {
static function (Locale $locale) use ($currencyIso, $previewAmount) {
$numberFormatter = new \NumberFormatter((string) $locale, \NumberFormatter::CURRENCY);

return $numberFormatter->formatCurrency($previewAmount, (string) $currencyIso);
}
);
}

/**
* @inheritdoc
*/
public function unique(): LocaleCollectionInterface
{
return new LocaleCollection(\array_unique($this->toArray()));
}

/**
* @param string[] $input
*
* @return self
*/
public static function fromStrings(array $input): self
{
return new self(
array_map(
function ($locale) {
\array_map(
static function ($locale) {
try {
return Locale::fromString($locale);
} catch (\InvalidArgumentException $exception) {
Expand All @@ -99,11 +92,9 @@ function ($locale) {
}

/**
* @param callable $callable
*
* @return LocaleCollection[]
*/
private function groupBy(callable $callable)
private function groupBy(callable $callable): array
{
$locales = [];

Expand Down
11 changes: 1 addition & 10 deletions src/Collection/LocaleCollectionInterface.php
Expand Up @@ -11,21 +11,12 @@
*/
interface LocaleCollectionInterface extends ImmutableCollectionInterface, StringCollectionInterface
{
/**
* @return RegionCodeCollectionInterface
*/
public function asRegionCodes(): RegionCodeCollectionInterface;

/**
* @param CurrencyIso $currencyIso
* @param float $previewAmount
*
* @return LocaleCollectionInterface[]
*/
public function groupByCurrencyFormat($currencyIso, $previewAmount): array;
public function groupByCurrencyFormat(CurrencyIso $currencyIso, float $previewAmount): array;

/**
* @return LocaleCollectionInterface
*/
public function unique(): LocaleCollectionInterface;
}