OpenML icon indicating copy to clipboard operation
OpenML copied to clipboard

Add Comprehensive Code Quality Tools(PHPStan,Psalm,PHP-CS-Fixer)

Open pankajbaid567 opened this issue 1 month ago • 1 comments

Description

Problem

The current PHP codebase lacks modern static analysis and code-quality enforcement. This causes:

Inconsistent code style across the project

Missed type and logic errors that static analysis could catch early

Harder onboarding for new contributors

No automated checks in CI/CD to prevent regressions

Proposed solution

Integrate the following tools:

PHPStan (level 5+) — catch type errors and bugs

Psalm — complementary static analysis with optional security checks

PHP-CS-Fixer — automatically fix code style to follow PSR-12

PHPMD — detect code smells and complexity issues

Steps/Code to Reproduce

Implementation plan

1. Repo files (examples) .phpstan.neon

parameters:
    level: 5
    paths:
        - openml_OS
    excludePaths:
        - openml_OS/libraries/*
        - openml_OS/third_party/*

.php-cs-fixer.php

<?php
$config = new PhpCsFixer\Config();
return $config
    ->setRules([
        '@PSR12' => true,
        '@PHP80Migration' => true,
        'array_syntax' => ['syntax' => 'short'],
    ])
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->in('openml_OS')
            ->exclude(['libraries', 'third_party'])
    );

psalm.xml (minimal starter)

<?xml version="1.0"?>
<psalm errorLevel="5">
  <projectFiles>
    <directory name="openml_OS"/>
    <exclude name="openml_OS/libraries"/>
    <exclude name="openml_OS/third_party"/>
  </projectFiles>
</psalm>

2. composer.json scripts Add dev dependencies and useful scripts:

{
  "require-dev": {
    "phpstan/phpstan": "^1.12",
    "vimeo/psalm": "^5.0",
    "friendsofphp/php-cs-fixer": "^3.0",
    "phpmd/phpmd": "^2.10"
  },
  "scripts": {
    "cs:check": "php-cs-fixer fix --dry-run --diff",
    "cs:fix": "php-cs-fixer fix",
    "phpstan": "phpstan analyse -c .phpstan.neon",
    "psalm": "psalm --output-format=summary",
    "phpmd": "phpmd openml_OS text codesize,unusedcode,naming"
  }
}

3. CI / GitHub Actions Example /.github/workflows/ci-quality.yml:

name: PHP Quality Checks

on:
  pull_request:
  push:
    branches: [ main ]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          extensions: mbstring, intl
      - name: Install composer deps
        run: composer install --prefer-dist --no-progress --no-suggest
      - name: PHP-CS-Fixer (check)
        run: composer run cs:check
      - name: PHPStan
        run: composer run phpstan
      - name: Psalm
        run: composer run psalm
      - name: PHPMD
        run: composer run phpmd

4. Onboarding & rollout

Add the config files to repo root.

Add the composer dev dependencies and scripts.

Add the GitHub Actions workflow above.

Run composer run cs:fix once on a branch to apply auto-fixes; commit changes in a single formatting PR.

Optionally run PHPStan/Psalm with --level=0 or --showProgress and gradually raise to level 5 while fixing issues.

Document developer steps in CONTRIBUTING.md.

Expected Results

Consistent PSR-12 formatting enforced automatically.

Early detection of type and security issues.

CI prevents regressions.

Faster, easier onboarding and safer refactors.

Actual Results

(No changes yet — this issue requests the integration.)

pankajbaid567 avatar Nov 20 '25 13:11 pankajbaid567

HI @pankajbaid567 , If possible can I contribute?

Aymuos22 avatar Nov 25 '25 04:11 Aymuos22