Skip to content

Conversation

@insign
Copy link
Contributor

@insign insign commented Nov 23, 2025

No description provided.

Identify areas for improvement across architecture, code quality,
testing, security, and documentation. Includes prioritized
recommendations for refactoring the main Rclone class, adding
type hints, improving exception handling, and fixing experimental
providers (crypt, union).
Changes include:
- Fix post-install-cmd script that never executed security-check
- Add complete type hints and PHPDoc to AbstractProvider
- Standardize NULL/TRUE/FALSE to lowercase (PSR-12 compliance)
- Change temp directory permissions from 0777 to 0700 (security)
- Create RcloneExitCode enum replacing magic numbers
- Add #[NoReturn] attribute and 'never' return type to handleProcessFailure
- Extract regex patterns to class constants for better performance
- Enhance RcloneException with getExitCode(), isRetryable(), getSummary()
- Add isRetryable() override in TemporaryErrorException
- Clean up Provider class removing duplicate property declarations
- Normalize code style in S3Provider and B2Provider
Breaking changes preparation (work in progress):
- Create ProviderInterface for better abstraction and testability
- Update AbstractProvider to implement ProviderInterface
- Update Rclone class to use ProviderInterface instead of Provider
- Extract SizeConverter utility class for byte conversions
- Extract DurationConverter utility class for time conversions
- Extract StatsParser for rclone statistics parsing
- Extract ProgressParser for real-time progress parsing

New files:
- src/Providers/ProviderInterface.php
- src/Util/SizeConverter.php
- src/Util/DurationConverter.php
- src/Parser/StatsParser.php
- src/Parser/ProgressParser.php
Configuration:
- Add PHPStan for static analysis (level 6)
- Add Laravel Pint for code style fixing
- Configure PHPUnit coverage with HTML and Clover reports
- Add composer scripts: analyse, lint, lint-test, test-coverage
- Update .gitignore for coverage artifacts

Code improvements:
- Refactor Rclone to use extracted Parser/Converter classes
- Fix CryptProvider to use ProviderInterface and proper encapsulation
- Fix UnionProvider to validate upstream providers and auto-generate upstreams config
- Add getWrappedProvider() and getUpstreamProviders() accessor methods

Dependencies added:
- phpstan/phpstan: ^2.0
- laravel/pint: ^1.18
BREAKING CHANGES:
- Removed static methods: setFlags(), setEnvs(), setTimeout(), setIdleTimeout()
- Configuration is now per-instance via constructor or builder pattern
- Added RcloneBuilder for fluent configuration

New API:
```php
// Simple instantiation (unchanged)
$rclone = new Rclone($provider);

// Builder pattern for advanced configuration
$rclone = Rclone::create($provider)
    ->withRightSide($destProvider)
    ->withTimeout(300)
    ->withIdleTimeout(200)
    ->withFlags(['verbose' => true])
    ->withEnvs(['CUSTOM_VAR' => 'value'])
    ->build();

// Or via constructor
$rclone = new Rclone(
    leftSide: $provider,
    rightSide: $destProvider,
    timeout: 300,
    flags: ['verbose' => true]
);
```

Benefits:
- Thread-safe: each instance has isolated configuration
- Testable: no global state to mock or reset
- Predictable: configuration is explicit and immutable after creation
Comprehensive guide covering:
- All removed static methods and their replacements
- Code examples for before/after migration
- Builder pattern documentation
- ProviderInterface usage
- CryptProvider and UnionProvider improvements
- Search patterns to find code needing updates
- FAQ section for common questions
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.

3 participants