Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e180ca0
refactor: Add PHP 8+ type declarations for PHPStan Level 5 (WIP)
ttsuru Oct 30, 2025
101b407
ci: Simplify PHPStan output format in CI
ttsuru Oct 30, 2025
a4205fe
fix: Allow null for Security::encrypt() plain parameter
ttsuru Oct 30, 2025
d80e3b4
style: Apply PHP CodeSniffer fixes
ttsuru Oct 30, 2025
5d41d80
ci: Add cs2pr integration for PHPStan results in PRs
ttsuru Oct 30, 2025
f221598
docs: Add EmailConfigInterface migration guide to UPGRADE.md
ttsuru Oct 30, 2025
3f0fa0d
fix: Fix PaginatorControllerPost::find() to properly handle 'popular'…
ttsuru Oct 30, 2025
ea22795
refactor: Fix PHPStan Level 5 type errors across codebase
ttsuru Oct 30, 2025
a9e677c
refactor: Add type declarations for PHPStan Level 5 compliance
ttsuru Oct 30, 2025
bfb7138
refactor: Add type declarations to Model behaviors for PHPStan Level 5
ttsuru Oct 31, 2025
0dda8c4
fix: Update truncate() return type to match execute() return type
ttsuru Oct 31, 2025
614ecc7
refactor: Replace SqlserverTestResultIterator with PDOStatement mock
ttsuru Oct 31, 2025
fd08b4c
style: Apply PHP CodeSniffer fixes
ttsuru Oct 31, 2025
e2c455c
refactor: Add type declarations to Console and Utility classes
ttsuru Oct 31, 2025
c13814c
refactor: Add type declarations to Console commands and Core classes
ttsuru Oct 31, 2025
81b8f66
refactor: Add type declarations to CakeSchema and fix schema tests
ttsuru Oct 31, 2025
6450b77
refactor: Add comprehensive type declarations across Model and I18n c…
ttsuru Oct 31, 2025
bbdfdb2
refactor: Add Dispatcher property type declaration to ConsoleShell
ttsuru Oct 31, 2025
1ceb6b3
refactor: Add type declarations to Controller and Component classes
ttsuru Oct 31, 2025
f41f10b
fix: Fix Configure::restore() and simplify Multibyte character conver…
ttsuru Oct 31, 2025
213d5aa
docs: Add PHPStan Level 5 achievement to CHANGELOG
ttsuru Oct 31, 2025
a9aeeff
refactor: Add type declarations and previous exception to CakeException
ttsuru Oct 31, 2025
903c09e
refactor: Add type declarations to exceptions, functions, and remaini…
ttsuru Nov 4, 2025
0cc2875
style: Remove unused Exception imports and add missing DocBlock
ttsuru Nov 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ jobs:
- name: Install Composer Packages
run: composer install --prefer-dist --no-interaction --no-progress

- name: Copy database.php
run: cp ./tests/config/database.php ./vendor/pieceofcake2/app/config/
- name: Copy config
run: |
cp ./tests/config/database.php ./vendor/pieceofcake2/app/config/
cp ./tests/config/Schema/i18n.php ./vendor/pieceofcake2/app/config/Schema/

- name: Make temporary directories writable
run: |
Expand Down
65 changes: 65 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,71 @@

## Unreleased

### PHPStan Level 5 Compliance & Comprehensive Type Declarations ([PR #32](https://github.com/pieceofcake2/cakephp/pull/32))

Achieved 100% PHPStan Level 5 compliance with comprehensive type declarations across the entire codebase. This represents a major milestone in type safety and static analysis coverage.

#### PHPStan Level 5 Achievement
- **Static Analysis**: PHPStan Level 5 now passes with zero errors (599 → 0)
- Added type declarations to 200+ methods across all core classes
- Fixed type coercion issues in transaction handling and return values
- Resolved contravariance issues in method signatures
- Fixed undefined variable and property errors throughout codebase

#### Comprehensive Type Declarations

**Model Layer:**
- Model, I18nModel: Complete method signatures with return types
- Behaviors: TreeBehavior (265 errors), TranslateBehavior, ContainableBehavior, AclBehavior
- BehaviorCollection, ModelBehavior: Full type coverage
- AclNode, Permission: Type declarations added

**DataSource Layer:**
- DboSource: Comprehensive type declarations for all methods
- Database Drivers: Mysql, Postgres, Sqlite, Sqlserver with full type coverage
- DataSource, CakeSession, ConnectionManager: Complete type declarations
- Removed `extract()` usage in `buildColumn()` for better type safety

**Controller Layer:**
- Controller, Component: Base class type declarations
- All Auth classes: Authenticators and Authorizers with full type coverage
- Components: Acl (split PhpAcl into PhpAco/PhpAro classes), Security, RequestHandler, Flash
- ComponentCollection, Scaffold: Type declarations added

**Console Layer:**
- Shell, ShellDispatcher: Complete method signatures
- All Commands: AclShell, ApiShell, SchemaShell, I18nShell, TestShell, ConsoleShell
- Tasks: ExtractTask with comprehensive type coverage
- ConsoleOutput, ConsoleInput: Full type declarations

**Core & Utilities:**
- Configure: Type declarations and bug fixes
- App, CakeObject: Type declarations
- CakeEventManager, CakeEvent: Full type coverage
- L10n, I18n, Multibyte: Complete type declarations
- CakeText, Folder: Type declarations added
- LegacyClassLoader: Changed `autoload()` return type to `void` (spl_autoload_register requirement)

**Test Infrastructure:**
- CakeTestFixture: Updated to match new type signatures
- Replaced `SqlserverTestResultIterator` with proper PDOStatement mocks
- Updated all test mocks to return correct types

