Skip to content

Commit 9658c6c

Browse files
committed
ISSUE-337: fix phpstan
1 parent 707b0a1 commit 9658c6c

File tree

12 files changed

+99
-101
lines changed

12 files changed

+99
-101
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"phpunit/phpunit": "^9.5",
5656
"guzzlehttp/guzzle": "^6.3.0",
5757
"squizlabs/php_codesniffer": "^3.2.0",
58-
"phpstan/phpstan": "^0.12.57",
58+
"phpstan/phpstan": "^1.10",
5959
"nette/caching": "^3.0.0",
6060
"nikic/php-parser": "^4.19.1",
6161
"phpmd/phpmd": "^2.6.0",

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ parameters:
55
- src
66
- tests
77
- public
8-
ignoreErrors:
9-
- '#Cannot call method (?:willReturn|shouldBeCalledOnce|shouldNotBeCalled|shouldBeCalled|shouldNotHaveBeenCalled)\(\) on .*\.#'
10-
- '#Call to an undefined method [a-zA-Z0-9\\_]+::willReturn\(\)#'

src/Composer/ScriptHandler.php

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace PhpList\Core\Composer;
56

67
use Composer\Package\PackageInterface;
78
use Composer\Script\Event;
9+
use DomainException;
810
use PhpList\Core\Core\ApplicationStructure;
11+
use RuntimeException;
912
use Symfony\Component\Filesystem\Filesystem;
1013

