Skip to content

Commit

Permalink
PHPStan level 10 part I (#443)
Browse files Browse the repository at this point in the history
This prepares the code for PHPStan to pass at the new level 10 introduced in PHPStan 2.0 (#431). The level is not set to 10 yet in this PR.

Besides some other things, this adds `assert()` calls to assert types for database rows and form field values. Tests are also added to make sure these asserts are correct.
  • Loading branch information
spaze authored Dec 11, 2024
2 parents d7ab032 + 404e8a2 commit 8386aa5
Show file tree
Hide file tree
Showing 113 changed files with 2,163 additions and 826 deletions.
8 changes: 5 additions & 3 deletions app/config/services.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
cliArgs:
type: MichalSpacekCz\Application\Cli\CliArgs
imported: true
- MichalSpacekCz\Application\ComponentParameters
- MichalSpacekCz\Application\Error
- MichalSpacekCz\Application\LinkGenerator
localeLinkGenerator: MichalSpacekCz\Application\Locale\LocaleLinkGenerator(languages: %locales.languages%)
Expand Down Expand Up @@ -31,6 +32,7 @@ services:
create: MichalSpacekCz\Database\TypedDatabase
autowired: MichalSpacekCz\Database\TypedDatabase
typedDatabase.pulse: MichalSpacekCz\Database\TypedDatabase(@database.pulse.explorer)
typedDatabase.upcKeys: MichalSpacekCz\Database\TypedDatabase(@database.upcKeys.explorer)
dateTimeFactory: MichalSpacekCz\DateTime\DateTimeFactory
- MichalSpacekCz\DateTime\DateTimeFormatter(@translation.translator::getDefaultLocale())
- MichalSpacekCz\DateTime\DateTimeParser
Expand Down Expand Up @@ -94,15 +96,15 @@ services:
talkVideoThumbnails: MichalSpacekCz\Media\VideoThumbnails(mediaResources: @talkMediaResources)
interviewVideoThumbnails: MichalSpacekCz\Media\VideoThumbnails(mediaResources: @interviewMediaResources)
- MichalSpacekCz\Net\DnsResolver
- MichalSpacekCz\Pulse\Companies(@database.pulse.explorer)
- MichalSpacekCz\Pulse\Companies(@database.pulse.explorer, @typedDatabase.pulse)
- MichalSpacekCz\Pulse\Passwords\Algorithms\PasswordHashingAlgorithms(@database.pulse.explorer, @typedDatabase.pulse)
- MichalSpacekCz\Pulse\Passwords\Disclosures\PasswordHashingDisclosures(@database.pulse.explorer, @typedDatabase.pulse)
- MichalSpacekCz\Pulse\Passwords\Passwords(@database.pulse.explorer, @typedDatabase.pulse)
- MichalSpacekCz\Pulse\Passwords\PasswordsSorting
- MichalSpacekCz\Pulse\Passwords\Rating
- MichalSpacekCz\Pulse\Passwords\Storage\StorageAlgorithmAttributesFactory
- MichalSpacekCz\Pulse\Passwords\Storage\StorageRegistryFactory
- MichalSpacekCz\Pulse\Sites(@database.pulse.explorer)
- MichalSpacekCz\Pulse\Sites(@database.pulse.explorer, @typedDatabase.pulse)
- MichalSpacekCz\Tags\Tags
- MichalSpacekCz\Talks\Slides\TalkSlides
- MichalSpacekCz\Talks\TalkFactory(videoFactory: @talkVideoFactory)
Expand Down Expand Up @@ -157,7 +159,7 @@ services:
- MichalSpacekCz\Training\Venues\TrainingVenues
- MichalSpacekCz\Twitter\TwitterCards
- MichalSpacekCz\UpcKeys\Technicolor(@database.upcKeys.explorer, apiUrl: %awsLambda.upcKeys.url%, apiKey: %awsLambda.upcKeys.apiKey%)
- MichalSpacekCz\UpcKeys\Ubee(@database.upcKeys.explorer)
- MichalSpacekCz\UpcKeys\Ubee(@typedDatabase.upcKeys)
- MichalSpacekCz\UpcKeys\UpcKeys(routers: [@MichalSpacekCz\UpcKeys\Technicolor, @MichalSpacekCz\UpcKeys\Ubee])
- MichalSpacekCz\User\Manager(passwordEncryption: @passwordEncryption, permanentLoginInterval: %permanentLogin.interval%)
- MichalSpacekCz\Utils\Strings
Expand Down
2 changes: 2 additions & 0 deletions app/config/tests.neon
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ services:
database.pulse.explorer: @database.default.explorer
dateTimeFactory: MichalSpacekCz\Test\DateTime\DateTimeMachineFactory
httpClient: MichalSpacekCz\Test\Http\Client\HttpClientMock
- MichalSpacekCz\Test\Form\FormComponents
session.session: MichalSpacekCz\Test\Http\NullSession
http.request: MichalSpacekCz\Test\Http\Request
http.response: MichalSpacekCz\Test\Http\Response
- MichalSpacekCz\Test\Http\SecurityHeadersFactory
mail.mailer: MichalSpacekCz\Test\NullMailer
translation.translator: MichalSpacekCz\Test\NoOpTranslator(availableLocales: [cs_CZ, en_US], defaultLocale: cs_CZ)
tracy.logger: MichalSpacekCz\Test\NullLogger
security.userStorage: MichalSpacekCz\Test\Security\NullUserStorage
- MichalSpacekCz\Test\TestCaseRunner
trainingFilesStorage: MichalSpacekCz\Test\Training\TrainingFilesNullStorage
cache.storage: Nette\Caching\Storages\DevNullStorage
Expand Down
17 changes: 8 additions & 9 deletions app/disallowed-calls.neon
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ parameters:
method: 'Tester\Environment::skip()'
message: 'use TestCaseRunner::skip() instead, it can ignore skipping with an environment variable'
allowInMethods:
- 'MichalSpacekCz\Test\TestCaseRunner::skip()'
- 'MichalSpacekCz\Test\TestCaseRunner::needsInternet()'
-
method:
- 'Nette\Utils\Strings::match()'
- 'Nette\Utils\Strings::matchAll()'
- 'Nette\Utils\Strings::replace()'
- 'Nette\Utils\Strings::split()'
message: 'use the Preg or Regex class from composer/pcre for better static analysis'
disallowedMethodCalls:
-
Expand All @@ -55,6 +56,12 @@ parameters:
message: 'use MichalSpacekCz\DateTime\DateTimeZoneFactory::get() instead, throws a more specific exception'
allowInMethods:
- 'MichalSpacekCz\DateTime\DateTimeZoneFactory::get()'
-
method:
- 'Nette\Forms\Container::getValues()'
- 'Nette\Forms\Container::getUntrustedValues()'
message: 'use methods from MichalSpacekCz\Form\UiForm instead'

disallowedConstants:
-
constant: 'LIBXML_NOENT'
Expand All @@ -67,14 +74,6 @@ parameters:
- src/Application/ServerEnv.php
- tests/Application/ServerEnvTest.phpt
disallowedClasses:
-
class:
- 'Nette\Application\UI\Form'
- 'Nette\Forms\Form'
message: 'use MichalSpacekCz\Form\UiForm for better type declarations'
allowIn:
- src/Form/UiForm.php
- src/Form/Controls/TrainingControlsFactory.php
-
class:
- 'Spaze\PhpInfo\PhpInfo'
Expand Down
8 changes: 8 additions & 0 deletions app/phpstan-vendor.neon
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ parameters:
message: 'use MichalSpacekCz\DateTime\DateTimeZoneFactory::get() instead, throws a more specific exception'
allowIn:
- vendor/*.php
-
method:
- 'Nette\Forms\Container::getValues()'
- 'Nette\Forms\Container::getUntrustedValues()'
message: 'use methods from MichalSpacekCz\Form\UiForm instead'
allowIn:
- vendor/nette/*.php
disallowedStaticCalls:
-
method: 'Tracy\Debugger::barDump()'
Expand All @@ -218,6 +225,7 @@ parameters:
- 'Nette\Utils\Strings::match()'
- 'Nette\Utils\Strings::matchAll()'
- 'Nette\Utils\Strings::replace()'
- 'Nette\Utils\Strings::split()'
allowIn:
- vendor/contributte/*.php
- vendor/nette/*.php
Expand Down
Loading

0 comments on commit 8386aa5

Please sign in to comment.