From 8856ebb14e022a143888e938309637309dbd278d Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Tue, 12 Sep 2023 18:51:46 +0700 Subject: [PATCH] Add rector and apply suggestions (#38) Co-authored-by: Sergei Predvoditelev --- .github/workflows/rector.yml | 21 +++++++++++++++++++++ composer.json | 1 + rector.php | 27 +++++++++++++++++++++++++++ src/Cookie.php | 22 +--------------------- src/CookieEncryptor.php | 1 - src/CookieSigner.php | 1 - 6 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/rector.yml create mode 100644 rector.php diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..411db3f --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,21 @@ +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 + with: + os: >- + ['ubuntu-latest'] + php: >- + ['7.4'] diff --git a/composer.json b/composer.json index a2ee82d..76c754e 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "httpsoft/http-message": "^1.0", "maglnet/composer-require-checker": "^3.8|^4.2", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.18.2", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.30|^5.8", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..b4b9e11 --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +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, + ]); +}; diff --git a/src/Cookie.php b/src/Cookie.php index 6015aee..fa9dc79 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -215,10 +215,6 @@ public function getValue(): string /** * Creates a cookie copy with a new time the cookie expires. * - * @param DateTimeInterface $dateTime - * - * @return static - * * @see $expires for more information. */ public function withExpires(DateTimeInterface $dateTime): self @@ -298,10 +294,6 @@ public function expireWhenBrowserIsClosed(): self /** * Creates a cookie copy with a new domain set. - * - * @param string $domain - * - * @return static */ public function withDomain(string $domain): self { @@ -325,8 +317,6 @@ public function getDomain(): ?string * * @param string $path To be set for the cookie. * - * @return static - * * @see $path for more information. */ public function withPath(string $path): self @@ -381,10 +371,6 @@ public function isSecure(): bool /** * Creates a cookie copy that would be accessible only through the HTTP protocol. - * - * @param bool $httpOnly - * - * @return static */ public function withHttpOnly(bool $httpOnly = true): self { @@ -405,10 +391,6 @@ public function isHttpOnly(): bool /** * Creates a cookie copy with SameSite attribute. - * - * @param string $sameSite - * - * @return static */ public function withSameSite(string $sameSite): self { @@ -449,8 +431,6 @@ public function getSameSite(): ?string /** * Adds the cookie to the response and returns it. * - * @param ResponseInterface $response - * * @return ResponseInterface Response with added cookie. */ public function addToResponse(ResponseInterface $response): ResponseInterface @@ -582,7 +562,7 @@ public static function fromCookieString(string $string): self private static function splitCookieAttribute(string $attribute): array { $parts = explode('=', $attribute, 2); - $parts[1] = $parts[1] ?? null; + $parts[1] ??= null; return $parts; } diff --git a/src/CookieEncryptor.php b/src/CookieEncryptor.php index 30df91f..741dac7 100644 --- a/src/CookieEncryptor.php +++ b/src/CookieEncryptor.php @@ -12,7 +12,6 @@ use function rawurldecode; use function rawurlencode; use function strlen; -use function strpos; use function substr; /** diff --git a/src/CookieSigner.php b/src/CookieSigner.php index 80c8be1..b7390b7 100644 --- a/src/CookieSigner.php +++ b/src/CookieSigner.php @@ -9,7 +9,6 @@ use Yiisoft\Security\Mac; use function md5; -use function strpos; use function strlen; use function substr;