Code metrics of php - Notepad++ [duplicate]
Asked Answered
T

3

9

In particular, I am interested to know how many lines of codes there are, but this spans across many files.

I have been using notepad++ to author the code and for each file it does display line numbers but of course I have empty returns to make the code more readable.

Does anyone know of a plugin or tool that I can accurately get the actual lines of code?

Tourism answered 24/6, 2010 at 11:47 Comment(3)
Using PHP Designer or Dreaweaver would be a better alternative....Transmundane
You might take a look at this previous answer stackoverflow.com/questions/1300420/good-php-metric-tools though counting the number of lines of code isn't really a significant measure of anythingWahl
@Jens: The OP clearly thought his line count spanned multiple files. The only thing I can imagine he might want to do that is to count the apparant size of a PHP script including the code participating via the transitive closure of a require (aka "include") clause, then it has to be PHP specific. That's sort of a measure of how hard it is to comprehend a script, because requires clauses are typically used to import what amounts to APIs and their implementation. Harry, please comment?Vincenza
U
24
  1. Go to Search -> Find in Files... or use Ctrl+Shift+F

    https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/V5MKW.png

  2. Find what: \S+\s\r\n*

    Filters: *.php

    Search Mode Regular expression

    Click Find All

    https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/YRXUX.png

  3. See the 'Find result' in the lower pane

    https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/UpuAQ.png

It's not perfect at all, but it works out of the box. Of course you can also make changes to the regular expression, like only counting lines with:

  • White space only: ^\s\r\n*
  • At least one letter or number: \w+.*\r\n
  • Which are used solely for curly braces: ^(\s[{}]\s)+\r\n**
  • A class keyword: class .*\r\n
  • A function keyword: function .*\r\n
Underthecounter answered 22/6, 2013 at 19:19 Comment(1)
@quamrana thanks for embedding the images.Underthecounter
L
2

Google for "php sloc counter". There are plenty of tools to do that, for example:

http://thecodecentral.com/2007/12/26/source-line-of-code-counter

However, this kind of measuring is absolutely useless, so I'm not sure why you would want to do this.

Letter answered 24/6, 2010 at 12:45 Comment(0)
G
1

Linux:

find -name '*.php' | xargs grep -av '\r' | wc -l

Windows (PowerShell):

(dir -include *.php -recurse | select-string "(?!^$)").count
Garrard answered 24/6, 2010 at 12:47 Comment(2)
1) He mentioned Notepad++ so he's on windows. 2) This would count all lines, not sloc, which is what he wants.Letter
and empty lines is not in counted nowGarrard

© 2022 - 2024 — McMap. All rights reserved.