Skip to content

Commit

Permalink
Enhancement: Add rector/rector (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored Aug 29, 2024
1 parent 92e1e50 commit c48ccd5
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 17 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ jobs:
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
tools: "composer:v2"

-
Expand All @@ -162,3 +163,36 @@ jobs:
-
name: "Run a static code analysis with phpstan/phpstan and default configuration"
run: "vendor/bin/phpstan analyse --configuration=phpstan-default.neon.dist --no-progress"

refactoring:
name: "Refactoring"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "8.3"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

-
name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
tools: "composer:v2"

-
name: "Install dependencies with composer"
uses: "ramsey/[email protected]"
with:
composer-options: "--no-scripts"

-
name: "Run rector/rector"
run: "vendor/bin/rector process --config rector.php"
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
$config->getFinder()
->append([
__DIR__.'/.php-cs-fixer.dist.php',
__DIR__.'/rector.php',
])
->in('examples')
->in('src')
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Check coding standards with [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-C
make cs
```

also fix common issues with [Rector](https://github.com/rector/rector)

```
make refactoring
```

#### Code Documentation

Document your code with [phpDocumentor](https://github.com/phpDocumentor/phpDocumentor) version 3.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ tests: check-symfony vendor
.PHONY: vendor
vendor: composer.json composer.lock ## Installs composer dependencies
symfony composer install

.PHONY: refactoring
refactoring: check-symfony vendor ## Refactor the code using rector/rector
symfony php vendor/bin/rector process --config rector.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"ergebnis/php-cs-fixer-config": "^6.34",
"friendsofphp/php-cs-fixer": "^3.61",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "*"
"phpunit/phpunit": "*",
"rector/rector": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 14 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/examples',
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhp74Sets()
->withTypeCoverageLevel(0);
4 changes: 2 additions & 2 deletions src/Api/Licensing/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getOs(): ?string

public function setOs(?string $os): void
{
if (!\in_array($os, $this->getAvailableOsTypes(), true)) {
if (!\in_array($os, static::getAvailableOsTypes(), true)) {
throw new InvalidArgumentException(sprintf('OS type "%s" is not available.', $os));
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public function canBeAssigned(): bool
*/
public static function getAvailableOsTypes(): array
{
$oClass = new \ReflectionClass(__CLASS__);
$oClass = new \ReflectionClass(self::class);

return $oClass->getConstants();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Message/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct(string $filename, string $mimeType)
*/
public static function getSupportedAttachmentTypes(): array
{
$oClass = new \ReflectionClass(__CLASS__);
$oClass = new \ReflectionClass(self::class);

return $oClass->getConstants();
}
Expand All @@ -118,7 +118,7 @@ public function getMimeType(): string

public function setMimeType(string $mimeType): void
{
if (!\in_array($mimeType, $this->getSupportedAttachmentTypes(), true)) {
if (!\in_array($mimeType, static::getSupportedAttachmentTypes(), true)) {
throw new InvalidArgumentException(sprintf('Attachment type "%s" is not supported.', $mimeType));
}

Expand All @@ -132,7 +132,7 @@ public function getFilename(): string

public function setFilename(string $filename): void
{
if (!\in_array(pathinfo($filename, \PATHINFO_EXTENSION), $this->getSupportedAttachmentExtensions(), true)) {
if (!\in_array(pathinfo($filename, \PATHINFO_EXTENSION), static::getSupportedAttachmentExtensions(), true)) {
throw new InvalidArgumentException(sprintf('Attachment extension "%s" is not supported.', pathinfo($filename, \PATHINFO_EXTENSION)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Message
/**
* Your message's title, otherwise your app's name is used.
*/
private ?string $title;
private ?string $title = null;

/**
* A supplementary URL to show with your message.
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Message/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ class Priority
* Specifies how often (in seconds) the Pushover servers will send the same notification to the user.
* Used only and required with Emergency Priority.
*/
private ?int $retry;
private ?int $retry = null;

/**
* Specifies how many seconds your notification will continue to be retried for (every "retry" seconds).
* Used only and required with Emergency Priority.
*/
private ?int $expire;
private ?int $expire = null;

/**
* (Optional) may be supplied with a publicly-accessible URL that our servers will send a request to when the user has acknowledged your notification.
* Used only but not required with Emergency Priority.
*/
private ?string $callback;
private ?string $callback = null;

public function __construct(int $priority = self::NORMAL, ?int $retry = null, ?int $expire = null)
{
Expand All @@ -125,7 +125,7 @@ public function __construct(int $priority = self::NORMAL, ?int $retry = null, ?i
*/
public static function getAvailablePriorities(): array
{
$oClass = new \ReflectionClass(__CLASS__);
$oClass = new \ReflectionClass(self::class);

return $oClass->getConstants();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Message/Sound.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function __construct(string $sound)
*/
public static function getAvailableSounds(): array
{
$oClass = new \ReflectionClass(__CLASS__);
$oClass = new \ReflectionClass(self::class);

return $oClass->getConstants();
}
Expand All @@ -166,7 +166,7 @@ public function getSound(): string

public function setSound(string $sound): void
{
if (!\in_array($sound, $this->getAvailableSounds(), true)) {
if (!\in_array($sound, static::getAvailableSounds(), true)) {
throw new InvalidArgumentException(sprintf('Sound "%s" is not available.', $sound));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/GroupsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function buildCurlPostFields(?Recipient $recipient = null): array
*/
private function isActionValid(string $action): bool
{
$oClass = new \ReflectionClass(__CLASS__);
$oClass = new \ReflectionClass(self::class);

if (\in_array($action, $oClass->getConstants(), true)) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/Client/Response/ReceiptResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReceiptResponse extends Response
/**
* Timestamp of when the user acknowledged, or null.
*/
private ?\DateTime $acknowledgedAt;
private ?\DateTime $acknowledgedAt = null;

/**
* User that first acknowledged the notification.
Expand All @@ -44,7 +44,7 @@ class ReceiptResponse extends Response
/**
* Timestamp of when the notification was last retried, or null.
*/
private ?\DateTime $lastDeliveredAt;
private ?\DateTime $lastDeliveredAt = null;

/**
* True or False whether the expiration date has passed.
Expand All @@ -64,7 +64,7 @@ class ReceiptResponse extends Response
/**
* Timestamp of when our server called back, or null.
*/
private ?\DateTime $calledBackAt;
private ?\DateTime $calledBackAt = null;

public function __construct(string $curlResponse)
{
Expand Down

0 comments on commit c48ccd5

Please sign in to comment.