1114
/**
@@ -48,7 +51,7 @@ class ScriptHandler
4851
/**
4952
* @return string absolute application root directory without the trailing slash
5053
*
51-
* @throws \RuntimeException if there is no composer.json in the application root
54+
* @throws RuntimeException if there is no composer.json in the application root
5255
*/
5356
private static function getApplicationRoot(): string
5457
{
@@ -61,7 +64,7 @@ private static function getApplicationRoot(): string
6164
*/
6265
private static function getCoreDirectory(): string
6366
{
64-
return static::getApplicationRoot() . '/vendor/' . static::CORE_PACKAGE_NAME;
67+
return self::getApplicationRoot() . '/vendor/' . static::CORE_PACKAGE_NAME;
6568
}
6669

6770
/**
@@ -73,12 +76,12 @@ private static function getCoreDirectory(): string
7376
*
7477
* @return void
7578
*
76-
* @throws \DomainException if this method is called for the core package
79+
* @throws DomainException if this method is called for the core package
7780
*/
78-
public static function createBinaries(Event $event)
81+
public static function createBinaries(Event $event): void
7982
{
80-
static::preventScriptFromCorePackage($event);
81-
static::mirrorDirectoryFromCore('bin');
83+
self::preventScriptFromCorePackage($event);
84+
self::mirrorDirectoryFromCore('bin');
8285
}
8386

8487
/**
@@ -90,27 +93,27 @@ public static function createBinaries(Event $event)
9093
*
9194
* @return void
9295
*
93-
* @throws \DomainException if this method is called for the core package
96+
* @throws DomainException if this method is called for the core package
9497
*/
95-
public static function createPublicWebDirectory(Event $event)
98+
public static function createPublicWebDirectory(Event $event): void
9699
{
97-
static::preventScriptFromCorePackage($event);
98-
static::mirrorDirectoryFromCore('public');
100+
self::preventScriptFromCorePackage($event);
101+
self::mirrorDirectoryFromCore('public');
99102
}
100103

101104
/**
102105
* @param Event $event
103106
*
104107
* @return void
105108
*
106-
* @throws \DomainException if this method is called for the core package
109+
* @throws DomainException if this method is called for the core package
107110
*/
108-
private static function preventScriptFromCorePackage(Event $event)
111+
private static function preventScriptFromCorePackage(Event $event): void
109112
{
110113
$composer = $event->getComposer();
111114
$packageName = $composer->getPackage()->getName();
112-
if ($packageName === static::CORE_PACKAGE_NAME) {
113-
throw new \DomainException(
115+
if ($packageName === self::CORE_PACKAGE_NAME) {
116+
throw new DomainException(
114117
'This Composer script must not be called for the core package itself.',
115118
1501240572
116119
);
@@ -128,14 +131,14 @@ private static function preventScriptFromCorePackage(Event $event)
128131
*
129132
* @return void
130133
*/
131-
private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes)
134+
private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes): void
132135
{
133136
$directoryWithSlashes = '/' . $directoryWithoutSlashes . '/';
134137

135138
$fileSystem = new Filesystem();
136139
$fileSystem->mirror(
137-
static::getCoreDirectory() . $directoryWithSlashes,
138-
static::getApplicationRoot() . $directoryWithSlashes,
140+
self::getCoreDirectory() . $directoryWithSlashes,
141+
self::getApplicationRoot() . $directoryWithSlashes,
139142
null,
140143
['override' => true, 'delete' => false]
141144
);
@@ -148,13 +151,13 @@ private static function mirrorDirectoryFromCore(string $directoryWithoutSlashes)
148151
*
149152
* @return void
150153
*/
151-
public static function listModules(Event $event)
154+
public static function listModules(Event $event): void
152155
{
153156
$packageRepository = new PackageRepository();
154157
$packageRepository->injectComposer($event->getComposer());
155158

156159
$modules = $packageRepository->findModules();
157-
$maximumPackageNameLength = static::calculateMaximumPackageNameLength($modules);
160+
$maximumPackageNameLength = self::calculateMaximumPackageNameLength($modules);
158161

159162
foreach ($modules as $module) {
160163
$paddedName = str_pad($module->getName(), $maximumPackageNameLength + 1);
@@ -185,11 +188,11 @@ private static function calculateMaximumPackageNameLength(array $modules): int
185188
*
186189
* @return void
187190
*/
188-
public static function createBundleConfiguration(Event $event)
191+
public static function createBundleConfiguration(Event $event): void
189192
{
190-
static::createAndWriteFile(
191-
static::getApplicationRoot() . static::BUNDLE_CONFIGURATION_FILE,
192-
static::createAndInitializeModuleFinder($event)->createBundleConfigurationYaml()
193+
self::createAndWriteFile(
194+
self::getApplicationRoot() . self::BUNDLE_CONFIGURATION_FILE,
195+
self::createAndInitializeModuleFinder($event)->createBundleConfigurationYaml()
193196
);
194197
}
195198

@@ -205,13 +208,13 @@ public static function createBundleConfiguration(Event $event)
205208
*
206209
* @return void
207210
*
208-
* @throws \RuntimeException
211+
* @throws RuntimeException
209212
*/
210-
private static function createAndWriteFile(string $path, string $contents)
213+
private static function createAndWriteFile(string $path, string $contents): void
211214
{
212215
$fileHandle = fopen($path, 'wb');
213216
if ($fileHandle === false) {
214-
throw new \RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
217+
throw new RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
215218
}
216219

217220
fwrite($fileHandle, $contents);
@@ -226,11 +229,11 @@ private static function createAndWriteFile(string $path, string $contents)
226229
*
227230
* @return void
228231
*/
229-
public static function createRoutesConfiguration(Event $event)
232+
public static function createRoutesConfiguration(Event $event): void
230233
{
231-
static::createAndWriteFile(
232-
static::getApplicationRoot() . static::ROUTES_CONFIGURATION_FILE,
233-
static::createAndInitializeModuleFinder($event)->createRouteConfigurationYaml()
234+
self::createAndWriteFile(
235+
self::getApplicationRoot() . self::ROUTES_CONFIGURATION_FILE,
236+
self::createAndInitializeModuleFinder($event)->createRouteConfigurationYaml()
234237
);
235238
}
236239

@@ -255,20 +258,20 @@ private static function createAndInitializeModuleFinder(Event $event): ModuleFin
255258
*
256259
* @return void
257260
*/
258-
public static function clearAllCaches()
261+
public static function clearAllCaches():void
259262
{
260263
$fileSystem = new Filesystem();
261-
$fileSystem->remove(static::getApplicationRoot() . '/var/cache');
264+
$fileSystem->remove(self::getApplicationRoot() . '/var/cache');
262265
}
263266

264267
/**
265268
* Creates config/parameters.yml (the parameters configuration file).
266269
*
267270
* @return void
268271
*/
269-
public static function createParametersConfiguration()
272+
public static function createParametersConfiguration(): void
270273
{
271-
$configurationFilePath = static::getApplicationRoot() . static::PARAMETERS_CONFIGURATION_FILE;
274+
$configurationFilePath = self::getApplicationRoot() . self::PARAMETERS_CONFIGURATION_FILE;
272275
if (file_exists($configurationFilePath)) {
273276
return;
274277
}
@@ -279,7 +282,7 @@ public static function createParametersConfiguration()
279282
$secret = bin2hex(random_bytes(20));
280283
$configuration = sprintf($template, $secret);
281284

282-
static::createAndWriteFile($configurationFilePath, $configuration);
285+
self::createAndWriteFile($configurationFilePath, $configuration);
283286
}
284287

285288
/**
@@ -289,11 +292,11 @@ public static function createParametersConfiguration()
289292
*
290293
* @return void
291294
*/
292-
public static function createGeneralConfiguration(Event $event)
295+
public static function createGeneralConfiguration(Event $event): void
293296
{
294-
static::createAndWriteFile(
295-
static::getApplicationRoot() . static::GENERAL_CONFIGURATION_FILE,
296-
static::createAndInitializeModuleFinder($event)->createGeneralConfigurationYaml()
297+
self::createAndWriteFile(
298+
self::getApplicationRoot() . self::GENERAL_CONFIGURATION_FILE,
299+
self::createAndInitializeModuleFinder($event)->createGeneralConfigurationYaml()
297300
);
298301
}
299302
}

src/Core/ApplicationKernel.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
123123
$loader->load($this->getApplicationDir() . '/config/config_modules.yml');
124124
}
125125

126-
/**
127-
* @return bool
128-
*/
129-
private function shouldHaveDevelopmentBundles(): bool
130-
{
131-
return $this->environment !== Environment::PRODUCTION;
132-
}
133-
134126
/**
135127
* Reads the bundles from the bundle configuration file and instantiates them.
136128
*

src/Core/Bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function isDebugEnabled(): bool
146146
*
147147
* @return Bootstrap fluent interface
148148
*/
149-
public function ensureDevelopmentOrTestingEnvironment(): static
149+
public function ensureDevelopmentOrTestingEnvironment(): self
150150
{
151151
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === Environment::TESTING) {
152152
return $this;

src/Domain/Model/Identity/Administrator.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,4 @@ public function setSuperUser(bool $superUser): void
127127
{
128128
$this->superUser = $superUser;
129129
}
130-
131-
#[ORM\PrePersist]
132-
public function setCreationDate(): void
133-
{
134-
if ($this->creationDate === null) {
135-
$this->creationDate = new DateTime();
136-
}
137-
}
138130
}

src/TestingSupport/Traits/SymfonyServerTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function getBaseUrl(): string
7373
private function waitForServerLockFileToAppear(): void
7474
{
7575
$currentWaitTime = 0;
76-
while (!$this->lockFileExists() && $currentWaitTime < static::$maximumWaitTimeForServerLockFile) {
76+
while (!$this->lockFileExists() && $currentWaitTime < self::$maximumWaitTimeForServerLockFile) {
7777
$process = new Process(['symfony', 'server:status', '--no-ansi']);
7878
$process->run();
7979

@@ -84,13 +84,13 @@ private function waitForServerLockFileToAppear(): void
8484
file_put_contents(self::$lockFileName, trim($port));
8585
}
8686
}
87-
usleep(static::$waitTimeBetweenServerCommands);
88-
$currentWaitTime += static::$waitTimeBetweenServerCommands;
87+
usleep(self::$waitTimeBetweenServerCommands);
88+
$currentWaitTime += self::$waitTimeBetweenServerCommands;
8989
}
9090

9191
if (!$this->lockFileExists()) {
9292
throw new RuntimeException(
93-
'There is no symfony server lock file "' . static::$lockFileName . '".',
93+
'There is no symfony server lock file "' . self::$lockFileName . '".',
9494
1516625236
9595
);
9696
}

tests/Integration/Domain/Repository/Fixtures/AdministratorFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public function load(ObjectManager $manager): void
3636
$this->setSubjectId($admin, (int)$row['id']);
3737
$admin->setLoginName($row['loginname']);
3838
$admin->setEmailAddress($row['email']);
39-
$this->setSubjectProperty($admin,'creationDate', new DateTime($row['created']));
4039
$admin->setPasswordHash($row['password']);
41-
$this->setSubjectProperty($admin,'passwordChangeDate', new DateTime($row['passwordchanged']));
4240
$admin->setDisabled((bool) $row['disabled']);
4341
$admin->setSuperUser((bool) $row['superuser']);
4442

4543
$manager->persist($admin);
44+
$this->setSubjectProperty($admin,'creationDate', new DateTime($row['created']));
45+
$this->setSubjectProperty($admin,'passwordChangeDate', new DateTime($row['passwordchanged']));
4646
}
4747

4848
fclose($handle);

tests/Integration/Domain/Repository/Identity/AdministratorRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function tearDown(): void
4242

4343
public function testFindReadsModelFromDatabase(): void
4444
{
45-
/** @var $actual Administrator */
45+
/** @var Administrator $actual */
4646
$actual = $this->repository->find(1);
4747

4848
$this->assertNotNull($actual);

tests/Integration/Domain/Repository/Messaging/SubscriberListRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ public function testFindsAssociatedSubscriptions()
166166
$this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);
167167

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

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

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

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

200200
$id = 2;
201-
/** @var SubscriberList $model */
201+
/** @var SubscriberList $subscriberList */
202202
$subscriberList = $this->subscriberListRepository->findWithSubscription($id);
203203

204204
$numberOfAssociatedSubscriptions = count($subscriberList->getSubscriptions());

0 commit comments

Comments
 (0)