Php lấy số dòng của tệp

Tôi sẽ sớm nói về Laravel và "doanh nghiệp" và khái niệm về LỘC [dòng mã] tiếp tục xuất hiện. Hóa ra đó thực sự là một con số khó khám phá hơn nhiều so với bạn nghĩ, vì vậy tôi nghĩ rằng tôi sẽ viết ra một vài lựa chọn ở đây

Đối với những gì nó đáng giá, tôi không phải là một fan hâm mộ lớn của LỘC như một thước đo tầm quan trọng, nhưng ít nhất nó có thể cung cấp cho chúng tôi một số nền tảng rộng để sử dụng để nói về sự khác biệt lớn về quy mô dự án. Nếu bạn hỏi tôi, tôi sẽ nói rằng chúng ta thậm chí không nên nghĩ về điều đó. Nhưng không phải lúc nào chúng ta cũng có được sự xa xỉ đó

TL;DR. sử dụng PHPLOC

Nếu bạn không muốn đọc nửa tá tùy chọn, hãy sử dụng PHPLOC. Bạn có thể tìm thấy mô tả dài hơn bên dưới, nhưng đây là hướng dẫn bắt đầu nhanh

cd Sites/
wget //phar.phpunit.de/phploc.phar
php phploc-4.0.1.phar --exclude vendor --exclude node_modules myprojectnamehere/

Lấy số

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
4 và
$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
5;

Lưu ý rằng bạn cũng có thể loại trừ các thư mục nhật ký và bộ đệm dành riêng cho khung và bất kỳ thứ gì khác giúp bạn có được số lượng tốt nhất

OK, hãy xem xét tất cả các tùy chọn. Xin lưu ý rằng một số công cụ này đếm tất cả các dòng mã, không chỉ PHP. Khi có thể, tôi đã chuyển các bộ lọc cho chúng để chỉ đếm các tệp PHP

Các công cụ dòng lệnh có thể cài đặt

PHPLOC

PHPLOC là một dự án của Sebastian Bergmann, người tạo ra PHPUnit, cung cấp số lượng LOC đơn giản và dễ dàng theo ngữ cảnh cho PHP

PHPLOC cũng cung cấp các số liệu cụ thể khác của PHP, như độ phức tạp theo chu trình, số lượng lớp, độ dài lớp trung bình, độ dài phương thức trung bình, v.v.

Đây là một báo cáo PHPLOC mẫu

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]

Bạn có thể yêu cầu nó trên toàn cầu hoặc dành riêng cho dự án với Trình soạn thảo hoặc, phương pháp ưa thích của tôi, chỉ cần tải xuống

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
6, chạy nó, sau đó xóa nó sau khi bạn hoàn tất

Đây là những gì tôi đã sử dụng

php phploc.phar --exclude vendor --exclude node_modules myproject

ĐỒNG HỒ

CLOC là một trong những chương trình chạy dài hơn và thông minh nhất để đếm các dòng mã. Nó có thể phân biệt các ngôn ngữ và cũng có thể tách biệt các dòng trống và dòng nhận xét với các dòng mã thực

Nó cũng có thể lấy từ kho lưu trữ và kho git, phân biệt hai phiên bản của cơ sở mã, lấy từ các cam kết cụ thể, bỏ qua các tệp và thư mục khớp với các mẫu cụ thể và có thể cài đặt qua Brew, NPM, hai trình quản lý gói Windows và tất cả các trình quản lý gói Linux chính

Đây là một ví dụ

prompt> cloc gcc-5.2.0/gcc/c
      16 text files.
      15 unique files.
       3 files ignored.

//github.com/AlDanial/cloc v 1.65  T=0.23 s [57.1 files/s, 188914.0 lines/s]
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                               10           4680           6621          30812
C/C++ Header                     3             99            286            496
-------------------------------------------------------------------------------
SUM:                            13           4779           6907          31308
-------------------------------------------------------------------------------

Vì CLOC không phụ thuộc vào ngôn ngữ nên nó sẽ không cung cấp cùng chất lượng hoặc sự đa dạng của các chỉ số như PHPLOC

Đây là những gì tôi đã sử dụng

cloc --exclude-dir=vendor,node_modules myproject

dành riêng cho IDE

PHPStorm

