Check Class Lengthのロゴ

Check Class Length

コミュニティ
dykyi-roman
check-class-length

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

Add to TypingMind

概要

公開者dykyi-roman
リポジトリawesome-claude-code
スキル名check-class-length
スター
98
フォーク
25
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    dykyi-romanがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Check Class Length」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/dykyi-roman/awesome-claude-code/tree/master/skills/check-class-length
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでCheck Class Lengthを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にCheck Class Lengthを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Check Class Lengthは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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)

よくある質問

AIスキル「Check Class Length」では何ができますか?

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

TypingMindでCheck Class Lengthを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Check Class Lengthはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにCheck Class Lengthをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/dykyi-roman/awesome-claude-code/tree/master/skills/check-class-lengthを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Check Class Lengthを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Check Class Lengthで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもCheck Class Lengthを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Check Class Length」は無料ですか?

はい。dykyi-romanがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