Skip to content

Conversation

sumaiazaman
Copy link

@sumaiazaman sumaiazaman commented Oct 10, 2025

Summary

This PR adds missing PHP return type declarations to methods across Session, Config, and Console classes that previously only had docblock type annotations. This improves type safety, enhances IDE support, and aligns with modern PHP best practices.

Changes Made

Session Classes

src/Illuminate/Session/EncryptedStore.php

  • Added getEncrypter(): EncrypterContract return type declaration

src/Illuminate/Session/CacheBasedSessionHandler.php

  • Added getCache(): CacheContract return type declaration

src/Illuminate/Session/SessionManager.php

  • Added shouldBlock(): bool return type declaration
  • Added blockDriver(): ?string return type declaration
  • Added defaultRouteBlockLockSeconds(): int return type declaration
  • Added defaultRouteBlockWaitSeconds(): int return type declaration
  • Added getSessionConfig(): array return type declaration
  • Added getDefaultDriver(): ?string return type declaration
  • Added setDefaultDriver(): void return type declaration

Config Classes

src/Illuminate/Config/Repository.php

  • Added has(): bool return type declaration
  • Added get(): mixed return type declaration
  • Added getMany(): array return type declaration
  • Added set(): void return type declaration
  • Added prepend(): void return type declaration
  • Added push(): void return type declaration
  • Added all(): array return type declaration

Console Classes

src/Illuminate/Cache/Console/PruneStaleTagsCommand.php

  • Added getArguments(): array return type declaration

src/Illuminate/Foundation/Console/ConfigMakeCommand.php

  • Added promptForMissingArgumentsUsing(): array return type declaration

src/Illuminate/Foundation/Console/ConfigCacheCommand.php

  • Added handle(): void return type declaration

Benefits

  • Enhanced Type Safety: Explicit return types catch type-related errors at compile time
  • Better IDE Support: Improved autocompletion and static analysis
  • Developer Experience: Clearer method contracts and better documentation
  • Modern PHP Standards: Aligns with PHP 8.2+ best practices
  • Backward Compatibility: All changes are fully backward compatible

Testing

  • All existing tests pass without modification
  • No breaking changes to public APIs
  • PHPStan static analysis shows no new errors
  • Changes maintain full backward compatibility

Checklist

  • Added return type declarations to 7 Laravel framework files
  • Verified all existing tests pass
  • Ensured backward compatibility
  • Followed Laravel coding standards
  • No breaking changes introduced

…ole classes

Improves type safety and developer experience by adding explicit return type
declarations to methods that had docblock types but missing PHP return types.

Session classes:
- EncryptedStore::getEncrypter(): EncrypterContract
- CacheBasedSessionHandler::getCache(): CacheContract
- SessionManager: shouldBlock(): bool, blockDriver(): ?string,
  defaultRouteBlockLockSeconds(): int, defaultRouteBlockWaitSeconds(): int,
  getSessionConfig(): array, getDefaultDriver(): ?string, setDefaultDriver(): void

Config classes:
- Repository: has(): bool, get(): mixed, getMany(): array, set(): void,
  prepend(): void, push(): void, all(): array

Console classes:
- PruneStaleTagsCommand::getArguments(): array
- ConfigMakeCommand::promptForMissingArgumentsUsing(): array
- ConfigCacheCommand::handle(): void

All changes maintain backward compatibility and follow Laravel's coding standards.
Tests pass and PHPStan shows no errors.
@sumaiazaman sumaiazaman changed the title Add missing PHP return type declarations to Session, Config Add missing PHP return type declarations to Session, Config, and Console classes Oct 10, 2025
@sumaiazaman sumaiazaman changed the title Add missing PHP return type declarations to Session, Config, and Console classes [12.x] Add missing PHP return type declarations to Session, Config, and Console classes Oct 10, 2025
@shaedrich
Copy link
Contributor

As they are potential breaking changes, these should be directed at master/13.x

@rodrigopedra
Copy link
Contributor

  • Backward Compatibility: All changes are fully backward compatible

Adding return types to public methods is a breaking change to any other class extending that class.

As @shaedrich said, this should have been sent to master instead.

But I have a feeling PRs that update just a handful of classes would be rejected.

You can try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants