Skip to content

Commit

Permalink
Add rector (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
xepozz and vjik committed Nov 3, 2023
1 parent 61c5515 commit 3630f72
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 29 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rector.yml
@@ -0,0 +1,23 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.2']
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -32,6 +32,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^3.8|^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.18.6",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
47 changes: 29 additions & 18 deletions phpunit.xml.dist
@@ -1,20 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Yii Security tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<phpunit
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
failOnRisky="true"
failOnWarning="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true"
>
<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Yii Security tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
29 changes: 29 additions & 0 deletions rector.php
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
JsonThrowOnErrorRector::class,
]);
};
6 changes: 0 additions & 6 deletions src/Crypt.php
Expand Up @@ -65,8 +65,6 @@ public function __construct(string $cipher = 'AES-128-CBC')
* @psalm-mutation-free
*
* @param string $algorithm Hash algorithm for key derivation. Recommend sha256, sha384 or sha512.
*
* @return self
*/
public function withKdfAlgorithm(string $algorithm): self
{
Expand All @@ -79,8 +77,6 @@ public function withKdfAlgorithm(string $algorithm): self
* @psalm-mutation-free
*
* @param string $info HKDF info value for derivation of message authentication key.
*
* @return self
*/
public function withAuthorizationKeyInfo(string $info): self
{
Expand All @@ -94,8 +90,6 @@ public function withAuthorizationKeyInfo(string $info): self
*
* @param int $iterations Derivation iterations count.
* Set as high as possible to hinder dictionary password attacks.
*
* @return self
*/
public function withDerivationIterations(int $iterations): self
{
Expand Down
2 changes: 1 addition & 1 deletion tests/MockHelper.php
Expand Up @@ -45,7 +45,7 @@ class MockHelper
* @var bool|null value to be returned by mocked extension_loaded() function.
* null means normal extension_loaded() behavior.
*/
public static ?bool $mock_extension_loaded;
public static ?bool $mock_extension_loaded = null;
/**
* @var false|string|null value to be returned by mocked openssl_encrypt() function.
* null means normal openssl_encrypt() behavior.
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase.php
Expand Up @@ -11,7 +11,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
*
* @param $object
* @param $method
* @param array $args
* @param bool $revoke whether to make method inaccessible after execution
*
* @throws \ReflectionException
Expand Down Expand Up @@ -59,7 +58,6 @@ protected function setInaccessibleProperty($object, $propertyName, $value, bool
* Gets an inaccessible object property.
*
* @param $object
* @param string $propertyName
* @param bool $revoke whether to make property inaccessible after getting
*
* @throws \ReflectionException
Expand Down
2 changes: 0 additions & 2 deletions tests/TokenMaskTest.php
Expand Up @@ -12,8 +12,6 @@ final class TokenMaskTest extends TestCase
/**
* @dataProvider maskProvider
*
* @param mixed $unmaskedToken
*
* @throws \Exception
*/
public function testMaskingAndUnmasking($unmaskedToken): void
Expand Down

0 comments on commit 3630f72

Please sign in to comment.