Check Class Length logo

Check Class Length

Community
dykyi-roman
check-class-length

Analyzes PHP code for class length issues. Detects classes exceeding 300 lines, God class indicators, cohesion issues, SRP violations.

Overview

Publisherdykyi-roman
Repositoryawesome-claude-code
Skill namecheck-class-length
Stars
98
Forks
25
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by dykyi-roman on GitHub. Read the source before you install it.

Installation

Install the Check Class Length AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dykyi-roman/awesome-claude-code.git /tmp/awesome-claude-code
mkdir -p .claude/skills
cp -r /tmp/awesome-claude-code/skills/check-class-length .claude/skills/check-class-length
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Check Class Length in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Check Class Length on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Check Class Length is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Class Length Check

Analyze PHP code for class size and cohesion issues.

Detection Thresholds

LinesClassification
1-100✅ Ideal
101-200⚠️ Acceptable
201-300🟡 Large - review needed
301-500🟠 Too large - split
501+🔴 God class - urgent refactoring

Detection Patterns

1. God Class Indicators

php
// GOD CLASS: Does everything
class OrderManager
{
    // Handles orders
    public function createOrder() {}
    public function updateOrder() {}
    public function cancelOrder() {}

    // Handles payments
    public function processPayment() {}
    public function refundPayment() {}

    // Handles shipping
    public function createShipment() {}
    public function trackShipment() {}

    // Handles inventory
    public function reserveStock() {}
    public function releaseStock() {}

    // Handles notifications
    public function sendOrderConfirmation() {}
    public function sendShippingNotification() {}

    // Handles reporting
    public function generateOrderReport() {}
    public function exportToExcel() {}

    // 50+ more methods...
}

// GOOD: Split by responsibility
class OrderService {}
class PaymentService {}
class ShippingService {}
class InventoryService {}
class NotificationService {}
class ReportingService {}

2. Low Cohesion Signs

php
// LOW COHESION: Methods don't use same properties
class UserService
{
    private $userRepository;
    private $emailService;
    private $paymentGateway;
    private $logService;
    private $cacheService;

    // User methods use $userRepository
    public function findUser() {}
    public function updateUser() {}

    // Email methods use $emailService (unrelated)
    public function sendEmail() {}
    public function validateEmail() {}

    // Payment methods use $paymentGateway (unrelated)
    public function processPayment() {}
    public function checkBalance() {}
}

// HIGH COHESION: All methods use same core dependencies
class UserService
{
    public function __construct(
        private UserRepository $userRepository,
        private PasswordHasher $hasher,
    ) {}

    public function findUser(int $id): User {}
    public function createUser(UserData $data): User {}
    public function updateUser(User $user, UserData $data): void {}
    public function changePassword(User $user, string $password): void {}
}

3. Too Many Dependencies

php
// TOO MANY DEPENDENCIES: Indicates SRP violation
class OrderProcessor
{
    public function __construct(
        private OrderRepository $orderRepository,
        private ProductRepository $productRepository,
        private UserRepository $userRepository,
        private PaymentGateway $paymentGateway,
        private ShippingService $shippingService,
        private InventoryService $inventoryService,
        private EmailService $emailService,
        private SmsService $smsService,
        private PushNotificationService $pushService,
        private LoggerInterface $logger,
        private CacheInterface $cache,
        private EventDispatcher $eventDispatcher,
        // 10+ more...
    ) {}
}

// GUIDELINE: Max 5-7 dependencies
class OrderProcessor
{
    public function __construct(
        private OrderRepository $orderRepository,
        private PaymentProcessor $paymentProcessor,
        private NotificationService $notificationService,
        private EventDispatcher $eventDispatcher,
    ) {}
}

4. Feature Envy

php
// FEATURE ENVY: Class manipulates other class's data extensively
class OrderPrinter
{
    public function print(Order $order): string
    {
        $output = "Order: " . $order->getId() . "\n";
        $output .= "Customer: " . $order->getCustomer()->getName() . "\n";
        $output .= "Address: " . $order->getCustomer()->getAddress()->getStreet() . "\n";
        $output .= "City: " . $order->getCustomer()->getAddress()->getCity() . "\n";

        $total = 0;
        foreach ($order->getItems() as $item) {
            $output .= $item->getProduct()->getName() . ": ";
            $output .= $item->getQuantity() . " x " . $item->getPrice() . "\n";
            $total += $item->getQuantity() * $item->getPrice();
        }
        // Many more lines accessing Order internals...
    }
}

