Skip to content

Commit

Permalink
Upgrade to PHP 8 (#6)
Browse files Browse the repository at this point in the history
* PHP 8 support
* Update CS fixer
  • Loading branch information
romainnorberg authored Aug 25, 2023
1 parent 4ce1069 commit 9dfeb75
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
- name: Package
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist --diff --dry-run
args: --config=.php-cs-fixer.dist.php --diff --dry-run
10 changes: 5 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.4]
php: [8.2, 8.3]
dependency-version: [prefer-lowest, prefer-stable]
include:
- testbench: 5.*
Expand All @@ -18,16 +18,16 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json
Expand All @@ -41,7 +41,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ composer.lock
/vendor/
.php_cs.cache
.phpunit.result.cache
.phpunit.cache/*
phpunit.xml.dist.bak
coverage.xml
.coverage
53 changes: 53 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Residue package.
* (c) Romain Norberg <romainnorberg@gmail.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$fileHeaderComment = <<<COMMENT
This file is part of the Residue package.
(c) Romain Norberg <romainnorberg@gmail.com>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
COMMENT;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('config')
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
// Binary operators should be surrounded by space as configured.
'binary_operator_spaces' => [
'operators' => ['=>' => 'align_single_space_minimal'],
],
'array_syntax' => ['syntax' => 'short'],
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'php_unit_strict' => false,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'trailing_comma_in_multiline' => true,
'php_unit_method_casing' => false,
'php_unit_test_annotation' => false,
'visibility_required' => false,
])
->setFinder($finder)
->setCacheFile(__DIR__.'/.php_cs.cache')
;
43 changes: 0 additions & 43 deletions .php_cs.dist

This file was deleted.

5 changes: 0 additions & 5 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Romain Norberg
Copyright (c) 2023 Romain Norberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ array(3) {
composer test
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
},
"type": "library",
"require": {
"php": "^7.4"
"php": "^8.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.49",
"phpunit/phpunit": "^8.0",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.0",
"spatie/phpunit-watcher": "^1.22"
},
"authors": [
Expand Down
32 changes: 12 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Residue Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Residue Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/Contracts/ResidueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace Romainnorberg\Residue\Contracts;

use Generator;

interface ResidueInterface
{
public const DEFAULT_DECIMAL = 2;

public const SPLIT_MODE_ALLOCATE = 'allocate';
public const SPLIT_MODE_EQUITY = 'equity';
public const SPLIT_MODES = [
Expand Down Expand Up @@ -41,7 +41,7 @@ public function decimal(int $decimal): self;
* or
* 101/3 with step 1 will split again into [33, 33, 33]
*/
public function split(string $mode = self::SPLIT_MODE_ALLOCATE): Generator;
public function split(string $mode = self::SPLIT_MODE_ALLOCATE): \Generator;

public function toArray(string $mode = self::SPLIT_MODE_ALLOCATE): array;

Expand Down
4 changes: 1 addition & 3 deletions src/Exception/DecimalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Romainnorberg\Residue\Exception;

use InvalidArgumentException;

class DecimalException extends InvalidArgumentException
class DecimalException extends \InvalidArgumentException
{
}
4 changes: 1 addition & 3 deletions src/Exception/DivideException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Romainnorberg\Residue\Exception;

use InvalidArgumentException;

class DivideException extends InvalidArgumentException
class DivideException extends \InvalidArgumentException
{
}
4 changes: 1 addition & 3 deletions src/Exception/ResidueModeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Romainnorberg\Residue\Exception;

use InvalidArgumentException;

class ResidueModeException extends InvalidArgumentException
class ResidueModeException extends \InvalidArgumentException
{
}
4 changes: 1 addition & 3 deletions src/Exception/StepException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Romainnorberg\Residue\Exception;

use InvalidArgumentException;

class StepException extends InvalidArgumentException
class StepException extends \InvalidArgumentException
{
}
9 changes: 4 additions & 5 deletions src/Residue.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Romainnorberg\Residue;

use Generator;
use Romainnorberg\Residue\Contracts\ResidueInterface;
use Romainnorberg\Residue\Exception\CannotGetRemainderException;
use Romainnorberg\Residue\Exception\DecimalException;
Expand All @@ -24,7 +23,7 @@ final class Residue implements ResidueInterface
private float $value;
private bool $isNegative;
private int $divider = 1;
private int $decimal = 2;
private int $decimal = ResidueInterface::DEFAULT_DECIMAL;
private float $step;
private float $remainder;

Expand Down Expand Up @@ -73,7 +72,7 @@ public static function create(float $value): self
* - Defining rm according to `M`
* - Iterate [n as 1 ... Dv] : yield pⁿ
*/
public function split(string $mode = self::SPLIT_MODE_ALLOCATE): Generator
public function split(string $mode = self::SPLIT_MODE_ALLOCATE): \Generator
{
if (!\in_array($mode, self::SPLIT_MODES, true)) {
throw new ResidueModeException(sprintf('Accepted modes are : %s', implode(', ', self::SPLIT_MODES)));
Expand All @@ -92,8 +91,8 @@ public function split(string $mode = self::SPLIT_MODE_ALLOCATE): Generator

for ($i = 1; $i <= $this->divider; ++$i) {
$xn = $defaultNumberOfSteps;
if (self::SPLIT_MODE_ALLOCATE === $mode &&
($defaultNumberOfSteps * $this->divider + $i) <= $maxNumberOfSteps
if (self::SPLIT_MODE_ALLOCATE === $mode
&& ($defaultNumberOfSteps * $this->divider + $i) <= $maxNumberOfSteps
) {
++$xn;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ResidueExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function it_should_throw_cannot_get_remainder_exception(): void

/**
* @test
*
* @dataProvider provideDataForDivideException
*/
public function it_should_throw_divide_exception(int $minusThanOne): void
Expand Down Expand Up @@ -80,7 +81,7 @@ public function it_should_throw_decimal_exception(): void
->decimal(-1);
}

public function provideDataForDivideException()
static public function provideDataForDivideException()
{
return [
[0],
Expand Down
Loading

0 comments on commit 9dfeb75

Please sign in to comment.