idrinth/php-cost-estimator

一个简单的工具,用于估算PHP脚本更改的成本

dev-master 2024-07-18 01:35 UTC

README

这个小工具旨在静态分析您的代码,以识别潜在的性能问题。

安装

composer require --global "php-cost-estimator/php-cost-estimator"
cd /your/project
estimate-cost estimate-cost:initialize

使用

cd /your/project
estimate-cost

输出

数字越高,代码导致性能问题的可能性就越大。

1xDe\Idrinth\PhpCostEstimator\Command\Check::execute@CLI => 189
- UsesFallbackToRootNamespace
  1xDe\Idrinth\PhpCostEstimator\Configuration\Merged::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Configuration\File::__construct@CLI => 2
  - UsesFallbackToRootNamespace
    1xis_file@CLI => 0
    1xis_array@CLI => 0
    1xRuntimeException::__construct@CLI => 0
  1xgetcwd@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Configuration\Cli::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\State\InheritanceList::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\State\CallableList::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\State\FunctionDefinitionList::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\State\TypeList::__construct@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Command\Check::iterateOverProject@CLI => 140
  - UsesFallbackToRootNamespace
    5xPhpParser\NodeTraverser::__construct@CLI => 0
    5xcount@CLI => 0
    5xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 130
    - UnnecessaryTypeDeclaration
    - UsesFallbackToRootNamespace
      50xstr_ends_with@CLI => 0
      25xstrtolower@CLI => 0
      25xis_dir@CLI => 0
      25xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 650
      - UnnecessaryTypeDeclaration
      - UsesFallbackToRootNamespace
        250xstr_ends_with@CLI => 0
        125xstrtolower@CLI => 0
        125xis_dir@CLI => 0
        125xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 3250
        - UnnecessaryTypeDeclaration
        - UsesFallbackToRootNamespace
          1250xstr_ends_with@CLI => 0
          625xstrtolower@CLI => 0
          625xis_dir@CLI => 0
          625xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 16250
          - UnnecessaryTypeDeclaration
          - UsesFallbackToRootNamespace
            6250xstr_ends_with@CLI => 0
            3125xstrtolower@CLI => 0
            3125xis_dir@CLI => 0
            3125xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 81250
            - UnnecessaryTypeDeclaration
            - UsesFallbackToRootNamespace
              31250xstr_ends_with@CLI => 0
              15625xstrtolower@CLI => 0
              15625xis_dir@CLI => 0
              15625xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 406250
              - UnnecessaryTypeDeclaration
              - UsesFallbackToRootNamespace
                156250xstr_ends_with@CLI => 0
                78125xstrtolower@CLI => 0
                78125xis_dir@CLI => 0
                15625xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => {-recursion-}
                78125xfile_get_contents@CLI => 0
              15625xfile_get_contents@CLI => 0
            3125xfile_get_contents@CLI => 0
          625xfile_get_contents@CLI => 0
        125xfile_get_contents@CLI => 0
      25xfile_get_contents@CLI => 0
    5xgetcwd@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Command\Check::iterateOverDependencies@CLI => 33
  - UnnecessaryTypeDeclaration
  - UsesFallbackToRootNamespace
    5xPhpParser\NodeTraverser::__construct@CLI => 0
    5xcount@CLI => 0
    1xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 26
    - UnnecessaryTypeDeclaration
    - UsesFallbackToRootNamespace
      10xstr_ends_with@CLI => 0
      5xstrtolower@CLI => 0
      5xis_dir@CLI => 0
      5xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 130
      - UnnecessaryTypeDeclaration
      - UsesFallbackToRootNamespace
        50xstr_ends_with@CLI => 0
        25xstrtolower@CLI => 0
        25xis_dir@CLI => 0
        25xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 650
        - UnnecessaryTypeDeclaration
        - UsesFallbackToRootNamespace
          250xstr_ends_with@CLI => 0
          125xstrtolower@CLI => 0
          125xis_dir@CLI => 0
          125xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 3250
          - UnnecessaryTypeDeclaration
          - UsesFallbackToRootNamespace
            1250xstr_ends_with@CLI => 0
            625xstrtolower@CLI => 0
            625xis_dir@CLI => 0
            625xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 16250
            - UnnecessaryTypeDeclaration
            - UsesFallbackToRootNamespace
              6250xstr_ends_with@CLI => 0
              3125xstrtolower@CLI => 0
              3125xis_dir@CLI => 0
              3125xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => 81250
              - UnnecessaryTypeDeclaration
              - UsesFallbackToRootNamespace
                31250xstr_ends_with@CLI => 0
                15625xstrtolower@CLI => 0
                15625xis_dir@CLI => 0
                3125xDe\Idrinth\PhpCostEstimator\Command\Check::iterateFolder@CLI => {-recursion-}
                15625xfile_get_contents@CLI => 0
              3125xfile_get_contents@CLI => 0
            625xfile_get_contents@CLI => 0
          125xfile_get_contents@CLI => 0
        25xfile_get_contents@CLI => 0
      5xfile_get_contents@CLI => 0
    1xgetcwd@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Command\Check::analyzeProject@CLI => 6
  - UnnecessaryTypeDeclaration
  - UsesFallbackToRootNamespace
    5xPhpParser\NodeTraverser::__construct@CLI => 0
    5xcount@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Command\Check::analyzeDependencies@CLI => 6
  - UnnecessaryTypeDeclaration
  - UsesFallbackToRootNamespace
    5xPhpParser\NodeTraverser::__construct@CLI => 0
    5xcount@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Command\Check::iterateOverResults@CLI => 1
  - UnnecessaryTypeDeclaration