#### Code Quality Improvements
- **Multibyte Optimization**: Simplified ASCII character conversion
- Removed unnecessary loops in `strtolower()` and `strtoupper()`
- Changed from 6-line loop to simple `ord(strtolower(chr($char)))`
- **EmailConfig Interface**: Added type-safe email configuration
- New `EmailConfigInterface` for consistent email configuration
- Updated UPGRADE.md with migration guide
- **Test Mock Improvements**: Enhanced type safety in test mocks
- All database transaction mocks now return proper boolean values
- Prevents null→false coercion issues with typed return values

#### Breaking Changes
- `EmailConfig` classes must now implement `EmailConfigInterface`
- See UPGRADE.md for detailed migration instructions

### PHPStan Static Analysis & Comprehensive Type Declarations ([PR #31](https://github.com/pieceofcake2/cakephp/pull/31))

Achieved 100% PHPStan level 0 compliance and added comprehensive property type declarations to all CakePHP 2.x core classes using Rector.
Expand Down
45 changes: 45 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,51 @@ class User extends AppModel

**Your existing non-namespaced application will continue to work without any changes** thanks to the LegacyClassLoader. This migration is completely optional and can be done at your own pace.

### EmailConfig Must Implement EmailConfigInterface ([PR #32](https://github.com/pieceofcake2/cakephp/pull/32))

All email configuration classes must now implement `EmailConfigInterface`. This change improves type safety and ensures consistent email configuration across applications.

#### What Changed

- `EmailConfig` class must implement `Cake\Network\Email\EmailConfigInterface`
- The interface requires all email configuration classes to define email settings as public properties

#### Impact on Your Application

If you have a custom `EmailConfig` class in `app/Config/email.php` or `config/email.php`, you need to update it to implement the interface:

**Before:**
```php
<?php
class EmailConfig
{
public $default = [
'transport' => 'Mail',
'from' => 'you@localhost',
];
}
```

**After:**
```php
<?php
use Cake\Network\Email\EmailConfigInterface;

class EmailConfig implements EmailConfigInterface
{
public $default = [
'transport' => 'Mail',
'from' => 'you@localhost',
];
}
```

#### Migration Steps

1. Add the `use` statement for `EmailConfigInterface` at the top of your `EmailConfig` class file
2. Add `implements EmailConfigInterface` to your `EmailConfig` class declaration
3. Ensure all email configurations are defined as public properties (arrays)

### Directory Structure Modernization ([PR #21](https://github.com/pieceofcake2/cakephp/pull/21))

- **Directory layout has been restructured to modern standards**
Expand Down
19 changes: 1 addition & 18 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>src/Controller/Component/Acl/PhpAcl.php</exclude-pattern>
<exclude-pattern>src/Error/exceptions.php</exclude-pattern>
<exclude-pattern>src/TestSuite/ControllerTestCase.ph</exclude-pattern>
<exclude-pattern>src/TestSuite/ControllerTestCase.php</exclude-pattern>
<exclude-pattern>tests/TestCase/*</exclude-pattern>
</rule>

Expand All @@ -113,23 +113,6 @@
<exclude-pattern>tests/test_app/Plugin/*/Console/Command/*</exclude-pattern>
</rule>

<!-- Allow @ error suppression in specific files where it's necessary -->
<rule ref="Generic.PHP.NoSilencedErrors.Discouraged">
<exclude-pattern>src/basics.php</exclude-pattern>
<exclude-pattern>src/functions.php</exclude-pattern>
<exclude-pattern>src/Cache/Engine/FileEngine.php</exclude-pattern>
<exclude-pattern>src/Console/Shell.php</exclude-pattern>
<exclude-pattern>src/Network/CakeResponse.php</exclude-pattern>
<exclude-pattern>src/Utility/Folder.php</exclude-pattern>
<exclude-pattern>src/View/Helper.php</exclude-pattern>
<exclude-pattern>src/View/View.php</exclude-pattern>
<exclude-pattern>tests/TestCase/Cache/CacheTest.php</exclude-pattern>
<exclude-pattern>tests/TestCase/Cache/Engine/MemcacheEngineTest.php</exclude-pattern>
<exclude-pattern>tests/TestCase/Cache/Engine/MemcachedEngineTest.php</exclude-pattern>
<exclude-pattern>tests/TestCase/Cache/Engine/RedisEngineTest.php</exclude-pattern>
<exclude-pattern>tests/TestCase/Error/ErrorHandlerTest.php</exclude-pattern>
</rule>

<!-- Allow non-PascalCase class names in database.php files (CakePHP2 convention) -->
<rule ref="Squiz.Classes.ValidClassName.NotPascalCase">
<exclude-pattern>*/database.php</exclude-pattern>
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ includes:
- vendor/pieceofcake2/phpstan-cakephp2/extension.neon

parameters:
level: 0
level: 5
phpVersion: 80000
paths:
- src
excludePaths:
- src/Console/Templates/*
- src/TestSuite/templates/*
- src/View/Scaffolds/*
bootstrapFiles:
- tests/bootstrap.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
# Ignore deprecated functions that are part of CakePHP 2.x
- '#Function strftime\(\) is deprecated#'
# Ignore mcrypt constants (extension removed in PHP 7.2+)
- '#Function mcrypt_.*\(\) is deprecated#'
- '#Function mcrypt_.* not found#'
- '#Constant MCRYPT_.* not found#'
# Config classes (generated at runtime)
- '#Class EmailConfig not found#'
- '# has unknown class DATABASE_CONFIG as its type.#'
parallel:
processTimeout: 300.0
maximumNumberOfProcesses: 4
Expand Down
Loading