Skip to content

Commit

Permalink
Upgrade PHP CS Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 3, 2024
1 parent 0e9cad7 commit dc95d05
Show file tree
Hide file tree
Showing 41 changed files with 396 additions and 377 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/php_cs.dist export-ignore
/.php-cs-fixer.dist.php export-ignore
6 changes: 3 additions & 3 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', 'latest']
type: ['Phpunit']
include:
- php: '8.0'
- php: 'latest'
type: 'CodingStyle'
- php: '8.3'
- php: 'latest'
type: 'StaticAnalysis'
steps:
- name: Checkout
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/.idea
/.php_cs
/.phpunit.result.cache
/vendor
/composer.lock
/phpunit.xml
/.phpunit.result.cache
78 changes: 78 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in([__DIR__])
->exclude(['vendor']);

return (new Config())
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,

// required by PSR-12
'concat_space' => [
'spacing' => 'one',
],

// disable some too strict rules
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
],
'single_line_throw' => false,
'yoda_style' => [
'equal' => false,
'identical' => false,
],
'native_constant_invocation' => true,
'native_function_invocation' => false,
'void_return' => false,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'exit'],
],
'final_internal_class' => false,
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'multiline_whitespace_before_semicolons' => false,
'no_superfluous_elseif' => false,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'return_assignment' => false,
'comment_to_phpdoc' => false,
'general_phpdoc_annotation_remove' => [
'annotations' => ['author', 'copyright', 'throws'],
],

// fn => without curly brackets is less readable,
// also prevent bounding of unwanted variables for GC
'use_arrow_functions' => false,

// TODO disable too strict rules for now - remove once the CS is updated
'declare_strict_types' => false,
'fully_qualified_strict_types' => false,
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => false,
'increment_style' => false,
'native_constant_invocation' => false,
'no_useless_else' => false,
'php_unit_data_provider_name' => false,
'php_unit_data_provider_return_type' => false,
'php_unit_data_provider_static' => false,
'php_unit_strict' => false,
'php_unit_test_case_static_method_calls' => false,
'phpdoc_to_comment' => false,
'static_lambda' => false,
'strict_comparison' => false,
])
->setFinder($finder)
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.' . md5(__DIR__) . '.cache');
60 changes: 0 additions & 60 deletions .php_cs.dist

This file was deleted.