1xDe\Idrinth\PhpCostEstimator\Command\Initialize::execute@CLI => 20
- UsesFallbackToRootNamespace
  1xgetcwd@CLI => 0
  1xis_file@CLI => 0
  1xmkdir@CLI => 0
  1xdirname@CLI => 0
  5xstr_ends_with@CLI => 0
  5xsubstr@CLI => 0
  1xsprintf@CLI => 0
  1xcount@CLI => 0
  1xfile_put_contents@CLI => 0
  1xstr_replace@CLI => 0
  1ximplode@CLI => 0
  1xfile_get_contents@CLI => 0
1xDe\Idrinth\PhpCostEstimator\Command\Reason::execute@CLI => 9
- UsesFallbackToRootNamespace
  1xReflectionClass::__construct@CLI => 0
  6xget_class@CLI => 0
  1xDe\Idrinth\PhpCostEstimator\Configuration\File::__construct@CLI => 2
  - UsesFallbackToRootNamespace
    1xis_file@CLI => 0
    1xis_array@CLI => 0
    1xRuntimeException::__construct@CLI => 0
  1xgetcwd@CLI => 0

配置

配置文件位于/your/project/.php-cost-estimator/config.php,将由初始化命令生成。您可以根据需要调整它并将其提交到版本控制。

<?php
declare(strict_types=1);

return [
    'rules' => [
        'De\\Idrinth\\PhpCostEstimator\\Rule\\BuildsUnusedObject',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\ConnectsToUnusedDatabase',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\LocksFileSystem',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\ParsesStaticTextFile',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\QueriesDatabase',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\ReadsFromFileSystem',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UnnecessaryCaching',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UnnecessaryTypeDeclaration',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesArrayKeyExists',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesFallbackToRootNamespace',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesInArrayOnLargeArray',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesReflection',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesRemoteCall',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesStaticComparison',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\UsesVersionSwitches',
        'De\\Idrinth\\PhpCostEstimator\\Rule\\WritesToFileSystem',
    ],
    'version' => '8.2.6',
    'folders' => [
        'src'
    ]
];

贡献

欢迎所有贡献,有关详细信息,请参阅CONTRIBUTING.md