Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHPStan in project #50

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Install dependencies with composer. Two CI tools are configured for this project
```
composer install
php vendor/bin/php-cs-fixer fix --no-interaction --dry-run --diff
php phpstan analyse tests/phpstan/phpstan.neon
php vendor/bin/phpstan analyse --configuration=tests/phpstan/phpstan.neon
```

Before submitting changes to the projects, tests can be run with:
Expand Down
1 change: 1 addition & 0 deletions bin/header-stamp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ $command = new UpdateLicensesCommand();

$application->add($command);

// @phpstan-ignore argument.type (Name is set in the command)
$application->setDefaultCommand($command->getName());
$application->run();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"author": "PrestaShop",
"require-dev": {
"prestashop/php-dev-tools": "1.*",
"phpstan/phpstan": "^0.12.83"
"phpstan/phpstan": "^1.12"
}
}
36 changes: 15 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/Command/UpdateLicensesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,6 @@ private function addLicenseToJsonFile(SplFileInfo $file): void
$this->reportOperationResult($encodedContent, $file->getContents(), $file->getFilename());
}

/**
* @var string
* @var string
*/
private function reportOperationResult(string $newFileContent, string $oldFileContent, string $filename): void
{
if ($newFileContent !== $oldFileContent) {
Expand Down
10 changes: 6 additions & 4 deletions src/LicenseHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace PrestaShop\HeaderStamp;

use Exception;

/**
* Class responsible of loading license file in memory and returning its content
*/
Expand Down Expand Up @@ -52,7 +54,7 @@ public function __construct(string $filePath)
public function getContent(): string
{
if (null === $this->content) {
$this->loadFile();
$this->content = $this->loadFile();
}

return $this->content;
Expand All @@ -61,7 +63,7 @@ public function getContent(): string
/**
* Checks the file and loads its content in memory
*/
private function loadFile(): void
private function loadFile(): string
{
if (!\file_exists($this->filePath)) {
// If the file is not found, we might have a relative path
Expand All @@ -84,9 +86,9 @@ private function loadFile(): void

$content = \file_get_contents($this->filePath);
if ($content === false) {
return;
throw new Exception('Cannot load license file ' . $this->filePath . '.');
}

$this->content = $content;
return $content;
}
}
4 changes: 2 additions & 2 deletions tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
paths:
- ../../src/
- ../../src
- ../../bin/header-stamp
level: 7
level: 8
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
Loading