// BETTER: Move logic to Order class
class Order
{
    public function format(): string
    {
        // Order knows how to format itself
    }
}

5. Too Many Public Methods

php
// TOO MANY PUBLIC METHODS: API surface too large
class UserService
{
    public function findById() {}
    public function findByEmail() {}
    public function findByPhone() {}
    public function findByUsername() {}
    public function findActive() {}
    public function findInactive() {}
    public function create() {}
    public function update() {}
    public function delete() {}
    public function activate() {}
    public function deactivate() {}
    public function ban() {}
    public function unban() {}
    public function verify() {}
    // 20+ more public methods
}

// BETTER: Split into focused classes
class UserFinder {}
class UserModifier {}
class UserStatusManager {}

Metrics

LCOM (Lack of Cohesion of Methods)

  • LCOM = 0: Perfect cohesion
  • LCOM < 0.5: Good cohesion
  • LCOM > 0.8: Poor cohesion

Class Complexity Indicators

  • Lines of code > 300
  • Methods > 20
  • Properties > 10
  • Dependencies > 7
  • Cyclomatic complexity > 50

Refactoring Strategies

Extract Class

php
// Before: One large class
class Order
{
    // Order data and methods (30 methods)
    // Pricing logic (10 methods)
    // Shipping logic (8 methods)
    // Notification logic (5 methods)
}

// After: Multiple focused classes
class Order {} // Core order data
class OrderPricing {} // Price calculation
class OrderShipping {} // Shipping logic
class OrderNotifier {} // Notifications

Introduce Domain Events

php
// Before: Class does everything
class OrderService
{
    public function complete(Order $order): void
    {
        $order->complete();
        $this->updateInventory($order);
        $this->sendEmail($order);
        $this->createInvoice($order);
        $this->notifyWarehouse($order);
    }
}

// After: Event-driven
class OrderService
{
    public function complete(Order $order): void
    {
        $order->complete();
        $this->eventDispatcher->dispatch(new OrderCompletedEvent($order));
    }
}

// Separate listeners handle each concern
class UpdateInventoryListener {}
class SendConfirmationEmailListener {}
class CreateInvoiceListener {}

Severity Classification

LinesSeverity
201-300🟡 Minor
301-500🟠 Major
501+🔴 Critical

Output Format

markdown
### Class Length: [ClassName] is too large

**Severity:** 🟠/🔴
**Location:** `file.php`
**Lines:** 450
**Methods:** 35
**Dependencies:** 12

**Issue:**
Class `OrderManager` is 450 lines with 35 methods, indicating multiple responsibilities.

**Responsibilities Detected:**
1. Order CRUD operations
2. Payment processing
3. Shipping management
4. Email notifications
5. Reporting

**Suggested Split:**

OrderService (100 lines) ├── OrderRepository PaymentProcessor (80 lines) ShippingManager (70 lines) OrderNotifier (50 lines) OrderReporter (60 lines)

When This Is Acceptable

  • Aggregate Roots — DDD aggregates may legitimately contain many methods to protect invariants
  • Event Sourcing aggregates — Aggregates with many apply* event handlers grow naturally
  • Test classes — Test classes with many test methods for thorough coverage

False Positive Indicators

  • Class extends AggregateRoot or similar base
  • Class is in tests/ directory
  • Class has many small, focused methods (high method count ≠ God class)

Frequently asked questions

What does the Check Class Length AI skill do?

Analyzes PHP code for class length issues. Detects classes exceeding 300 lines, God class indicators, cohesion issues, SRP violations.

Why use Check Class Length on TypingMind?

Because you install it once and use it with any model. Check Class Length is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Check Class Length in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/dykyi-roman/awesome-claude-code/tree/master/skills/check-class-length. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Check Class Length?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Check Class Length?

As many as you like. As long as a model supports skills, you can use Check Class Length with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Check Class Length AI skill free?

Yes. It is published on GitHub by dykyi-roman under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