Skip to content

Commit

Permalink
Merge pull request #18 from acodispo/php-8
Browse files Browse the repository at this point in the history
Require PHP >= 8.0
  • Loading branch information
AnthonyPorthouse authored Feb 14, 2022
2 parents f0c0af2 + 357a6a5 commit 1059d47
Show file tree
Hide file tree
Showing 37 changed files with 129 additions and 86 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ jobs:
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
extensions: json
tools: composer

- name: Install Dependencies
run: composer install

- name: PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --diff-format=udiff --dry-run --using-cache=false --verbose
run: ./vendor/bin/php-cs-fixer fix --diff --dry-run --using-cache=no --verbose

unit-tests:
name: Unit Tests
Expand All @@ -81,22 +81,22 @@ jobs:

strategy:
matrix:
php-version: ['7.1', '7.2', '7.3', '7.4']
php-version: ['8.0', '8.1']
dependencies: ['lowest', 'highest']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json
tools: composer

- name: Cache Dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
4 changes: 2 additions & 2 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'@PSR12' => true,
])
->setFinder($finder);
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
}
},
"require": {
"php": "^7.1.3",
"php": "^7.1.3 || ^8.0.0",
"ext-json": "*",
"symfony/console": "^4.0|^5.0"
"symfony/console": "^4.0|^5.0|^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.9",
"phpunit/phpunit": "^7.5",
"friendsofphp/php-cs-fixer": "^3",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^8 || ^9",
"roave/security-advisories": "dev-master"
}
}
31 changes: 11 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
>
<testsuites>
<testsuite name="DiceBag Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist
processUncoveredFilesFromWhitelist="true"
>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" colors="true" verbose="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="DiceBag Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 5 additions & 1 deletion src/Console/Commands/RollCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ protected function configure(): void
}

/** {@inheritdoc} */
protected function execute(InputInterface $input, OutputInterface $output) : int
protected function execute(InputInterface $input, OutputInterface $output): int
{
$diceString = $input->getArgument('dice') ?? '';
if (is_array($diceString)) {
$diceString = implode(' ', $diceString);
}

if (!is_string($diceString)) {
throw new \InvalidArgumentException('Dice argument must be a string, or array of strings.');
}

$diceBag = DiceBag::factory($diceString);

$output->writeln($diceBag->__toString());
Expand Down
12 changes: 6 additions & 6 deletions src/Dice/AbstractDice.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ public function __construct(RandomizationEngine $randomization)
}

/** {@inheritdoc} */
public function min() : int
public function min(): int
{
return $this->min;
}

/** {@inheritdoc} */
public function max() : int
public function max(): int
{
return $this->max;
}

/** {@inheritdoc} */
public function value() : int
public function value(): int
{
return $this->value;
}

/** {@inheritdoc} */
public static function isValid(string $diceString) : bool
public static function isValid(string $diceString): bool
{
return (bool)preg_match(static::FORMAT, $diceString);
}

/**
* @return array<int>
*/
public function jsonSerialize() : array
public function jsonSerialize(): array
{
return [
'min' => $this->min(),
Expand All @@ -73,7 +73,7 @@ public function jsonSerialize() : array
*
* @return string
*/
public function __toString() : string
public function __toString(): string
{
return '[' . $this->value() . ']';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dice/Dice.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(RandomizationEngine $randomization, int $size)
/**
* {@inheritdoc}
*/
public static function make(RandomizationEngine $randomization, string $diceString) : array
public static function make(RandomizationEngine $randomization, string $diceString): array
{
preg_match(static::FORMAT, $diceString, $tokens);

Expand Down
2 changes: 1 addition & 1 deletion src/Dice/DiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(RandomizationEngine $randomizationEngine)
*
* @return DiceInterface[]
*/
public function makeDice(string $diceString) : array
public function makeDice(string $diceString): array
{
foreach (self::DICE_TYPES as $type) {
/** @var DiceInterface $type */
Expand Down
12 changes: 6 additions & 6 deletions src/Dice/DiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

use DiceBag\Randomization\RandomizationEngine;

interface DiceInterface
interface DiceInterface extends \Stringable
{
/**
* Returns the minimum value for the Dice
*
* @return int
*/
public function min() : int;
public function min(): int;

/**
* Returns the maximum value for the Dice
*
* @return int
*/
public function max() : int;
public function max(): int;

/**
* Returns the rolled value of the Dice
*
* @return int
*/
public function value() : int;
public function value(): int;

/**
* Checks is the dice string is a valid format for this dice
Expand All @@ -36,7 +36,7 @@ public function value() : int;
*
* @return bool
*/
public static function isValid(string $diceString) : bool;
public static function isValid(string $diceString): bool;

/**
* Makes a dice of this type with the given dice string
Expand All @@ -46,5 +46,5 @@ public static function isValid(string $diceString) : bool;
*
* @return DiceInterface[]
*/
public static function make(RandomizationEngine $randomization, string $diceString) : array;
public static function make(RandomizationEngine $randomization, string $diceString): array;
}
2 changes: 1 addition & 1 deletion src/Dice/FudgeDice.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(RandomizationEngine $randomization)
}

/** {@inheritdoc} */
public static function make(RandomizationEngine $randomization, string $diceString) : array
public static function make(RandomizationEngine $randomization, string $diceString): array
{
preg_match(static::FORMAT, $diceString, $tokens);

Expand Down
4 changes: 2 additions & 2 deletions src/Dice/Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function __construct(RandomizationEngine $randomization, string $modifier
}

/** {@inheritdoc} */
public static function make(RandomizationEngine $randomization, string $diceString) : array
public static function make(RandomizationEngine $randomization, string $diceString): array
{
preg_match(static::FORMAT, $diceString, $tokens);

return [new static($randomization, $tokens['value'])];
}

/** {@inheritdoc} */
public function __toString() : string
public function __toString(): string
{
return (string)$this->value();
}
Expand Down
10 changes: 5 additions & 5 deletions src/DiceBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $diceStrings, RandomizationEngine $randomizati
*
* @return DiceBag
*/
public static function factory(string $diceString, RandomizationEngine $randomizationEngine = null) : DiceBag
public static function factory(string $diceString, RandomizationEngine $randomizationEngine = null): DiceBag
{
$randomizationEngine = $randomizationEngine ?? new RandomInt();

Expand All @@ -56,7 +56,7 @@ public static function factory(string $diceString, RandomizationEngine $randomiz
*
* @return DicePool[]
*/
public function getDicePools() : array
public function getDicePools(): array
{
return $this->dicePools;
}
Expand All @@ -66,7 +66,7 @@ public function getDicePools() : array
*
* @return int
*/
public function getTotal() : int
public function getTotal(): int
{
return array_reduce($this->dicePools, function (int $prev, DicePool $pool) {
return $prev + $pool->getTotal();
Expand All @@ -76,7 +76,7 @@ public function getTotal() : int
/**
* @return mixed[]
*/
public function jsonSerialize() : array
public function jsonSerialize(): array
{
return [
'pools' => $this->getDicePools(),
Expand All @@ -89,7 +89,7 @@ public function jsonSerialize() : array
*
* @return string
*/
public function __toString() : string
public function __toString(): string
{
return implode(' + ', $this->dicePools) . ' = ' . $this->getTotal();
}
Expand Down
Loading

0 comments on commit 1059d47

Please # to comment.