Skip to content

Commit

Permalink
ISSUE-337: fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
tatevikg1 committed Dec 9, 2024
1 parent 707b0a1 commit 9658c6c
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 101 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"phpunit/phpunit": "^9.5",
"guzzlehttp/guzzle": "^6.3.0",
"squizlabs/php_codesniffer": "^3.2.0",
"phpstan/phpstan": "^0.12.57",
"phpstan/phpstan": "^1.10",
"nette/caching": "^3.0.0",
"nikic/php-parser": "^4.19.1",
"phpmd/phpmd": "^2.6.0",
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ parameters:
- src
- tests
- public
ignoreErrors:
- '#Cannot call method (?:willReturn|shouldBeCalledOnce|shouldNotBeCalled|shouldBeCalled|shouldNotHaveBeenCalled)\(\) on .*\.#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::willReturn\(\)#'
81 changes: 42 additions & 39 deletions src/Composer/ScriptHandler.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

namespace PhpList\Core\Composer;

use Composer\Package\PackageInterface;
use Composer\Script\Event;
use DomainException;
use PhpList\Core\Core\ApplicationStructure;
use RuntimeException;
use Symfony\Component\Filesystem\Filesystem;

/**
Expand Down Expand Up @@ -48,7 +51,7 @@ class ScriptHandler
/**
* @return string absolute application root directory without the trailing slash
*
* @throws \RuntimeException if there is no composer.json in the application root
* @throws RuntimeException if there is no composer.json in the application root
*/
private static function getApplicationRoot(): string
{
Expand All @@ -61,7 +64,7 @@ private static function getApplicationRoot(): string
*/
private static function getCoreDirectory(): string
{
return static::getApplicationRoot() . '/vendor/' . static::CORE_PACKAGE_NAME;
return self::getApplicationRoot() . '/vendor/' . static::CORE_PACKAGE_NAME;
}

/**
Expand All @@ -73,12 +76,12 @@ private static function getCoreDirectory(): string
*
* @return void
*
* @throws \DomainException if this method is called for the core package
* @throws DomainException if this method is called for the core package
*/
public static function createBinaries(Event $event)
public static function createBinaries(Event $event): void
{
static::preventScriptFromCorePackage($event);
static::mirrorDirectoryFromCore('bin');
self::preventScriptFromCorePackage($event);
self::mirrorDirectoryFromCore('bin');
}

/**
Expand All @@ -90,27 +93,27 @@ public static function createBinaries(Event $event)
*
* @return void
*
* @throws \DomainException if this method is called for the core package
* @throws DomainException if this method is called for the core package
*/
public static function createPublicWebDirectory(Event $event)
public static function createPublicWebDirectory(Event $event): void
{
static::preventScriptFromCorePackage($event);
static::mirrorDirectoryFromCore('public');
self::preventScriptFromCorePackage($event);
self::mirrorDirectoryFromCore('public');
}

/**
* @param Event $event
*
* @return void
*
* @throws \DomainException if this method is called for the core package
* @throws DomainException if this method is called for the core package
*/
private static function preventScriptFromCorePackage(Event $event)
private static function preventScriptFromCorePackage(Event $event): void
{
$composer = $event->getComposer();
$packageName = $composer->getPackage()->getName();
if ($packageName === static::CORE_PACKAGE_NAME) {
throw new \DomainException(
if ($packageName === self::CORE_PACKAGE_NAME) {
throw new DomainException(
'This Composer script must not be called for the core package itself.',
1501240572
);
Expand All @@ -128,14 +131,14 @@ private static function preventScriptFromCorePackage(Event $event)
*
* @return void
*/
private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes)
private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes): void
{
$directoryWithSlashes = '/' . $directoryWithoutSlashes . '/';

$fileSystem = new Filesystem();
$fileSystem->mirror(
static::getCoreDirectory() . $directoryWithSlashes,
static::getApplicationRoot() . $directoryWithSlashes,
self::getCoreDirectory() . $directoryWithSlashes,
self::getApplicationRoot() . $directoryWithSlashes,
null,
['override' => true, 'delete' => false]
);
Expand All @@ -148,13 +151,13 @@ private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes)
*
* @return void
*/
public static function listModules(Event $event)
public static function listModules(Event $event): void
{
$packageRepository = new PackageRepository();
$packageRepository->injectComposer($event->getComposer());

$modules = $packageRepository->findModules();
$maximumPackageNameLength = static::calculateMaximumPackageNameLength($modules);
$maximumPackageNameLength = self::calculateMaximumPackageNameLength($modules);

foreach ($modules as $module) {
$paddedName = str_pad($module->getName(), $maximumPackageNameLength + 1);
Expand Down Expand Up @@ -185,11 +188,11 @@ private static function calculateMaximumPackageNameLength(array $modules): int
*
* @return void
*/
public static function createBundleConfiguration(Event $event)
public static function createBundleConfiguration(Event $event): void
{
static::createAndWriteFile(
static::getApplicationRoot() . static::BUNDLE_CONFIGURATION_FILE,
static::createAndInitializeModuleFinder($event)->createBundleConfigurationYaml()
self::createAndWriteFile(
self::getApplicationRoot() . self::BUNDLE_CONFIGURATION_FILE,
self::createAndInitializeModuleFinder($event)->createBundleConfigurationYaml()
);
}

Expand All @@ -205,13 +208,13 @@ public static function createBundleConfiguration(Event $event)
*
* @return void
*
* @throws \RuntimeException
* @throws RuntimeException
*/
private static function createAndWriteFile(string $path, string $contents)
private static function createAndWriteFile(string $path, string $contents): void
{
$fileHandle = fopen($path, 'wb');
if ($fileHandle === false) {
throw new \RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
throw new RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
}

fwrite($fileHandle, $contents);
Expand All @@ -226,11 +229,11 @@ private static function createAndWriteFile(string $path, string $contents)
*
* @return void
*/
public static function createRoutesConfiguration(Event $event)
public static function createRoutesConfiguration(Event $event): void
{
static::createAndWriteFile(
static::getApplicationRoot() . static::ROUTES_CONFIGURATION_FILE,
static::createAndInitializeModuleFinder($event)->createRouteConfigurationYaml()
self::createAndWriteFile(
self::getApplicationRoot() . self::ROUTES_CONFIGURATION_FILE,
self::createAndInitializeModuleFinder($event)->createRouteConfigurationYaml()
);
}

Expand All @@ -255,20 +258,20 @@ private static function createAndInitializeModuleFinder(Event $event): ModuleFin
*
* @return void
*/
public static function clearAllCaches()
public static function clearAllCaches():void
{
$fileSystem = new Filesystem();
$fileSystem->remove(static::getApplicationRoot() . '/var/cache');
$fileSystem->remove(self::getApplicationRoot() . '/var/cache');
}

/**
* Creates config/parameters.yml (the parameters configuration file).
*
* @return void
*/
public static function createParametersConfiguration()
public static function createParametersConfiguration(): void
{
$configurationFilePath = static::getApplicationRoot() . static::PARAMETERS_CONFIGURATION_FILE;
$configurationFilePath = self::getApplicationRoot() . self::PARAMETERS_CONFIGURATION_FILE;
if (file_exists($configurationFilePath)) {
return;
}
Expand All @@ -279,7 +282,7 @@ public static function createParametersConfiguration()
$secret = bin2hex(random_bytes(20));
$configuration = sprintf($template, $secret);

static::createAndWriteFile($configurationFilePath, $configuration);
self::createAndWriteFile($configurationFilePath, $configuration);
}

/**
Expand All @@ -289,11 +292,11 @@ public static function createParametersConfiguration()
*
* @return void
*/
public static function createGeneralConfiguration(Event $event)
public static function createGeneralConfiguration(Event $event): void
{
static::createAndWriteFile(
static::getApplicationRoot() . static::GENERAL_CONFIGURATION_FILE,
static::createAndInitializeModuleFinder($event)->createGeneralConfigurationYaml()
self::createAndWriteFile(
self::getApplicationRoot() . self::GENERAL_CONFIGURATION_FILE,
self::createAndInitializeModuleFinder($event)->createGeneralConfigurationYaml()
);
}
}
8 changes: 0 additions & 8 deletions src/Core/ApplicationKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load($this->getApplicationDir() . '/config/config_modules.yml');
}

/**
* @return bool
*/
private function shouldHaveDevelopmentBundles(): bool
{
return $this->environment !== Environment::PRODUCTION;
}

/**
* Reads the bundles from the bundle configuration file and instantiates them.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private function isDebugEnabled(): bool
*
* @return Bootstrap fluent interface
*/
public function ensureDevelopmentOrTestingEnvironment(): static
public function ensureDevelopmentOrTestingEnvironment(): self
{
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === Environment::TESTING) {
return $this;
Expand Down
8 changes: 0 additions & 8 deletions src/Domain/Model/Identity/Administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,4 @@ public function setSuperUser(bool $superUser): void
{
$this->superUser = $superUser;
}

#[ORM\PrePersist]
public function setCreationDate(): void
{
if ($this->creationDate === null) {
$this->creationDate = new DateTime();
}
}
}
8 changes: 4 additions & 4 deletions src/TestingSupport/Traits/SymfonyServerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function getBaseUrl(): string
private function waitForServerLockFileToAppear(): void
{
$currentWaitTime = 0;
while (!$this->lockFileExists() && $currentWaitTime < static::$maximumWaitTimeForServerLockFile) {
while (!$this->lockFileExists() && $currentWaitTime < self::$maximumWaitTimeForServerLockFile) {
$process = new Process(['symfony', 'server:status', '--no-ansi']);
$process->run();

Expand All @@ -84,13 +84,13 @@ private function waitForServerLockFileToAppear(): void
file_put_contents(self::$lockFileName, trim($port));
}
}
usleep(static::$waitTimeBetweenServerCommands);
$currentWaitTime += static::$waitTimeBetweenServerCommands;
usleep(self::$waitTimeBetweenServerCommands);
$currentWaitTime += self::$waitTimeBetweenServerCommands;
}

if (!$this->lockFileExists()) {
throw new RuntimeException(
'There is no symfony server lock file "' . static::$lockFileName . '".',
'There is no symfony server lock file "' . self::$lockFileName . '".',
1516625236
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public function load(ObjectManager $manager): void
$this->setSubjectId($admin, (int)$row['id']);
$admin->setLoginName($row['loginname']);
$admin->setEmailAddress($row['email']);
$this->setSubjectProperty($admin,'creationDate', new DateTime($row['created']));
$admin->setPasswordHash($row['password']);
$this->setSubjectProperty($admin,'passwordChangeDate', new DateTime($row['passwordchanged']));
$admin->setDisabled((bool) $row['disabled']);
$admin->setSuperUser((bool) $row['superuser']);

$manager->persist($admin);
$this->setSubjectProperty($admin,'creationDate', new DateTime($row['created']));
$this->setSubjectProperty($admin,'passwordChangeDate', new DateTime($row['passwordchanged']));
}

fclose($handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function tearDown(): void

public function testFindReadsModelFromDatabase(): void
{
/** @var $actual Administrator */
/** @var Administrator $actual */
$actual = $this->repository->find(1);

$this->assertNotNull($actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ public function testFindsAssociatedSubscriptions()
$this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);

$id = 2;
/** @var Subscription[] $model */
$subscriptions = $this->subscriptionRepository->findBySubscriberList($id);
$subscriber = $this->subscriberRepository->find($id);
/** @var Subscription[] $subscriptions */
$subscriptions = $this->subscriptionRepository->findBySubscriberList($subscriber);

self::assertNotEmpty($subscriptions);
/** @var Subscription $firstSubscription */
$firstSubscription = $subscriptions[0];
self::assertInstanceOf(Subscription::class, $firstSubscription);
$expectedSubscriberId = 1;
Expand All @@ -182,7 +182,7 @@ public function testFindsAssociatedSubscribers()
$this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);

$id = 2;
/** @var Subscriber[] $model */
/** @var Subscriber[] $subscribers */
$subscribers = $this->subscriberRepository->getSubscribersBySubscribedListId($id);

$expectedSubscriber = $this->subscriberRepository->find(1);
Expand All @@ -198,7 +198,7 @@ public function testRemoveAlsoRemovesAssociatedSubscriptions()
$initialNumberOfSubscriptions = count($this->subscriptionRepository->findAll());

$id = 2;
/** @var SubscriberList $model */
/** @var SubscriberList $subscriberList */
$subscriberList = $this->subscriberListRepository->findWithSubscription($id);

$numberOfAssociatedSubscriptions = count($subscriberList->getSubscriptions());
Expand Down
Loading

0 comments on commit 9658c6c

Please sign in to comment.