9 changes: 2 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@
"ext-sysvsem": "*",
"eloquent/liberator": "^2.0",
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^2.16",
"johnkary/phpunit-speedtrap": "^3.0",
"friendsofphp/php-cs-fixer": "^3.0",
"mikey179/vfsstream": "^1.6.7",
"php-mock/php-mock-phpunit": "^2.1",
"phpstan/phpstan": "^0.12.58",
"phpunit/phpunit": "^9.4",
"predis/predis": "^1.1",
"spatie/async": "^1.5",
"squizlabs/php_codesniffer": "^3.3"
"spatie/async": "^1.5"
},
"suggest": {
"ext-igbinary": "To use this library with PHP Redis igbinary serializer enabled.",
Expand Down Expand Up @@ -82,8 +80,5 @@
"phpstan/extension-installer": true
},
"sort-packages": true
},
"scripts": {
"fix-cs": "vendor/bin/phpcbf --standard=PSR2 src/ tests/"
}
}
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit>
4 changes: 1 addition & 3 deletions src/exception/DeadlineException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* Deadline exception.
*/
class DeadlineException extends RuntimeException implements PhpLockException
{
}
class DeadlineException extends RuntimeException implements PhpLockException {}
9 changes: 5 additions & 4 deletions src/exception/ExecutionOutsideLockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class ExecutionOutsideLockException extends LockReleaseException
/**
* Creates a new instance of the ExecutionOutsideLockException class.
*
* @param float $elapsedTime Total elapsed time of the synchronized code
* callback execution.
* @param float $timeout The lock timeout in seconds.
* @return self Execution outside lock exception.
* @param float $elapsedTime total elapsed time of the synchronized code
* callback execution
* @param float $timeout the lock timeout in seconds
*
* @return self execution outside lock exception
*/
public static function create(float $elapsedTime, float $timeout): self
{
Expand Down
4 changes: 1 addition & 3 deletions src/exception/LockAcquireException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
* Used when the lock could not be acquired. This exception implies that the
* critical code was not executed, or at least had no side effects.
*/
class LockAcquireException extends MutexException
{
}
class LockAcquireException extends MutexException {}
16 changes: 9 additions & 7 deletions src/exception/LockReleaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LockReleaseException extends MutexException
* Gets the result that has been returned during the critical code
* execution.
*
* @return mixed The return value of the executed code block.
* @return mixed the return value of the executed code block
*/
public function getCodeResult()
{
Expand All @@ -44,8 +44,9 @@ public function getCodeResult()
* Sets the result that has been returned during the critical code
* execution.
*
* @param mixed $codeResult The return value of the executed code block.
* @return self Current lock release exception instance.
* @param mixed $codeResult the return value of the executed code block
*
* @return self current lock release exception instance
*/
public function setCodeResult($codeResult): self
{
Expand All @@ -58,8 +59,8 @@ public function setCodeResult($codeResult): self
* Gets the exception that has happened during the synchronized code
* execution.
*
* @return \Throwable|null The exception thrown by the code block or null
* when there has been no exception.
* @return \Throwable|null the exception thrown by the code block or null
* when there has been no exception
*/
public function getCodeException(): ?Throwable
{
Expand All @@ -70,8 +71,9 @@ public function getCodeException(): ?Throwable
* Sets the exception that has happened during the critical code
* execution.
*
* @param \Throwable $codeException The exception thrown by the code block.
* @return self Current lock release exception instance.
* @param \Throwable $codeException the exception thrown by the code block
*
* @return self current lock release exception instance
*/
public function setCodeException(Throwable $codeException): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/exception/MutexException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class MutexException extends RuntimeException implements PhpLockException
{
/**
* @var int Not enough redis servers.
* @var int not enough redis servers
*/
public const REDIS_NOT_ENOUGH_SERVERS = 1;
}
18 changes: 8 additions & 10 deletions src/exception/PhpLockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
/**
* Common php-lock/lock exception interface.
*
* @method string getMessage()
* @method int getCode()
* @method string getFile()
* @method int getLine()
* @method array getTrace()
* @method string getTraceAsString()
* @method string getMessage()
* @method int getCode()
* @method string getFile()
* @method int getLine()
* @method array getTrace()
* @method string getTraceAsString()
* @method \Throwable|null getPrevious()
* @method string __toString()
* @method string __toString()
*/
interface PhpLockException
{
}
interface PhpLockException {}
5 changes: 3 additions & 2 deletions src/exception/TimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class TimeoutException extends LockAcquireException
/**
* Creates a new instance of the TimeoutException class.
*
* @param float $timeout The timeout in seconds.
* @return self A timeout has been exceeded exception.
* @param float $timeout the timeout in seconds
*
* @return self a timeout has been exceeded exception
*/
public static function create(float $timeout): self
{
Expand Down
17 changes: 10 additions & 7 deletions src/mutex/CASMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class CASMutex extends Mutex
{
/**
* @var Loop The loop.
* @var Loop the loop
*/
private $loop;

Expand All @@ -27,8 +27,9 @@ class CASMutex extends Mutex
*
* The default is 3 seconds.
*
* @param float $timeout The timeout in seconds.
* @throws \LengthException The timeout must be greater than 0.
* @param float $timeout the timeout in seconds
*
* @throws \LengthException the timeout must be greater than 0
*/
public function __construct(float $timeout = 3)
{
Expand Down Expand Up @@ -69,11 +70,13 @@ public function notify(): void
* </code>
*
* @template T
* @param callable(): T $code The synchronized execution block.
* @throws \Exception The execution block threw an exception.
* @throws TimeoutException The timeout was reached.
* @return T The return value of the execution block.
*
* @param callable(): T $code the synchronized execution block
*
* @return T the return value of the execution block
*
* @throws \Exception the execution block threw an exception
* @throws TimeoutException the timeout was reached
*/
public function synchronized(callable $code)
{
Expand Down
Loading

0 comments on commit dc95d05

Please sign in to comment.