Tôi đã tìm thấy một plugin cho PHPStorm có tên là Thống kê cung cấp cho bạn tổng số dòng mã trong toàn bộ dự án của bạn và được chia nhỏ theo loại tệp

Văn bản tuyệt vời

Tôi tìm thấy Gist này, nó khai thác khả năng regex của tìm kiếm Sublime Text và giúp dễ dàng chỉ định loại tệp và thư mục nào bạn muốn bao gồm hoặc loại trừ

Tôi đã sử dụng phiên bản này [từ một nhận xét, bỏ qua các dòng khoảng trắng]

________số 8

Đảm bảo loại trừ đúng thư mục. Đây là danh sách của tôi cho một dự án PHP chung

-./vendor/*,-./node_modules/*,-./.git/*,*.php

Lệnh thiết bị đầu cuối thủ công

Lệnh
$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
7

Đây chắc chắn là một trong những biện pháp ít chính xác hơn, nhưng nó cũng không yêu cầu bạn phải cài đặt bất kỳ thứ gì khác và nó cung cấp cho bạn khả năng bao gồm và loại trừ các mẫu cụ thể cho các tệp và thư mục

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
1

Như bạn có thể thấy, chúng tôi đang loại trừ hai thư mục nhà cung cấp, thư mục git, sau đó bạn cũng có thể xem ví dụ về cách loại trừ và bao gồm các mẫu tệp cụ thể

Cảm ơn Jake Bathman tại Tighten đã giúp tôi làm cho lệnh này hoạt động chính xác

Người Tìm Kiếm Bạc [
$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
8]

Nếu bạn đã cài đặt Silver Searcher, bạn có thể thử điều này

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
3

Cảm ơn Daniel Coulbourne tại Tighten vì điều này

Câu hỏi thường gặp

  • Tôi có nên bao gồm các thư mục nhà cung cấp không?
    Theo tôi, không.
  • Tôi có nên bao gồm nhận xét và khoảng trắng không?
    Theo tôi, không.
  • LỘC có phải là một chỉ báo tốt về mức độ phức tạp hoặc ý nghĩa không?
    Theo tôi, không.
  • Độ phức tạp chu trình là gì?
    Bạn có thể tìm hiểu thêm bằng cách đọc bài viết của Wikipedia, nhưng về bản chất, đó là thước đo nhằm xem mức độ phức tạp của một cơ sở mã. Thật thú vị khi xem xét, nhưng nó cũng nhất thiết phải tăng lên khi quy mô của dự án tăng lên, vì vậy đây không thực sự là một con số dễ sử dụng và đã có ý kiến ​​cho rằng nó không thực sự tương quan với số lượng lỗi cao hơn. Cho nên. No co vui không? . Có ích? . Đôi khi, một số số phức tạp [ví dụ: dòng trung bình cho mỗi phương thức và lớp] có thể hữu ích hơn. Nếu bạn quan tâm, bạn có thể lấy những con số phức tạp này từ PHPLOC và một công cụ khác gọi là PhpMetrics; .
  • Dòng mã logic là gì?
    Còn được gọi là "dòng mã hiệu quả", đây là những dòng mã thực sự hướng dẫn trình phân tích cú pháp thực hiện điều gì đó. Theo như tôi có thể nói, điều này là để phân biệt chúng với các mẫu, tiêu đề, nhận xét và mã không hiệu quả; .

LOC kết quả từ mỗi công cụ trên cùng một dự án

Tôi đã chạy tất cả các công cụ này trên cùng một dự án. Hội nghị chuyên đề, một trong những dự án nguồn mở của Thắt chặt, để xem tất cả chúng so sánh như thế nào

PHPLOC

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
4

Kết quả

  • LỘC. 13,609
  • Nhận xét dòng mã. 2,431
  • Dòng mã không bình luận. 11,178
  • dòng logic. 2.958

ĐỒNG HỒ

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
0

Kết quả

  • LỘC. 26.068
  • Bình luận. 4.296
  • PHP LỘC. 7,653
  • Nhận xét PHP. 2,444

PHPStorm

Jose Soto chạy những thứ này cho tôi

Kết quả

  • LỘC. 52,168
  • PHP LỘC. 12.096
  • Mã nguồn PHP LỘC. 7,849
  • Nhận xét PHP LỘC. 2,406

Ghi chú. Để plugin này mang lại cho tôi kết quả tốt, Jose đã phải xóa các thư mục

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
9 và
php phploc.phar --exclude vendor --exclude node_modules myproject
0

Văn bản tuyệt vời

Khi bật regex, hãy tìm

php phploc.phar --exclude vendor --exclude node_modules myproject
1 trong

-./vendor/*,-./node_modules/*,-./.git/*,*.php

Và sau đó nhìn vào kết quả ở phía dưới

Kết quả

  • PHP LỘC. 11,468

Hướng dẫn sử dụng lệnh
$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
7

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
2
  • PHP LỘC. 13,609

Silver Surfer [
$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
8]

$ phploc src
phploc 4.0.0 by Sebastian Bergmann.

Directories                                          3
Files                                               10

Size
  Lines of Code [LOC]                             1882
  Comment Lines of Code [CLOC]                     255 [13.55%]
  Non-Comment Lines of Code [NCLOC]               1627 [86.45%]
  Logical Lines of Code [LLOC]                     377 [20.03%]
    Classes                                        351 [93.10%]
      Average Class Length                          35
        Minimum Class Length                         0
        Maximum Class Length                       172
      Average Method Length                          2
        Minimum Method Length                        1
        Maximum Method Length                      117
    Functions                                        0 [0.00%]
      Average Function Length                        0
    Not in classes or functions                     26 [6.90%]

Cyclomatic Complexity
  Average Complexity per LLOC                     0.49
  Average Complexity per Class                   19.60
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    139.00
  Average Complexity per Method                   2.43
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    96.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 [0.00%]
    Global Variables                                 0 [0.00%]
    Super-Global Variables                           0 [0.00%]
  Attribute Accesses                                85
    Non-Static                                      85 [100.00%]
    Static                                           0 [0.00%]
  Method Calls                                     280
    Non-Static                                     276 [98.57%]
    Static                                           4 [1.43%]

Structure
  Namespaces                                         3
  Interfaces                                         1
  Traits                                             0
  Classes                                            9
    Abstract Classes                                 0 [0.00%]
    Concrete Classes                                 9 [100.00%]
  Methods                                          130
    Scope
      Non-Static Methods                           130 [100.00%]
      Static Methods                                 0 [0.00%]
    Visibility
      Public Methods                               103 [79.23%]
      Non-Public Methods                            27 [20.77%]
  Functions                                          0
    Named Functions                                  0 [0.00%]
    Anonymous Functions                              0 [0.00%]
  Constants                                          0
    Global Constants                                 0 [0.00%]
    Class Constants                                  0 [0.00%]
3

Kết quả

  • PHP LỘC. 11,795

Phần kết luận

Ồ. Bài đăng này mất nhiều thời gian hơn tôi mong đợi. Kudos cho bạn để đọc này dài. trời ạ. tôi mệt

Cuối cùng, tôi vẫn khuyên dùng PHPLOC nếu bạn có thể. Nó được bối cảnh hóa nhiều nhất và cung cấp thêm chi tiết mà một số người khác không có. Nó giúp dễ dàng loại trừ các thư mục nhà cung cấp. nó tốt. Đó là tất cả

Làm cách nào để đếm số dòng trong một tệp trong PHP?

Cách tiếp cận 1. Tải toàn bộ tệp vào bộ nhớ rồi sử dụng hàm đếm[] để trả về số dòng trong tệp này.

Làm cách nào để đếm số lượng trong một tệp trong PHP?

Hàm đếm[] . Các hàm count[] là một hàm mảng được sử dụng để đếm tất cả các phần tử trong một mảng hoặc một thứ gì đó trong một đối tượng. Hàm này sử dụng COUNT_RECURSIVE làm chế độ đếm mảng theo cách đệ quy, hữu ích để đếm tất cả các phần tử của mảng nhiều chiều.

Làm cách nào để kiểm tra từng dòng mã trong PHP?

Lấy dữ liệu theo từng dòng. Chúng ta có thể lấy từng dòng dữ liệu bằng cách sử dụng phương thức fgets[] .

Làm cách nào để đọc dòng đầu tiên của tệp trong PHP?

PHP Đọc một dòng - fgets[] .

Chủ Đề