Skip to content

Update IsolationForest.php #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

itashia
Copy link

@itashia itashia commented Jun 8, 2025

refactor: improve type safety, readability, and modernize code

  • Added precise type hints and docblocks:
    • Used @var array for float arrays
    • Defined return types with @return array<string, mixed>
  • Extracted repetitive logic into private methods:
    • updateVariancesWithSmoothing()
    • calculateThreshold()
    • updateThreshold()
  • Simplified model training checks via trained() method
  • Minor optimizations:
    • Replaced or with || for consistency
    • Removed redundant and unnecessary comments
    • Used empty() for array checks
    • Combined mathematical operations for better performance
  • Modernization changes:
    • Marked class as final to prevent unnecessary inheritance
    • Removed obvious comments (e.g. empty array declarations)
    • Sorted use statements for clarity

refactor: improve type safety, readability, and modernize code

- Added precise type hints and docblocks:
  - Used @var array<float> for float arrays
  - Defined return types with @return array<string, mixed>
- Extracted repetitive logic into private methods:
  - updateVariancesWithSmoothing()
  - calculateThreshold()
  - updateThreshold()
- Simplified model training checks via trained() method
- Minor optimizations:
  - Replaced `or` with `||` for consistency
  - Removed redundant and unnecessary comments
  - Used empty() for array checks
  - Combined mathematical operations for better performance
- Modernization changes:
  - Marked class as final to prevent unnecessary inheritance
  - Removed obvious comments (e.g. empty array declarations)
  - Sorted use statements for clarity
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.

2 participants