Skip to content

Commit

Permalink
Fix PHPStan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Aug 27, 2024
1 parent abb1c41 commit cc3d645
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ phpunit.xml.dist export-ignore
README.md export-ignore
strauss.phar export-ignore
build export-ignore
tests
tests export-ignore
phpstan-stubs export-ignore

/.circleci export-ignore
/.github export-ignore
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ vendor_prefixed
!vendor_prefixed/.gitkeep
!build/strauss.phar
!build/vendor_prefixed/.gitkeep
phpstan.neon
38 changes: 38 additions & 0 deletions phpstan-stubs/gravityforms.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare( strict_types=1 );

/**
* @param string|mixed[] $filter The name of the filter.
* @param mixed $value The value to filter.
* @param mixed ...$extra_values Extra values.
*
* @return mixed The filtered value.
*/
function gf_apply_filters( $filter, $value, ...$extra_values ) {
return $value;
}

/**
* @param string|mixed[] $action The action.
* @param mixed ...$extra_values The extra values.
*/
function gf_do_action( $action, ...$extra_values ): void {
}

/**
* Get a specific property of an array without needing to check if that property exists.
*
* Provide a default value if you want to return a specific value if the property is not set.
*
* @since Unknown
* @access public
*
* @param array<mixed> $array Array from which the property's value should be retrieved.
* @param string $prop Name of the property to be retrieved.
* @param mixed $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
*
* @return null|string|mixed The value
*/
function rgar( $array, $prop, $default = null ) {
}
56 changes: 0 additions & 56 deletions phpstan.neon

This file was deleted.

40 changes: 40 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#$ composer update --optimize-autoloader
#$ vendor/bin/phpstan analyze

includes:
# @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
# Include this extension
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 5
bootstrapFiles:
- gfexcel.php
- tests/phpstan/bootstrap.php
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'

inferPrivatePropertyTypeFromConstructor: true
# autoload_files:
# # Missing constants, function and class stubs
# - %currentWorkingDirectory%/tests/phpstan/bootstrap.php
# # Plugin stubs
# - %currentWorkingDirectory%/tests/phpstan/PLUGIN-stubs.php
# # Procedural code
# - %currentWorkingDirectory%/myplugin-functions.php
# autoload_directories:
# - %currentWorkingDirectory%/inc/
paths:
- src
- tests

scanDirectories:
- vendor/gravityforms/gravityforms # Gravity Forms has no `autoload` section, so we need to configure the path.

scanFiles:
- phpstan-stubs/gravityforms.php.stub # Needed until https://github.com/phpstan/phpstan/issues/11559 is resolved.

# excludes_analyse:
# - %currentWorkingDirectory%/inc/views/
ignoreErrors:
# Unit tests edge cases
- '/MockObject|stdClass>? given.$/'
61 changes: 30 additions & 31 deletions src/Renderer/PHPExcelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,41 @@ protected function getFileName()
* @param string $title
* @return PHPExcelRenderer
*/
private function setTitle($title)
{
$title = gf_apply_filters(
[
'gfexcel_renderer_title',
$this->form['id'],
],
$title,
$this->form
);

$this->setWorksheetTitle($this->worksheet, $this->form);
$this->spreadsheet->getProperties()->setTitle($title);

return $this;
}
private function setTitle( $title ) {
$title = gf_apply_filters(
[
'gfexcel_renderer_title',
$this->form['id'],
],
$title,
$this->form
);

$this->setWorksheetTitle( $this->worksheet, $this->form );
$this->spreadsheet->getProperties()->setTitle( $title );

return $this;
}

/**
* Fluent setter for file subject.
* @param string $title
* @return PHPExcelRenderer
*/
private function setSubject($title)
{
$title = gf_apply_filters(
[
'gfexcel_renderer_subject',
$this->form['id'],
],
$title,
$this->form
);
private function setSubject( $title ) {
$title = gf_apply_filters(
[
'gfexcel_renderer_subject',
$this->form['id'],
],
$title,
$this->form
);

$this->spreadsheet->getProperties()->setSubject($title);
return $this;
}
$this->spreadsheet->getProperties()->setSubject( (string) $title );

return $this;
}

/**
* Fluent setter for properties
Expand Down Expand Up @@ -131,8 +130,8 @@ private function setDescription($description)
$this->form
);

$this->spreadsheet->getProperties()
->setDescription($description);
$this->spreadsheet->getProperties()->setDescription( (string) $description );

return $this;
}
}
6 changes: 4 additions & 2 deletions tests/Action/NotificationsActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public function testDismissNotificationWithInvalidValues(): void
],
]);

$this->assertNull($this->action->dismissNotification());
$this->expectNotToPerformAssertions();
$this->action->dismissNotification();
}

/**
Expand Down Expand Up @@ -158,6 +159,7 @@ public function testRegisterScripts(): void
],
]);

$this->assertNull($this->action->registerScripts());
$this->expectNotToPerformAssertions();
$this->action->registerScripts();
}
}
6 changes: 4 additions & 2 deletions tests/Notification/Repository/NotificationRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function testMarkAsDismissed(): void
'return' => true,
]);

$this->assertNull($this->repository->markAsDismissed($notifications[0]));
$this->expectNotToPerformAssertions();
$this->repository->markAsDismissed($notifications[0]);
}

/**
Expand Down Expand Up @@ -124,7 +125,8 @@ public function testStoreNotification(): void
'return' => true,
]);

$this->assertNull($this->repository->storeNotification(...$new_notifications));
$this->expectNotToPerformAssertions();
$this->repository->storeNotification(...$new_notifications);
}

/**
Expand Down

0 comments on commit cc3d645

Please sign in to comment.