diff --git a/composer.json b/composer.json index 09dca6d..7b2ebde 100644 --- a/composer.json +++ b/composer.json @@ -22,18 +22,18 @@ }, "require-dev": { "edgedesign/phpqa": "^v1.25", - "phpunit/phpunit": "^8.0", "friendsofphp/php-cs-fixer": "^3.0", - "vimeo/psalm": "^4.3", "php-parallel-lint/php-parallel-lint": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12" + "phpstan/phpstan": "^1.2", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^8.0", + "vimeo/psalm": "^4.3" }, "minimum-stability": "stable", "scripts": { "cs-fix": "@php ./vendor/bin/php-cs-fixer fix", "phpqa": "@php ./vendor/bin/phpqa --report --tools phpcs:0,phpmetrics,phploc,pdepend,security-checker:0,parallel-lint:0 --ignoredDirs vendor,tests", - "phpstan": "@php ./vendor/bin/phpstan analyse src --level 5 -c extension.neon", + "phpstan": "@php ./vendor/bin/phpstan analyse src --level 6 -c extension.neon", "psalm": "@php ./vendor/bin/psalm --threads=8 --diff", "test": "@php ./vendor/bin/phpunit" }, diff --git a/extension.neon b/extension.neon index 94700c5..3ff206e 100644 --- a/extension.neon +++ b/extension.neon @@ -4,3 +4,4 @@ includes: parameters: treatPhpDocTypesAsCertain: false + checkMissingIterableValueType: false diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index d8fc781..f14acda 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -34,11 +34,7 @@ final public function __construct($data) $this->htmlUrl = $data['html_url'] ?? ''; $this->id = $data['id'] ?? ''; - if (is_array($data['user'])) { - $user = $data['user']; - } else { - $user = []; - } + $user = is_array($data['user']) ? $data['user'] : []; $this->user = User::createFromData($user); $this->position = isset($data['position']) ? $data['position'] : ''; diff --git a/src/Entity/CommitUser.php b/src/Entity/CommitUser.php index e283681..6bb2f34 100644 --- a/src/Entity/CommitUser.php +++ b/src/Entity/CommitUser.php @@ -4,7 +4,10 @@ class CommitUser { - private $date; + /** + * @var \DateTime|\DateTimeImmutable + */ + private \DateTimeInterface $date; private $name; private $email; diff --git a/src/Entity/Deployment.php b/src/Entity/Deployment.php index decadf5..f202b94 100644 --- a/src/Entity/Deployment.php +++ b/src/Entity/Deployment.php @@ -13,10 +13,7 @@ class Deployment private $environment; private $description; - /** - * @var User - */ - private $creator; + private \LoveOSS\Github\Entity\User $creator; private $createdAt; private $updatedAt; private $statusesUrl; diff --git a/src/Entity/Integration.php b/src/Entity/Integration.php index e48f988..c9cbf41 100644 --- a/src/Entity/Integration.php +++ b/src/Entity/Integration.php @@ -9,10 +9,7 @@ class Integration */ private $installationId; - /** - * @var User - */ - private $account; + private ?\LoveOSS\Github\Entity\User $account = null; /** * @var string diff --git a/src/Entity/Issue.php b/src/Entity/Issue.php index fdde2d6..b118512 100644 --- a/src/Entity/Issue.php +++ b/src/Entity/Issue.php @@ -13,19 +13,13 @@ class Issue private $number; private $title; - /** - * @var User - */ - private $user; - private $labels; + private \LoveOSS\Github\Entity\User $user; + private array $labels; private $state; private $isLocked; - /** - * @var User|null - */ - private $assignee; - private $milestone; + private ?\LoveOSS\Github\Entity\User $assignee = null; + private ?bool $milestone = null; private $commentsCount; private $createdAt; private $updatedAt; diff --git a/src/Entity/PullRequest.php b/src/Entity/PullRequest.php index a302dfa..2e20607 100644 --- a/src/Entity/PullRequest.php +++ b/src/Entity/PullRequest.php @@ -67,7 +67,7 @@ final public function __construct($data) $this->htmlUrl = $data['html_url']; $diffUrl = isset($data['diff_url']) ? $data['diff_url'] : null; $diffUrlFromPR = isset($data['pull_request']['diff_url']) ? $data['pull_request']['diff_url'] : null; - $this->diffUrl = !is_null($diffUrl) ? $diffUrl : $diffUrlFromPR; + $this->diffUrl = is_null($diffUrl) ? $diffUrlFromPR : $diffUrl; $this->issueUrl = isset($data['issue_url']) ? $data['issue_url'] : null; $this->number = $data['number']; $this->state = $data['state']; diff --git a/src/Entity/Release.php b/src/Entity/Release.php index 0fa60cb..348be88 100644 --- a/src/Entity/Release.php +++ b/src/Entity/Release.php @@ -13,7 +13,7 @@ class Release private $targetCommitish; private $name; private $isDraft; - private $author; + private \LoveOSS\Github\Entity\User $author; private $isPreRelease; private $createdAt; private $publishedAt; @@ -21,8 +21,8 @@ class Release private $tarballUrl; private $zipballUrl; private $body; - private $repository; - private $sender; + private \LoveOSS\Github\Entity\Repository $repository; + private \LoveOSS\Github\Entity\User $sender; public static function createFromData(array $data, Repository $repository, User $sender) { diff --git a/src/Entity/Repository.php b/src/Entity/Repository.php index 43668a1..fc9a993 100644 --- a/src/Entity/Repository.php +++ b/src/Entity/Repository.php @@ -8,10 +8,7 @@ class Repository private $name; private $fullName; - /** - * @var User - */ - private $owner; + private \LoveOSS\Github\Entity\User $owner; private $isPrivate; private $htmlUrl; private $description; @@ -73,7 +70,7 @@ class Repository private $openIssues; private $watchers; private $defaultBranch; - private $isPublic; + private ?bool $isPublic = null; public static function createFromData(array $data) { diff --git a/src/EventType/AbstractEventType.php b/src/EventType/AbstractEventType.php index cca5a61..c28ad5e 100644 --- a/src/EventType/AbstractEventType.php +++ b/src/EventType/AbstractEventType.php @@ -28,7 +28,7 @@ public static function name(): string public static function isValid(array $data): bool { foreach (static::fields() as $field) { - if ((isset($data[$field]) || array_key_exists($field, $data)) === false) { + if (!isset($data[$field]) && !array_key_exists($field, $data)) { return false; } } diff --git a/src/EventType/DeploymentStatusEvent.php b/src/EventType/DeploymentStatusEvent.php index be2b4e8..db03ce8 100644 --- a/src/EventType/DeploymentStatusEvent.php +++ b/src/EventType/DeploymentStatusEvent.php @@ -12,10 +12,7 @@ class DeploymentStatusEvent extends RepositoryAwareEventType */ public $deployment; - /** - * @var User - */ - public $sender; + public ?\LoveOSS\Github\Entity\User $sender = null; public static function name(): string { diff --git a/src/EventType/ForkEvent.php b/src/EventType/ForkEvent.php index 23dbda9..1884737 100644 --- a/src/EventType/ForkEvent.php +++ b/src/EventType/ForkEvent.php @@ -17,10 +17,7 @@ class ForkEvent extends RepositoryAwareEventType */ public $owner; - /** - * @var User - */ - public $forker; + public ?\LoveOSS\Github\Entity\User $forker = null; public static function name(): string { diff --git a/src/EventType/PullRequestReviewCommentEvent.php b/src/EventType/PullRequestReviewCommentEvent.php index 1fa486d..4c0ae12 100644 --- a/src/EventType/PullRequestReviewCommentEvent.php +++ b/src/EventType/PullRequestReviewCommentEvent.php @@ -33,13 +33,7 @@ public static function fields(): array public static function isValid($data): bool { - if (parent::isValid($data)) { - if ($data['action'] === 'created') { - return true; - } - } - - return false; + return parent::isValid($data) && $data['action'] === 'created'; } public function createFromData($data): self diff --git a/src/EventType/PushEvent.php b/src/EventType/PushEvent.php index 9bb2281..1c76b5f 100644 --- a/src/EventType/PushEvent.php +++ b/src/EventType/PushEvent.php @@ -26,7 +26,7 @@ public static function fields(): array return ['ref', 'head', 'before', 'commits']; } - public function createFromData($data): self + public function createFromData(array $data): self { parent::createFromData($data); diff --git a/src/EventType/ReleaseEvent.php b/src/EventType/ReleaseEvent.php index a338285..ce672bc 100644 --- a/src/EventType/ReleaseEvent.php +++ b/src/EventType/ReleaseEvent.php @@ -7,11 +7,11 @@ class ReleaseEvent extends RepositoryAwareEventType implements ActionableEventInterface { - public $action; + public string $action; public Release $release; - public function getAction() + public function getAction(): string { return $this->action; } @@ -26,7 +26,7 @@ public static function fields(): array return ['action', 'release', 'sender', 'repository']; } - public function createFromData($data): self + public function createFromData(array $data): self { parent::createFromData($data); diff --git a/src/EventType/RepositoryAwareEventType.php b/src/EventType/RepositoryAwareEventType.php index 7e1a522..6744f85 100644 --- a/src/EventType/RepositoryAwareEventType.php +++ b/src/EventType/RepositoryAwareEventType.php @@ -14,7 +14,7 @@ public function getRepository(): Repository return $this->repository; } - public function createFromData($data): self + public function createFromData(array $data): self { parent::createFromData($data); diff --git a/src/EventType/StatusEvent.php b/src/EventType/StatusEvent.php index 8fc2ae5..c34ae97 100644 --- a/src/EventType/StatusEvent.php +++ b/src/EventType/StatusEvent.php @@ -6,7 +6,7 @@ class StatusEvent extends RepositoryAwareEventType { - public $branches; + public array $branches; public User $committer; public string $description; @@ -24,7 +24,7 @@ public static function fields(): array return ['sha', 'state', 'description', 'target_url', 'branches']; } - public function createFromData($data): self + public function createFromData(array $data): self { parent::createFromData($data); diff --git a/src/EventType/WatchEvent.php b/src/EventType/WatchEvent.php index 1aa92bb..a7ab8b9 100644 --- a/src/EventType/WatchEvent.php +++ b/src/EventType/WatchEvent.php @@ -6,11 +6,11 @@ class WatchEvent extends RepositoryAwareEventType implements ActionableEventInterface { - public $action; + public string $action; public User $user; - public function getAction() + public function getAction(): string { return $this->action; } @@ -25,16 +25,12 @@ public static function fields(): array return ['action']; } - public static function isValid($data): bool + public static function isValid(array $data): bool { - if (array_key_exists('action', $data) && $data['action'] === 'started') { - return true; - } - - return false; + return array_key_exists('action', $data) && $data['action'] === 'started'; } - public function createFromData($data): self + public function createFromData(array $data): self { parent::createFromData($data); diff --git a/src/Exception/RepositoryNotFoundException.php b/src/Exception/RepositoryNotFoundException.php index 17a0ed4..a38daaf 100644 --- a/src/Exception/RepositoryNotFoundException.php +++ b/src/Exception/RepositoryNotFoundException.php @@ -6,7 +6,7 @@ class RepositoryNotFoundException extends Exception { - public function __construct($errorMessage) + public function __construct(string $errorMessage) { $exceptionMessage = sprintf("A repository can't be extracted from data: %s", $errorMessage); diff --git a/src/Parser/WebhookResolver.php b/src/Parser/WebhookResolver.php index b21f914..bfda41b 100644 --- a/src/Parser/WebhookResolver.php +++ b/src/Parser/WebhookResolver.php @@ -2,11 +2,12 @@ namespace LoveOSS\Github\Parser; +use LoveOSS\Github\EventType\GithubEventInterface; use LoveOSS\Github\Exception\EventNotFoundException; class WebhookResolver { - public function resolve(array $data) + public function resolve(array $data): GithubEventInterface { foreach ($this->eventsType() as $eventType) { if ($eventType['class']::isValid($data)) { @@ -17,7 +18,7 @@ public function resolve(array $data) throw new EventNotFoundException(); } - public function eventsType() + public function eventsType(): array { $classes = [ 'LoveOSS\Github\EventType\IssuesEvent', @@ -45,7 +46,7 @@ public function eventsType() } usort($eventTypes, function ($a, $b) { - if ($a['priority'] == $b['priority']) { + if ($a['priority'] === $b['priority']) { return 0; }