Skip to content

Commit

Permalink
Improve static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Sep 1, 2024
1 parent 17f3756 commit 1f6db11
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 50 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
]);

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
Expand Down
113 changes: 113 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:filterAndroidBackgroundLayout\\(\\) has parameter \\$layouts with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:filterIosAttachments\\(\\) has parameter \\$attachments with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:filterWebButtons\\(\\) has parameter \\$buttons with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:normalizeButtons\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:normalizeButtons\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:normalizeFilters\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\NotificationResolver\\:\\:normalizeFilters\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/NotificationResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\SegmentResolver\\:\\:normalizeFilters\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/SegmentResolver.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method OneSignal\\\\Resolver\\\\SegmentResolver\\:\\:normalizeFilters\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Resolver/SegmentResolver.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#1 \\$success of class OneSignal\\\\Response\\\\Segment\\\\CreateSegmentResponse constructor expects bool, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/CreateSegmentResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#2 \\$id of class OneSignal\\\\Response\\\\Segment\\\\CreateSegmentResponse constructor expects non\\-empty\\-string, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/CreateSegmentResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#1 \\$success of class OneSignal\\\\Response\\\\Segment\\\\DeleteSegmentResponse constructor expects bool, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/DeleteSegmentResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(array\\)\\: OneSignal\\\\Response\\\\Segment\\\\Segment given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#1 \\$totalCount of class OneSignal\\\\Response\\\\Segment\\\\ListSegmentsResponse constructor expects int\\<0, max\\>, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#2 \\$array of function array_map expects array, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#2 \\$offset of class OneSignal\\\\Response\\\\Segment\\\\ListSegmentsResponse constructor expects int\\<0, 2147483648\\>, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#3 \\$limit of class OneSignal\\\\Response\\\\Segment\\\\ListSegmentsResponse constructor expects int\\<0, 2147483648\\>, mixed given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];
$ignoreErrors[] = [
// identifier: argument.type
'message' => '#^Parameter \\#4 \\$segments of class OneSignal\\\\Response\\\\Segment\\\\ListSegmentsResponse constructor expects list\\<OneSignal\\\\Response\\\\Segment\\\\Segment\\>, array\\<OneSignal\\\\Response\\\\Segment\\\\Segment\\> given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Response/Segment/ListSegmentsResponse.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- phpstan-baseline.php

parameters:
bootstrapFiles:
Expand All @@ -10,7 +12,6 @@ parameters:
tmpDir: %currentWorkingDirectory%/.phpstan
level: 9
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: true
checkUninitializedProperties: true
ignoreErrors:
Expand Down
30 changes: 22 additions & 8 deletions src/Apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function __construct(OneSignal $client, ResolverFactory $resolverFactory)
* User authentication key must be set.
*
* @param string $id ID of your application
*
* @return array<mixed>
*/
public function getOne(string $id): array
{
Expand All @@ -45,6 +47,8 @@ public function getOne(string $id): array
* Get information about all your created applications.
*
* User authentication key must be set.
*
* @return array<mixed>
*/
public function getAll(): array
{
Expand All @@ -59,7 +63,9 @@ public function getAll(): array
*
* User authentication key must be set.
*
* @param array $data Application data
* @param array<mixed> $data Application data
*
* @return array<mixed>
*/
public function add(array $data): array
{
Expand All @@ -78,8 +84,10 @@ public function add(array $data): array
*
* User authentication key must be set.
*
* @param string $id ID of your application
* @param array $data New application data
* @param string $id ID of your application
* @param array<mixed> $data New application data
*
* @return array<mixed>
*/
public function update(string $id, array $data): array
{
Expand All @@ -96,10 +104,12 @@ public function update(string $id, array $data): array
/**
* Create a new segment for application with provided data.
*
* @param string $appId ID of your application
* @param array $data Segment Data
* @param string $appId ID of your application
* @param array<mixed> $data Segment Data
*
* @return array<mixed>
*/
public function createSegment($appId, array $data): array
public function createSegment(string $appId, array $data): array
{
$resolvedData = $this->resolverFactory->createSegmentResolver()->resolve($data);

Expand All @@ -118,6 +128,8 @@ public function createSegment($appId, array $data): array
*
* @param string $appId Application ID
* @param string $segmentId Segment ID
*
* @return array<mixed>
*/
public function deleteSegment(string $appId, string $segmentId): array
{
Expand All @@ -130,8 +142,10 @@ public function deleteSegment(string $appId, string $segmentId): array
/**
* View the details of all the outcomes associated with your app.
*
* @param string $appId Application ID
* @param array $data Outcome data filters
* @param string $appId Application ID
* @param array<mixed> $data Outcome data filters
*
* @return array<mixed>
*/
public function outcomes(string $appId, array $data): array
{
Expand Down
28 changes: 25 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@

final class Config
{
private $applicationId;
private $applicationAuthKey;
private $userAuthKey;
/**
* @var non-empty-string
*/
private string $applicationId;

/**
* @var non-empty-string
*/
private string $applicationAuthKey;

/**
* @var non-empty-string|null
*/
private ?string $userAuthKey;

/**
* @param non-empty-string $applicationId
* @param non-empty-string $applicationAuthKey
* @param non-empty-string|null $userAuthKey
*/
public function __construct(string $applicationId, string $applicationAuthKey, ?string $userAuthKey = null)
{
$this->applicationId = $applicationId;
Expand All @@ -19,6 +35,8 @@ public function __construct(string $applicationId, string $applicationAuthKey, ?

/**
* Get OneSignal application id.
*
* @return non-empty-string
*/
public function getApplicationId(): string
{
Expand All @@ -27,6 +45,8 @@ public function getApplicationId(): string

/**
* Get OneSignal application authentication key.
*
* @return non-empty-string
*/
public function getApplicationAuthKey(): string
{
Expand All @@ -35,6 +55,8 @@ public function getApplicationAuthKey(): string

/**
* Get user authentication key.
*
* @return non-empty-string|null
*/
public function getUserAuthKey(): ?string
{
Expand Down
Loading

0 comments on commit 1f6db11

Please sign in to comment.